diff --git a/src/client/resolvers.js b/src/client/resolvers.js index 8e9d061..886afa4 100644 --- a/src/client/resolvers.js +++ b/src/client/resolvers.js @@ -105,14 +105,17 @@ export async function resolveGroupConfig(source, _id, name, activated, context) export async function resolveDomain(_id, name, activated, context) { const args = {}; - if (_id) { args._id = _id; } - if (name) { - if (context.admin) { - args.name = name; + // When Admin + if (context.admin) { + if (name) { + args.name = name; args.owner = context.admin._id; } else { - args._id = context.domain; + args._id = _id; } + // When Component + } else if (context.domain) { + args._id = context.domain; } let domain = await Domain.findOne({ ...args }).lean().exec(); diff --git a/tests/client-api.test.js b/tests/client-api.test.js index a483c48..5ea7650 100644 --- a/tests/client-api.test.js +++ b/tests/client-api.test.js @@ -418,7 +418,6 @@ describe('Testing domain', () => { .post('/graphql') .set('Authorization', `Bearer ${token}`) .send(graphqlUtils.domainQuery([ - ['name', domainDocument.name], ['environment', EnvType.DEFAULT]]) ); @@ -432,7 +431,6 @@ describe('Testing domain', () => { .post('/graphql') .set('Authorization', `Bearer ${token}`) .send(graphqlUtils.domainQuery([ - ['name', domainDocument.name], ['environment', EnvType.DEFAULT], ['_component', 'TestApp']]) ); @@ -448,7 +446,6 @@ describe('Testing domain', () => { .post('/graphql') .set('Authorization', `Bearer ${token}`) .send(graphqlUtils.domainQuery([ - ['name', domainDocument.name], ['environment', EnvType.DEFAULT]], true, true, true) ); @@ -851,6 +848,17 @@ describe('Testing domain [Adm-GraphQL] ', () => { expect(JSON.parse(req.text)).toMatchObject(JSON.parse(graphqlUtils.expected107)); }); + test('CLIENT_SUITE - Should NOT return domain structure - Missing query params', async () => { + const req = await request(app) + .post('/adm-graphql') + .set('Authorization', `Bearer ${adminAccountToken}`) + .send(graphqlUtils.domainQuery([['environment', EnvType.DEFAULT]])); + + const expected = '{"data":{"domain":null}}'; + expect(req.statusCode).toBe(200); + expect(JSON.parse(req.text)).toMatchObject(JSON.parse(expected)); + }); + test('CLIENT_SUITE - Should return domain Flat-structure - By Switcher Key', async () => { const req = await request(app) .post('/adm-graphql')