-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathenv-apl.test.ts
93 lines (79 loc) · 2.35 KB
/
env-apl.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { describe, expect, it, vi } from "vitest";
import { AuthData } from "./apl";
import { EnvAPL } from "./env-apl";
const getMockEnvVars = () => ({
SALEOR_APP_TOKEN: "some-token",
SALEOR_APP_ID: "app-id",
SALEOR_API_URL: "https://my-saleor-instance.cloud/graphql/",
});
const getMockAuthData = (): AuthData => ({
saleorApiUrl: "https://my-saleor-instance.cloud/graphql/",
appId: "app-id",
token: "some-token",
jwks: "{}",
domain: "my-saleor-instance.cloud",
});
describe("EnvAPL", () => {
it("Constructs when values are provided in constructor", () => {
const envVars = getMockEnvVars();
expect(
new EnvAPL({
env: {
token: envVars.SALEOR_APP_TOKEN,
appId: envVars.SALEOR_APP_ID,
saleorApiUrl: envVars.SALEOR_API_URL,
},
})
).toBeDefined();
});
it("Prints auth data from \"set\" method in stdout if printAuthDataOnRegister set to \"true\"", async () => {
const envVars = getMockEnvVars();
vi.spyOn(console, "log");
const mockAuthData = getMockAuthData();
await new EnvAPL({
env: {
token: envVars.SALEOR_APP_TOKEN,
appId: envVars.SALEOR_APP_ID,
saleorApiUrl: envVars.SALEOR_API_URL,
},
printAuthDataOnRegister: true,
}).set(mockAuthData);
// eslint-disable-next-line no-console
return expect(console.log).toHaveBeenNthCalledWith(
2,
/**
* Assert stringified values for formatting
*/
`{
"saleorApiUrl": "https://my-saleor-instance.cloud/graphql/",
"appId": "app-id",
"token": "some-token",
"jwks": "{}",
"domain": "my-saleor-instance.cloud"
}`
);
});
it("Returns authData from constructor in get() and getAll()", async () => {
const envVars = getMockEnvVars();
const apl = new EnvAPL({
env: {
token: envVars.SALEOR_APP_TOKEN,
appId: envVars.SALEOR_APP_ID,
saleorApiUrl: envVars.SALEOR_API_URL,
},
printAuthDataOnRegister: true,
});
expect(await apl.get(envVars.SALEOR_API_URL)).toEqual({
token: envVars.SALEOR_APP_TOKEN,
appId: envVars.SALEOR_APP_ID,
saleorApiUrl: envVars.SALEOR_API_URL,
});
expect(await apl.getAll()).toEqual([
{
token: envVars.SALEOR_APP_TOKEN,
appId: envVars.SALEOR_APP_ID,
saleorApiUrl: envVars.SALEOR_API_URL,
},
]);
});
});