-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcontext.test.ts
47 lines (39 loc) · 1.33 KB
/
context.test.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
import axios from "axios";
import { setupRecorder } from "nock-record";
import { buildAuthHeaders } from "../auth";
import { DH } from "../constants";
import { findCfg, findInitialData } from ".";
const id = process.env.MC_TEST_VIDEO_ID;
const channelId = process.env.MC_TEST_CHANNEL_ID;
const credentialsB64 = process.env.MC_TEST_CREDENTIAL_2;
const credentials = credentialsB64
? JSON.parse(Buffer.from(credentialsB64!, "base64").toString())
: undefined;
const enabled = id && channelId && credentialsB64;
const describeif = enabled ? describe : describe.skip;
const mode = (process.env.NOCK_BACK_MODE as any) || "lockdown";
const record = setupRecorder({ mode });
jest.setTimeout(20 * 1000);
describeif("watch", () => {
let watchHtml: string;
beforeAll(async () => {
const { completeRecording } = await record("watch");
const res = await axios.get("https://www.youtube.com", {
headers: {
...DH,
...buildAuthHeaders(credentials),
},
});
watchHtml = res.data;
completeRecording();
});
it("can parse cfg", async () => {
const cfg = findCfg(watchHtml);
expect(cfg).not.toBeUndefined();
expect(Object.keys(cfg)).toContain("DELEGATED_SESSION_ID");
});
it("can parse initialData", async () => {
const cfg = findInitialData(watchHtml);
expect(cfg).not.toBeUndefined();
});
});