Skip to content

Commit

Permalink
setup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Balestra committed May 25, 2019
1 parent bec3683 commit cd21954
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
TODO
node_modules
credentials.json
/test.js
/testLocal.js
*.log
65 changes: 65 additions & 0 deletions tests/getOptions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* eslint-disable */

const { join } = require("path");
const getOptions = require("../src/utils/getOptions");
const constants = require("../src/constants");

beforeEach(() => {
delete process.env.KEYFILENAME;
delete process.env.CF_ID;
delete process.env.CF_EMAIL;
delete process.env.CF_KEY;
});

test("Passing credential object to getOptions", () => {
const credentials = require(join(__dirname, "mockCredentials.json"));

const options = getOptions(credentials);
expect(options.baseURL).toBe(
`${constants.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(
`${constants.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.KEYFILENAME = credentialsFile;
const options = getOptions();

expect(options.baseURL).toBe(
`${constants.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 = CF_ID;
process.env.CF_EMAIL = CF_EMAIL;
process.env.CF_KEY = CF_KEY;
const options = getOptions();

expect(options.baseURL).toBe(`${constants.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);
});
5 changes: 5 additions & 0 deletions tests/mockCredentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "001",
"key": "ABC123",
"email": "[email protected]"
}

0 comments on commit cd21954

Please sign in to comment.