-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcypress.config.ts
67 lines (63 loc) · 1.89 KB
/
cypress.config.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { defineConfig } from "cypress";
import dotenv from "dotenv";
dotenv.config();
import fs from "fs";
import { google } from "googleapis";
import { JSDOM } from "jsdom";
async function get_login_link() {
const credentials = JSON.parse(
fs.readFileSync(process.env.TEST_CYPRESS_GMAIL_CRED as string, "utf-8"),
);
console.log(credentials);
const auth = new google.auth.OAuth2(
credentials.web.client_id,
credentials.web.client_secret,
process.env.TEST_CYPRESS_GMAIL_API_REDIRECT_URI as string,
);
auth.setCredentials({
access_token: process.env.TEST_CYPRESS_GMAIL_ACCESS_TOKE as string,
refresh_token: process.env.TEST_CYPRESS_GMAIL_REFRESH_TOKEN as string,
});
const gmail = google.gmail({ version: "v1", auth });
const res = await gmail.users.messages.list({
userId: "me",
maxResults: 10,
});
const messages = res.data.messages;
for (let message of messages!) {
try {
const msg = await gmail.users.messages.get({
userId: "me",
id: message.id!,
});
const data = JSON.stringify(msg.data.payload?.body?.data);
const mailBody = Buffer.from(data, "base64").toString();
const dom = new JSDOM(mailBody);
const idx = process.env.NEXT_PUBLIC_ENV_NAME === "local" ? 1 : 0;
const link = dom.window.document.querySelectorAll("p")[idx].textContent;
console.log(link);
return link;
} catch (e) {
console.log(e);
}
}
}
export default defineConfig({
env: {
base_url: process.env.TEST_CYPRESS_BASEURL,
test_email: process.env.NEXT_PUBLIC_AWS_COGNITO_TEST_EMAIL,
},
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
on("task", {
"gmail:check": async (args) => {
const url = await get_login_link();
return url;
},
});
return config;
},
baseUrl: process.env.TEST_CYPRESS_BASEURL,
},
});