Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvpickering committed Aug 29, 2022
1 parent b330985 commit 094de29
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ const config = {
adminSub: ADMIN_SUB[process.env.AWS_ACCOUNT_ID],
};


// We are in permanent develop staging environment
if (config.clusterEnv === 'staging' && config.sandboxId === 'default') {
config.workerInstanceConfigUrl = `https://raw.githubusercontent.com/${githubOrganisationName}/iac/master/releases/staging/worker.yaml`;
Expand Down
32 changes: 30 additions & 2 deletions tests/config/__snapshots__/default-config-production.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`default-config Returns correct values for production 1`] = `
exports[`default-config Returns correct values for BIOMAGE production 1`] = `
Object {
"adminSub": "032abd44-0cd3-4d58-af21-850ca0b95ac7",
"api": Object {
"prefix": "/",
},
"awsAccountId": "000000000000",
"awsAccountId": "242905224710",
"awsRegion": "eu-west-1",
"cachingEnabled": true,
"clusterEnv": "production",
Expand All @@ -28,3 +28,31 @@ Object {
"workerNamespace": "worker-default",
}
`;

exports[`default-config Returns correct values for HMS production 1`] = `
Object {
"adminSub": "a01e8bcc-c9a2-4c56-bd66-39de93764be8",
"api": Object {
"prefix": "/",
},
"awsAccountId": "160782110667",
"awsRegion": "eu-west-1",
"cachingEnabled": true,
"clusterEnv": "production",
"cognitoISP": mockConstructor {
"CALL_EVENTS_BUBBLE": [MockFunction],
"MONITOR_EVENTS_BUBBLE": [MockFunction],
},
"corsOriginUrl": "https://localhost:5000",
"domainName": "localhost:5000",
"githubToken": undefined,
"pipelineInstanceConfigUrl": "https://raw.githubusercontent.com/hms-dbmi-cellenics/iac/master/releases/production/pipeline.yaml",
"pipelineNamespace": "pipeline-default",
"podName": "local",
"port": 3000,
"rdsSandboxId": "default",
"sandboxId": "default",
"workerInstanceConfigUrl": "https://raw.githubusercontent.com/hms-dbmi-cellenics/iac/master/releases/production/worker.yaml",
"workerNamespace": "worker-default",
}
`;
39 changes: 38 additions & 1 deletion tests/config/default-config-production.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,48 @@ describe('default-config', () => {
process.env = OLD_ENV;
});

it('Returns correct values for production', () => {
it('Returns correct values for BIOMAGE production', () => {
const prodEnvironment = 'production';
process.env.K8S_ENV = prodEnvironment;
process.env.CLUSTER_ENV = prodEnvironment;
process.env.AWS_DEFAULT_REGION = 'eu-west-1';
process.env.AWS_ACCOUNT_ID = '242905224710';

const userPoolId = 'mockUserPoolId';
const accountId = 'mockAccountId';

AWS.CognitoIdentityServiceProvider = jest.fn(() => ({
listUserPools: {
promise: jest.fn(() => Promise.resolve(
{ UserPools: [{ id: userPoolId, Name: `biomage-user-pool-case-insensitive-${prodEnvironment}` }] },
)),
},
}));

AWS.STS = jest.fn(() => ({
getCallerIdentity: {
promise: jest.fn(() => Promise.resolve({ Account: accountId })),
},
}));

const defaultConfig = jest.requireActual('../../src/config/default-config');

const defaultConfigEntries = Object.entries(defaultConfig);
const filteredEntries = defaultConfigEntries.filter(([, value]) => !isPromise(value));
const defaultConfigFiltered = Object.fromEntries(filteredEntries);

expect(defaultConfigFiltered).toMatchSnapshot();
});

it('Returns correct values for HMS production', () => {
jest.unmock('../../src/config/default-config');
jest.resetModules();

const prodEnvironment = 'production';
process.env.K8S_ENV = prodEnvironment;
process.env.CLUSTER_ENV = prodEnvironment;
process.env.AWS_DEFAULT_REGION = 'eu-west-1';
process.env.AWS_ACCOUNT_ID = '160782110667';

const userPoolId = 'mockUserPoolId';
const accountId = 'mockAccountId';
Expand Down

0 comments on commit 094de29

Please sign in to comment.