Skip to content

Commit

Permalink
Tdykes.query.for.group.by.id (#88)
Browse files Browse the repository at this point in the history
* filters on schema and statements on logic to handle filter variables.

* lists to test query with filters passed on org and user

* Actually test on a group that exists, so you know... it passes
  • Loading branch information
OSPFNeighbour authored Dec 3, 2017
1 parent 851a02d commit 56c73df
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
10 changes: 8 additions & 2 deletions server/src/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export const userHandler = {
query(_, __, ctx) {
return getAuthenticatedUser(ctx);
},
groups(user) {
groups(user, args) {
if (args.id) {
return user.getGroups({ where: { Id: args.id } });
}
return user.getGroups();
},
events(user) {
Expand Down Expand Up @@ -241,8 +244,11 @@ export const organisationHandler = {
const { name } = args.organisation;
return Creators.organisation({ name });
},
groups(org) {
groups(org, args) {
// TODO: think about who we show the complete organisation group list to
if (args.id) {
return org.getGroups({ where: { Id: args.id } });
}
return org.getGroups();
},
users(org) {
Expand Down
4 changes: 2 additions & 2 deletions server/src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const Schema = [`
id: Int! # unique id for the organisation
name: String!
users: [User]!
groups: [Group]!
groups(id: Int): [Group]!
tags: [Tag]!
capabilities: [Capability]!
}
Expand All @@ -72,7 +72,7 @@ export const Schema = [`
email: String! # we will also require a unique email per user
username: String # this is the name we'll show other users
organisation: Organisation! # the organisation this user belongs to
groups: [Group]! # groups the user belongs to
groups(id: Int): [Group]! # groups the user belongs to
schedules: [Schedule]! # schedules from groups the user belongs to
events: [Event]! # events from groups the user belongs to
devices: [Device]! # devices this user has logged in to
Expand Down
53 changes: 53 additions & 0 deletions server/tests/current-user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ describe('GraphQL query - Current user', () => {
}));
});

describe('Get organisations groups passing filter', () => {
const response = query(`
{
user {
organisation {
id
name
groups(id: 1) {
id
}
}
}
}
`);

itReturnsSuccess(response);
it('Returns correct single group entity', () => response.then((res) => {
expect(res.data.user.organisation.groups.length).toBe(1);
expect(res.data.user.organisation.groups[0]).toHaveProperty('id');
expect(res.data.user.organisation.groups[0].id).toBe(1);
}));
});

describe('Get groups', () => {
const response = query(`
{
Expand All @@ -91,6 +114,36 @@ describe('GraphQL query - Current user', () => {
itReturnsSuccess(response);
});

describe('Get users group by passing filter', () => {
const response = query(`
{
user {
id
groups(id: 2) {
id
schedules {
id
}
events {
id
}
tags {
id
}
}
}
}
`);

itReturnsSuccess(response);
it('Returns correct single entity', () => response.then((res) => {
expect(res.data.user.groups.length).toBe(1);
expect(res.data.user.groups[0]).toHaveProperty('id');
expect(res.data.user.groups[0].id).toBe(2);
expect(res.data.user.groups[0].id).not.toBe(1);
}));
});

describe('Get schedules', () => {
const response = query(`
{
Expand Down

0 comments on commit 56c73df

Please sign in to comment.