-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetOptions.test.js
65 lines (52 loc) · 2.18 KB
/
getOptions.test.js
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
/* eslint-disable */
const { join } = require("path");
const getOptions = require("../src/utils/getOptions");
const {
CF_API_URL,
CF_KEYFILENAME_ENV_NAME,
CF_EMAIL_ENV_NAME,
CF_ID_ENV_NAME,
CF_KEY_ENV_NAME
} = require("../src/constants");
afterEach(() => {
delete process.env[CF_KEYFILENAME_ENV_NAME];
delete process.env.CF_ID;
delete process.env[CF_EMAIL_ENV_NAME];
delete process.env.CF_KEY;
});
test("Passing credential object", () => {
const credentials = require(join(__dirname, "mockCredentials.json"));
const options = getOptions(credentials);
expect(options.baseURL).toBe(`${CF_API_URL}/accounts/${credentials.id}`);
expect(options.headers.common["X-Auth-Email"]).toBe(credentials.email);
expect(options.headers.common["X-Auth-Key"]).toBe(credentials.key);
});
test("Passing path to credentialsFile.json", () => {
const credentialsFile = join(__dirname, "mockCredentials.json");
const credentials = require(credentialsFile);
const options = getOptions(credentialsFile);
expect(options.baseURL).toBe(`${CF_API_URL}/accounts/${credentials.id}`);
expect(options.headers.common["X-Auth-Email"]).toBe(credentials.email);
expect(options.headers.common["X-Auth-Key"]).toBe(credentials.key);
});
test("Relying on path available in global env", () => {
const credentialsFile = join(__dirname, "mockCredentials.json");
const credentials = require(credentialsFile);
process.env[CF_KEYFILENAME_ENV_NAME] = credentialsFile;
const options = getOptions();
expect(options.baseURL).toBe(`${CF_API_URL}/accounts/${credentials.id}`);
expect(options.headers.common["X-Auth-Email"]).toBe(credentials.email);
expect(options.headers.common["X-Auth-Key"]).toBe(credentials.key);
});
test("Relying on credential available in global env", () => {
const CF_ID = "002";
const CF_KEY = "123ABC";
const CF_EMAIL = "[email protected]";
process.env[CF_ID_ENV_NAME] = CF_ID;
process.env[CF_EMAIL_ENV_NAME] = CF_EMAIL;
process.env[CF_KEY_ENV_NAME] = CF_KEY;
const options = getOptions();
expect(options.baseURL).toBe(`${CF_API_URL}/accounts/${CF_ID}`);
expect(options.headers.common["X-Auth-Email"]).toBe(CF_EMAIL);
expect(options.headers.common["X-Auth-Key"]).toBe(CF_KEY);
});