-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcypress.config.ts
More file actions
33 lines (28 loc) · 1.1 KB
/
cypress.config.ts
File metadata and controls
33 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { defineConfig } from "cypress";
import { google } from "googleapis";
import * as fs from "fs";
async function getLastEmailSnippet() {
const credentials = JSON.parse(fs.readFileSync("credentials.json", "utf8"));
const token = JSON.parse(fs.readFileSync("token.json", "utf8"));
const { client_secret, client_id, redirect_uris } = credentials.installed;
const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]);
oAuth2Client.setCredentials(token);
const gmail = google.gmail({ version: "v1", auth: oAuth2Client });
const res = await gmail.users.messages.list({ userId: "me", maxResults: 1 });
const message = res.data.messages?.[0];
if (!message) return "Aucun email trouvé";
const full = await gmail.users.messages.get({ userId: "me", id: message.id! });
return full.data.snippet || "Pas de contenu";
}
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
on("task", {
async getLastEmail() {
return await getLastEmailSnippet();
},
});
return config;
},
},
});