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
13 changes: 8 additions & 5 deletions src/client/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 11 additions & 3 deletions tests/client-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ describe('Testing domain', () => {
.post('/graphql')
.set('Authorization', `Bearer ${token}`)
.send(graphqlUtils.domainQuery([
['name', domainDocument.name],
['environment', EnvType.DEFAULT]])
);

Expand All @@ -432,7 +431,6 @@ describe('Testing domain', () => {
.post('/graphql')
.set('Authorization', `Bearer ${token}`)
.send(graphqlUtils.domainQuery([
['name', domainDocument.name],
['environment', EnvType.DEFAULT],
['_component', 'TestApp']])
);
Expand All @@ -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)
);

Expand Down Expand Up @@ -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')
Expand Down