-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(campaigns): list campaign members
- Loading branch information
1 parent
c6d88df
commit 2384274
Showing
4 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
const { startServer, stopServer } = require('../../lib/server.js'); | ||
const { request } = require('../scripts/helpers'); | ||
const generator = require('../scripts/generator'); | ||
|
||
describe('Campaign users list', () => { | ||
beforeAll(async () => { | ||
await startServer(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await stopServer(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await generator.clearAll(); | ||
}); | ||
|
||
test('should fail if no permission', async () => { | ||
const user = await generator.createUser(); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
const campaign = await generator.createCampaign(); | ||
|
||
const res = await request({ | ||
uri: '/campaigns/' + campaign.id + '/members', | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(403); | ||
expect(res.body.success).toEqual(false); | ||
expect(res.body).toHaveProperty('message'); | ||
expect(res.body).not.toHaveProperty('data'); | ||
}); | ||
|
||
test('should succeed when everything is okay', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'view', object: 'member' }); | ||
|
||
const campaign = await generator.createCampaign(); | ||
const otherUser = await generator.createUser({ campaign_id: campaign.id }); | ||
|
||
const res = await request({ | ||
uri: '/campaigns/' + campaign.id + '/members', | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).toHaveProperty('data'); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
|
||
expect(res.body.data.length).toEqual(1); | ||
expect(res.body.data[0].id).toEqual(otherUser.id); | ||
}); | ||
|
||
test('should respect limit and offset', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
const campaign = await generator.createCampaign(); | ||
|
||
await generator.createUser({ campaign_id: campaign.id }); | ||
const member = await generator.createUser({ campaign_id: campaign.id }); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'view', object: 'member' }); | ||
|
||
const res = await request({ | ||
uri: '/campaigns/' + campaign.id + '/members?limit=1&offset=1', // second one should be returned | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).toHaveProperty('data'); | ||
expect(res.body).toHaveProperty('meta'); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
|
||
expect(res.body.data.length).toEqual(1); | ||
expect(res.body.data[0].id).toEqual(member.id); | ||
|
||
expect(res.body.meta.count).toEqual(2); | ||
}); | ||
|
||
test('should respect sorting', async () => { | ||
const campaign = await generator.createCampaign(); | ||
|
||
const firstUser = await generator.createUser({ | ||
first_name: 'aaa', | ||
mail_confirmed_at: new Date(), | ||
superadmin: true, | ||
campaign_id: campaign.id | ||
}); | ||
const token = await generator.createAccessToken({}, firstUser); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'view', object: 'member' }); | ||
|
||
const secondUser = await generator.createUser({ first_name: 'bbb', campaign_id: campaign.id }); | ||
|
||
const res = await request({ | ||
uri: '/campaigns/' + campaign.id + '/members?sort=first_name&direction=desc', // second one should be returned | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).toHaveProperty('data'); | ||
expect(res.body).toHaveProperty('meta'); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
|
||
expect(res.body.data.length).toEqual(2); | ||
expect(res.body.data[0].id).toEqual(secondUser.id); | ||
expect(res.body.data[1].id).toEqual(firstUser.id); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters