Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/models/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ const configSchema = new mongoose.Schema({
auth_token: {
type: Map,
of: String
},
verification_code: {
type: String
},
verified: {
type: Boolean,
default: false
}
}
}, {
Expand Down
79 changes: 40 additions & 39 deletions tests/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Testing configuration insertion', () => {
}).expect(201);

// DB validation - document created
const config = await Config.findById(response.body._id).lean();
const config = await Config.findById(response.body._id).lean().exec();
expect(config).not.toBeNull();

// Response validation
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('Testing fetch configuration info', () => {

test('CONFIG_SUITE - Should get Configs by sorting ascending and descending', async () => {
// given a config that was sent to the past
const configKey1 = await Config.findOne({ key: 'TEST_CONFIG_KEY_1' });
const configKey1 = await Config.findOne({ key: 'TEST_CONFIG_KEY_1' }).exec();
let pastDate = new Date(configKey1.createdAt);
pastDate.setDate(pastDate.getDate() - 2);
configKey1.createdAt = pastDate;
Expand Down Expand Up @@ -195,43 +195,43 @@ describe('Testing configuration deletion', () => {

test('CONFIG_SUITE - Should delete Config', async () => {
// DB validation Before deleting
let domain = await Domain.findById(domainId).lean();
let domain = await Domain.findById(domainId).lean().exec();
expect(domain).not.toBeNull();

let group = await GroupConfig.findById(groupConfigId).lean();
let group = await GroupConfig.findById(groupConfigId).lean().exec();
expect(group).not.toBeNull();

let config1 = await Config.findById(configId1).lean();
let config1 = await Config.findById(configId1).lean().exec();
expect(config1).not.toBeNull();

let config2 = await Config.findById(configId2).lean();
let config2 = await Config.findById(configId2).lean().exec();
expect(config2).not.toBeNull();

let configStrategy = await ConfigStrategy.findById(configStrategyId).lean();
let configStrategy = await ConfigStrategy.findById(configStrategyId).lean().exec();
expect(configStrategy).not.toBeNull();

await request(app)
.delete('/config/' + configId1)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send().expect(200);

const admin = await Admin.findById(adminMasterAccountId).lean();
const admin = await Admin.findById(adminMasterAccountId).lean().exec();
expect(admin).not.toBeNull();

// DB validation After - Verify deleted dependencies
domain = await Domain.findById(domainId).lean();
domain = await Domain.findById(domainId).lean().exec();
expect(domain).not.toBeNull();

group = await GroupConfig.findById(groupConfigId).lean();
group = await GroupConfig.findById(groupConfigId).lean().exec();
expect(group).not.toBeNull();

config1 = await Config.findById(configId1).lean();
config1 = await Config.findById(configId1).lean().exec();
expect(config1).toBeNull();

config2 = await Config.findById(configId2).lean();
config2 = await Config.findById(configId2).lean().exec();
expect(config2).not.toBeNull();

configStrategy = await ConfigStrategy.findById(configStrategyId).lean();
configStrategy = await ConfigStrategy.findById(configStrategyId).lean().exec();
expect(configStrategy).toBeNull();
});
});
Expand All @@ -241,7 +241,7 @@ describe('Testing update info', () => {

test('CONFIG_SUITE - Should update Config info', async () => {

let config = await Config.findById(configId1).lean();
let config = await Config.findById(configId1).lean().exec();
expect(config).not.toBeNull();

await request(app)
Expand All @@ -253,7 +253,7 @@ describe('Testing update info', () => {
}).expect(200);

// DB validation - verify flag updated
config = await Config.findById(configId1).lean();
config = await Config.findById(configId1).lean().exec();
expect(config).not.toBeNull();
expect(config.key).toEqual('NEWKEY');
expect(config.description).toEqual('New description');
Expand Down Expand Up @@ -304,7 +304,7 @@ describe('Testing update info', () => {
expect(response.body.activated[EnvType.DEFAULT]).toEqual(false);

// DB validation - verify status updated
const config = await Config.findById(configId1).lean();
const config = await Config.findById(configId1).lean().exec();
expect(config.activated[EnvType.DEFAULT]).toEqual(false);
});
});
Expand Down Expand Up @@ -335,7 +335,7 @@ describe('Testing Environment status change', () => {
expect(response.body.activated['QA']).toEqual(true);

// DB validation - verify status updated
let config = await Config.findById(configId1).lean();
let config = await Config.findById(configId1).lean().exec();
expect(config.activated[EnvType.DEFAULT]).toEqual(true);
expect(config.activated['QA']).toEqual(true);

Expand All @@ -347,7 +347,7 @@ describe('Testing Environment status change', () => {
QA: false
}).expect(200);

config = await Config.findById(configId1).lean();
config = await Config.findById(configId1).lean().exec();
expect(config.activated[EnvType.DEFAULT]).toEqual(true);
expect(config.activated['QA']).toEqual(false);
});
Expand Down Expand Up @@ -396,7 +396,7 @@ describe('Testing Environment status change', () => {
QA1: true
}).expect(200);

let config = await Config.findById(configId1).lean();
let config = await Config.findById(configId1).lean().exec();
expect(config.activated['QA1']).toEqual(true);

await request(app)
Expand All @@ -407,7 +407,7 @@ describe('Testing Environment status change', () => {
}).expect(200);

// DB validation - verify status updated
config = await Config.findById(configId1).lean();
config = await Config.findById(configId1).lean().exec();
expect(config.activated['QA1']).toEqual(undefined);
});

Expand Down Expand Up @@ -444,7 +444,7 @@ describe('Testing Environment status change', () => {
expect(response.body).not.toEqual([]);

// DB validation
let history = await History.find({ elementId: configId }).lean();
let history = await History.find({ elementId: configId }).lean().exec();
expect(history[0].oldValue['description']).toEqual('Description of my new Config');
expect(history[0].newValue['description']).toEqual('New description');

Expand All @@ -456,7 +456,7 @@ describe('Testing Environment status change', () => {
}).expect(200);

// DB validation
history = await History.find({ elementId: configId }).lean();
history = await History.find({ elementId: configId }).lean().exec();
expect(history.length).toEqual(2);
});

Expand Down Expand Up @@ -485,15 +485,15 @@ describe('Testing Environment status change', () => {
});

test('CONFIG_SUITE - Should delete history from a Config element', async () => {
let history = await History.find({ elementId: configId1 }).lean();
let history = await History.find({ elementId: configId1 }).lean().exec();
expect(history.length > 0).toEqual(true);

await request(app)
.delete('/config/history/' + configId1)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send().expect(200);

history = await History.find({ elementId: configId1 }).lean();
history = await History.find({ elementId: configId1 }).lean().exec();
expect(history.length > 0).toEqual(false);
});

Expand Down Expand Up @@ -538,7 +538,7 @@ describe('Testing Environment status change', () => {
env: 'QA3'
}).expect(404);

const config = await Config.findById(configId1).lean();
const config = await Config.findById(configId1).lean().exec();
expect(config.activated[EnvType.DEFAULT]).toEqual(true);
expect(config.activated['QA3']).toEqual(true);
});
Expand Down Expand Up @@ -575,7 +575,7 @@ describe('Testing component association', () => {
}).expect(200);

// DB validation - document updated
const config = await Config.findById(configId1);
const config = await Config.findById(configId1).exec()
expect(config.components.includes(responseComponent.body.component._id)).toBe(true);
});

Expand Down Expand Up @@ -609,7 +609,7 @@ describe('Testing component association', () => {
}).expect(200);

// DB validation - document updated
const config = await Config.findById(configId1).lean();
const config = await Config.findById(configId1).lean().exec();
expect(config.components.length >= 2).toBe(true);
});

Expand Down Expand Up @@ -749,19 +749,19 @@ describe('Testing component association', () => {
}).expect(200);

// DB validation - document updated
const config = await Config.findById(configId1).lean();
const config = await Config.findById(configId1).lean().exec();
expect(config.components.includes(responseComponent.body.component._id)).toEqual(false);
});

test('CONFIG_SUITE - Should remove records from history after deleting element', async () => {
let history = await History.find({ elementId: configId1 }).lean();
let history = await History.find({ elementId: configId1 }).lean().exec();
expect(history.length > 0).toEqual(true);
await request(app)
.delete('/config/' + configId1)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send().expect(200);

history = await History.find({ elementId: configId1 });
history = await History.find({ elementId: configId1 }).exec();
expect(history.length).toEqual(0);
});
});
Expand Down Expand Up @@ -792,7 +792,8 @@ describe('Testing relay association', () => {
.send(bodyRelayProd).expect(200);

// DB validation - document updated
const config = await Config.findById(configId1).lean();
const config = await Config.findById(configId1).lean().exec();
expect(config.relay.verified).toEqual(false);
expect(config.relay.activated['default']).toEqual(true);
expect(config.relay.endpoint['default']).toBe('http://localhost:3001');
expect(config.relay.auth_token['default']).toEqual('123');
Expand Down Expand Up @@ -886,7 +887,7 @@ describe('Testing relay association', () => {
}).expect(200);

// DB validation - document updated
const config = await Config.findById(configId1).lean();
const config = await Config.findById(configId1).lean().exec();
expect(config.relay.type).toEqual('VALIDATION');
expect(config.relay.activated['default']).toEqual(true);
expect(config.relay.endpoint['default']).toBe('http://localhost:3001');
Expand All @@ -906,7 +907,7 @@ describe('Testing relay association', () => {
}).expect(200);

// DB validation - document updated
const config = await Config.findById(configId1).lean();
const config = await Config.findById(configId1).lean().exec();
expect(config.relay.type).toEqual('VALIDATION');
expect(config.relay.activated['default']).toEqual(true);
expect(config.relay.endpoint['default']).toBe('http://localhost:3001');
Expand Down Expand Up @@ -934,7 +935,7 @@ describe('Testing relay association', () => {
}).expect(200);

// DB validation - document updated
let config = await Config.findById(configId1).lean();
let config = await Config.findById(configId1).lean().exec();
expect(config.relay.activated['development']).toEqual(true);
expect(config.relay.endpoint['development']).toBe('http://localhost:7000');
expect(config.relay.auth_token['development']).toEqual('abcd');
Expand All @@ -945,7 +946,7 @@ describe('Testing relay association', () => {
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send().expect(200);

config = await Config.findById(configId1).lean();
config = await Config.findById(configId1).lean().exec();
expect(config.relay.activated['development']).toBe(undefined);
expect(config.relay.endpoint['development']).toBe(undefined);
expect(config.relay.auth_token['development']).toBe(undefined);
Expand All @@ -964,7 +965,7 @@ describe('Testing relay association', () => {
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send().expect(200);

const config = await Config.findById(configId1).lean();
const config = await Config.findById(configId1).lean().exec();
expect(config.relay).toEqual({});
});

Expand Down Expand Up @@ -992,7 +993,7 @@ describe('Testing disable metrics', () => {
}).expect(200);

// DB validation - document updated
const config = await Config.findById(configId1).lean();
const config = await Config.findById(configId1).lean().exec();
expect(config.disable_metrics['default']).toEqual(true);
});

Expand Down Expand Up @@ -1021,7 +1022,7 @@ describe('Testing disable metrics', () => {
}).expect(200);

// DB validation - document updated
let config = await Config.findById(configId1).lean();
let config = await Config.findById(configId1).lean().exec();
expect(config.disable_metrics['development']).toEqual(true);

//test
Expand All @@ -1033,7 +1034,7 @@ describe('Testing disable metrics', () => {
}).expect(200);

// DB validation - document updated
config = await Config.findById(configId1).lean();
config = await Config.findById(configId1).lean().exec();
expect(config.disable_metrics['development']).toEqual(undefined);
});

Expand Down
2 changes: 1 addition & 1 deletion tests/relay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { adminMasterAccountId } from './fixtures/db_api';
import { StrategiesType, ConfigStrategy } from '../src/models/config-strategy';

const changeStrategy = async (strategyId, newOperation, status, environment) => {
const strategy = await ConfigStrategy.findById(strategyId);
const strategy = await ConfigStrategy.findById(strategyId).exec()
strategy.operation = newOperation ? newOperation : strategy.operation;
strategy.activated.set(environment, status !== undefined ? status : strategy.activated.get(environment));
strategy.updatedBy = adminMasterAccountId;
Expand Down