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
2 changes: 1 addition & 1 deletion requests/Switcher Resolver Node.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@
"body": {
"mode": "graphql",
"graphql": {
"query": "query Domain(\r\n $name: String, \r\n $environment: String, \r\n $_component: String) {\r\n domain(\r\n name: $name, \r\n environment: $environment,\r\n _component: $_component\r\n ) {\r\n name\r\n version\r\n description\r\n activated\r\n group {\r\n name\r\n description\r\n activated\r\n config {\r\n key\r\n description\r\n activated\r\n strategies {\r\n strategy\r\n activated\r\n operation\r\n values\r\n }\r\n relay {\r\n type\r\n method\r\n activated\r\n authPrefix\r\n verifiedByEnv { env value }\r\n authTokenByEnv { env value }\r\n statusByEnv { env value }\r\n endpointByEnv { env value }\r\n }\r\n components\r\n }\r\n }\r\n }\r\n}",
"query": "query Domain(\r\n $name: String, \r\n $environment: String, \r\n $_component: String) {\r\n domain(\r\n name: $name, \r\n environment: $environment,\r\n _component: $_component\r\n ) {\r\n name\r\n version\r\n description\r\n activated\r\n group {\r\n name\r\n description\r\n activated\r\n config {\r\n key\r\n description\r\n activated\r\n strategies {\r\n description\r\n strategy\r\n activated\r\n operation\r\n values\r\n }\r\n relay {\r\n type\r\n method\r\n activated\r\n description\r\n authPrefix\r\n verifiedByEnv { env value }\r\n authTokenByEnv { env value }\r\n statusByEnv { env value }\r\n endpointByEnv { env value }\r\n }\r\n components\r\n }\r\n }\r\n }\r\n}",
"variables": "{\r\n \"name\": \"{{domain_name}}\",\r\n \"environment\": \"{{env_name}}\",\r\n \"_component\": \"{{component_name}}\"\r\n}"
}
},
Expand Down
22 changes: 18 additions & 4 deletions src/client/configuration-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ const commonFieldsType = {
export const strategyType = new GraphQLObjectType({
name: 'Strategy',
fields: {
...commonFieldsType,
_id: {
type: GraphQLString
},
description: {
type: GraphQLString
},
strategy: {
type: GraphQLString
},
Expand All @@ -63,8 +65,20 @@ export const strategyType = new GraphQLObjectType({
},
values: {
type: new GraphQLList(GraphQLString)
},
activated: {
type: GraphQLBoolean,
resolve: (source, _args, { environment }) => {
return source.activated[`${environment}`];
}
},
statusByEnv: {
type: new GraphQLList(envStatus),
resolve: (source) => {
return resolveEnvValue(source, 'activated', Object.keys(source.activated));
}
}
}
});

export const relayType = new GraphQLObjectType({
Expand All @@ -76,6 +90,9 @@ export const relayType = new GraphQLObjectType({
method: {
type: GraphQLString,
},
description: {
type: GraphQLString
},
activated: {
type: GraphQLBoolean,
resolve: (source, _args, { environment }) => {
Expand Down Expand Up @@ -204,9 +221,6 @@ export const domainType = new GraphQLObjectType({
name: {
type: GraphQLString
},
description: {
type: GraphQLString
},
owner: {
type: GraphQLString
},
Expand Down
26 changes: 16 additions & 10 deletions src/client/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,31 @@ export async function resolveConfigStrategy(source, _id, strategy, operation, ac
if (operation) { args.operation = operation; }

let strategies = await ConfigStrategy.find({ config: source._id, ...args }).lean().exec();
const environment = context.environment ?? EnvType.DEFAULT;
const environment = context.environment;

strategies = strategies.filter(s => s.activated[environment] !== undefined);
if (activated !== undefined) {
strategies = strategies.filter(s => s.activated[environment] === activated);
if (environment) {
strategies = strategies.filter(s => s.activated[environment] !== undefined);
if (activated !== undefined) {
strategies = strategies.filter(s => s.activated[environment] === activated);
}
}

return strategies;
}

export async function resolveRelay(source, context) {
const relay = source.relay;
const environment = context.environment ?? EnvType.DEFAULT;

if (!relay.type || !relay.endpoint[environment] || (relay.activated[environment] == undefined)) {
const { relay } = source;
const { environment } = context;

if (environment) {
if (relay.activated && relay.activated[environment] !== undefined) {
return relay;
}

return null;
}

return relay;
return relay.type ? relay : null;
}

export async function resolveConfig(source, _id, key, activated, context) {
Expand Down
6 changes: 3 additions & 3 deletions tests/client-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,14 @@ describe('Testing domain [GraphQL]', () => {

afterAll(setupDatabase);

test('CLIENT_SUITE - Should return the Domain structure', async () => {
test('CLIENT_SUITE - Should return the Domain structure for Environment (default)', async () => {
const req = await request(app)
.post('/graphql')
.set('Authorization', `Bearer ${token}`)
.send(graphqlUtils.domainQuery([['_id', domainId], ['environment', EnvType.DEFAULT]], true, true, true));
.send(graphqlUtils.domainQuery([['_id', domainId], ['environment', EnvType.DEFAULT]]));

expect(req.statusCode).toBe(200);
expect(JSON.parse(req.text)).toMatchObject(JSON.parse(graphqlUtils.expected102));
expect(JSON.parse(req.text)).toMatchObject(JSON.parse(graphqlUtils.expected102Default));
});

test('CLIENT_SUITE - Should return 2 switchers when NOT filtered by Component', async () => {
Expand Down
103 changes: 99 additions & 4 deletions tests/graphql-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const domainQuery = (where, group, config, strategy) => {
{
domain(${query}) {
name version description activated statusByEnv { env value }
group${elementQuery(group)} {
group${group !== undefined ? elementQuery(group) : ''} {
name description activated statusByEnv { env value }
config${elementQuery(config)} {
config${config !== undefined ? elementQuery(config) : ''} {
key description activated statusByEnv { env value }
strategies${elementQuery(strategy)} {
strategy activated operation values statusByEnv { env value }
strategies${strategy !== undefined ? elementQuery(strategy): ''} {
strategy activated operation values
}
relay {
type
Expand Down Expand Up @@ -183,6 +183,101 @@ export const expected102 = `
}
}`;

export const expected102Default = `
{
"data": {
"domain": {
"name": "Domain",
"version": 5,
"description": "Test Domain",
"activated": true,
"statusByEnv": [{
"env": "default",
"value": true
}],
"group": [{
"name": "Group Test",
"description": "Test Group",
"activated": true,
"statusByEnv": [{
"env": "default",
"value": true
}],
"config": [{
"key": "TEST_CONFIG_KEY",
"description": "Test config 1",
"activated": true,
"statusByEnv": [{
"env": "default",
"value": true
}],
"strategies": [{
"strategy": "VALUE_VALIDATION",
"activated": true,
"operation": "EXIST",
"values": [
"USER_1",
"USER_2",
"USER_3"
]
}, {
"strategy": "NETWORK_VALIDATION",
"activated": true,
"operation": "EXIST",
"values": [
"10.0.0.0/24"
]
}, {
"strategy": "TIME_VALIDATION",
"activated": false,
"operation": "BETWEEN",
"values": [
"13:00",
"14:00"
]
}, {
"strategy": "DATE_VALIDATION",
"activated": false,
"operation": "GREATER",
"values": [
"2019-12-01T13:00"
]
}],
"relay": {
"type": "NOTIFICATION",
"method": "POST",
"activated": false,
"endpointByEnv": [{
"env": "default",
"value": "http://localhost:3000"
}],
"statusByEnv": [ {
"env": "default",
"value": false
}]
},
"components": ["TestApp"]
},
{
"key": "TEST_CONFIG_KEY_PRD_QA",
"description": "Test config 2 - Off in PRD and ON in QA",
"activated": false,
"statusByEnv": [{
"env": "default",
"value": false
},{
"env": "QA",
"value": true
}],
"strategies": [],
"relay": null,
"components": []
}]
}]
}
}
}`;

export const expected103 = `
{
"data": {
Expand Down