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
26 changes: 14 additions & 12 deletions requests/Switcher API.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"info": {
"_postman_id": "cdfeeb52-cd3e-45ec-8478-155390a22621",
"_postman_id": "0cc46f7a-eeac-44a1-909e-4240909b7614",
"name": "Switcher API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "9436108"
},
"item": [
{
Expand Down Expand Up @@ -4457,7 +4458,7 @@
"query": [
{
"key": "",
"value": null,
"value": "",
"disabled": true
}
]
Expand Down Expand Up @@ -4504,7 +4505,7 @@
"query": [
{
"key": "",
"value": null,
"value": "",
"disabled": true
}
]
Expand Down Expand Up @@ -4551,7 +4552,7 @@
"query": [
{
"key": "",
"value": null,
"value": "",
"disabled": true
}
]
Expand Down Expand Up @@ -4606,7 +4607,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n\t\"domain\": \"My Domain\",\n\t\"component\": \"CustomerAPI\",\n\t\"environment\": \"default\"\n}",
"raw": "{\n\t\"domain\": \"Test Domain\",\n\t\"component\": \"App\",\n\t\"environment\": \"default\"\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -4667,15 +4668,15 @@
],
"body": {
"mode": "raw",
"raw": "{\n\t\"entry\": [\n\t\t{\n\t\t\t\"strategy\": \"VALUE_VALIDATION\",\n\t\t\t\"input\": \"Roger\"\n\t\t}]\n}",
"raw": "{\n\t\"entry\": [\n\t\t{\n\t\t\t\"strategy\": \"PAYLOAD_VALIDATION\",\n\t\t\t\"input\": \"{ \\\"status\\\": \\\"ready\\\" }\"\n\t\t}]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/criteria?showReason=true&showStrategy=true&bypassMetric=true&key=FEATURE01",
"raw": "{{url}}/criteria?showReason=true&showStrategy=true&key=TEST_SWITCH",
"host": [
"{{url}}"
],
Expand All @@ -4693,11 +4694,12 @@
},
{
"key": "bypassMetric",
"value": "true"
"value": "true",
"disabled": true
},
{
"key": "key",
"value": "FEATURE01"
"value": "TEST_SWITCH"
}
]
}
Expand Down Expand Up @@ -5063,7 +5065,7 @@
"body": {
"mode": "graphql",
"graphql": {
"query": "{\r\n configuration(domain: \"5e0ece606f4f994eac9007ae\") {\r\n # configuration(domain: \"5e0ece606f4f994eac9007ae\", group: \"Project 2\") {\r\n # configuration(domain: \"5e0ece606f4f994eac9007ae\", group: \"Release 1\") {\r\n # configuration(domain: \"5e0ece606f4f994eac9007ae\", key: \"FEATURE01\", environment: \"default\") {\r\n # configuration(domain: \"5e4f9d8966e06b59c8254500\", key: \"FEATURE01\", environment: \"default\") {\r\n domain {\r\n name\r\n activated\r\n }\r\n group {\r\n name\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n }\r\n config {\r\n key\r\n activated\r\n }\r\n }\r\n}",
"query": "{\r\n configuration(domain: \"5e4f9d8966e06b59c8254500\", key: \"TEST_SWITCH\") {\r\n # configuration(domain: \"5e4f9d8966e06b59c8254500\", configId: \"6270b2fe68bceea783c450b4\") {\r\n # configuration(domain: \"5e4f9d8966e06b59c8254500\", groupId: \"6270b2f568bceea783c45081\") {\r\n # configuration(domain: \"5e4f9d8966e06b59c8254500\", group: \"Test group\") {\r\n # configuration(domain: \"5e0ece606f4f994eac9007ae\", key: \"FEATURE01\", environment: \"default\") {\r\n domain {\r\n name\r\n activated\r\n }\r\n group {\r\n _id\r\n name\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n }\r\n config {\r\n _id\r\n key\r\n activated\r\n }\r\n }\r\n}",
"variables": ""
}
},
Expand Down Expand Up @@ -5128,7 +5130,7 @@
"response": []
},
{
"name": "Client - Configuration (Salck-GraphQL) - Configs",
"name": "Client - Configuration (Slack-GraphQL) - Configs",
"request": {
"method": "POST",
"header": [],
Expand Down
2 changes: 1 addition & 1 deletion src/api-docs/swagger-info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
title: 'Switcher API',
version: 'v1.2.4',
version: 'v1.2.5',
description: 'Switcher API is a Feature Flag API focused on toggling features over different environments and applications.',
contact: {
name: 'Roger Floriano (petruki)',
Expand Down
38 changes: 20 additions & 18 deletions src/client/configuration-resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@ import { getSlack } from '../services/slack';
import { getDomainById } from '../services/domain';
import { getComponents } from '../services/component';

async function resolveConfigByConfig(key, domainId) {
const config = await getConfigs({ key, domain: domainId }, true);
async function resolveConfigByConfig(domainId, key, configId) {
const config = await getConfigs({
id: configId,
key, domain: domainId
}, true);

if (config.length > 0) {
return { config };
} else {
return undefined;
}
}

async function resolveGroup(domainId, groupConfig = undefined) {
let query = {
domain: domainId
};
return undefined;
}

if (groupConfig)
query.name = groupConfig;
async function resolveGroup(domainId, groupConfig, groupId) {
const group = await getGroupConfigs({
id: groupId,
name: groupConfig,
domain: domainId
}, true);

const group = await getGroupConfigs(query, true);
if (group.length > 0) {
return { group };
} else {
return undefined;
}

return undefined;
}

async function resolveSlackInstallation(args) {
Expand All @@ -53,12 +55,12 @@ export async function resolveConfiguration(args, context) {
if (context.domain || args.domain) {
context.environment = args.environment;
context.domain = context.domain || args.domain;
if (args.key) {
return resolveConfigByConfig(args.key, context.domain);
if (args.key || args.config_id) {
return resolveConfigByConfig(context.domain, args.key, args.config_id);
}

if (args.group) {
return resolveGroup(context.domain, args.group);
if (args.group || args.group_id) {
return resolveGroup(context.domain, args.group, args.group_id);
}

return resolveGroup(context.domain);
Expand Down
16 changes: 16 additions & 0 deletions src/client/configuration-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ export const domainType = new GraphQLObjectType({
description: {
type: GraphQLString
},
owner: {
type: GraphQLString
},
transfer: {
type: GraphQLBoolean
},
integrations: {
type: new GraphQLObjectType({
name: 'Integrations',
fields: {
slack: {
type: GraphQLString
}
}
})
},
activated: {
type: GraphQLBoolean,
resolve: (source, _args, { environment }) => {
Expand Down
6 changes: 6 additions & 0 deletions src/client/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ const queryType = new GraphQLObjectType({
group: {
type: GraphQLString
},
group_id: {
type: GraphQLString
},
key: {
type: GraphQLString
},
config_id: {
type: GraphQLString
},
environment: {
type: GraphQLString
},
Expand Down
1 change: 1 addition & 0 deletions src/services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export async function getConfig(where, lean = false) {
export async function getConfigs(where, lean = false) {
const query = Config.find();

if (where.id) query.where('_id', where.id);
if (where.key) query.where('key', where.key);
if (where.domain) query.where('domain', where.domain);
if (where.group) query.where('group', where.group);
Expand Down
1 change: 1 addition & 0 deletions src/services/group-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export async function getGroupConfigById(id, lean = false) {

export async function getGroupConfigs(where, lean = false) {
const query = GroupConfig.find();
if (where.id) query.where('_id', where.id);
if (where.domain) query.where('domain', where.domain);
if (where.name) query.where('name', where.name);
if (lean) query.lean();
Expand Down
21 changes: 21 additions & 0 deletions tests/client-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,16 @@ describe('Testing domain [Adm-GraphQL] ', () => {
expect(JSON.parse(req.text)).toMatchObject(JSON.parse(graphqlUtils.expected108));
});

test('CLIENT_SUITE - Should return domain Flat-structure - By Switcher Id', async () => {
const req = await request(app)
.post('/adm-graphql')
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send(graphqlUtils.configurationQuery([['domain', domainId], ['config_id', configId]]));

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

test('CLIENT_SUITE - Should return domain Flat-structure - By Group', async () => {
const req = await request(app)
.post('/adm-graphql')
Expand All @@ -827,6 +837,17 @@ describe('Testing domain [Adm-GraphQL] ', () => {
expect(result.data.configuration.group[0].name).toEqual('Group Test');
});

test('CLIENT_SUITE - Should return domain Flat-structure - By Group Id', async () => {
const req = await request(app)
.post('/adm-graphql')
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send(graphqlUtils.configurationQuery([['domain', domainId], ['group_id', groupConfigId]]));

const result = JSON.parse(req.text);
expect(req.statusCode).toBe(200);
expect(result.data.configuration.group[0].name).toEqual('Group Test');
});

test('CLIENT_SUITE - Should return domain Flat-structure for a team member', async () => {
const req = await request(app)
.post('/adm-graphql')
Expand Down