Skip to content

Commit

Permalink
Fixes #463 - domain query proper input arg validation (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
petruki authored Nov 9, 2023
1 parent 53bf66d commit 1258918
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
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

0 comments on commit 1258918

Please sign in to comment.