-
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(circles): adding and deleting permissions
- Loading branch information
1 parent
e7ece27
commit f95f47b
Showing
4 changed files
with
230 additions
and
0 deletions.
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,103 @@ | ||
const { startServer, stopServer } = require('../../lib/server.js'); | ||
const { request } = require('../scripts/helpers'); | ||
const generator = require('../scripts/generator'); | ||
|
||
describe('Circle add permission', () => { | ||
beforeAll(async () => { | ||
await startServer(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await stopServer(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await generator.clearAll(); | ||
}); | ||
|
||
test('should fail without permission', async () => { | ||
const user = await generator.createUser(); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
const circle = await generator.createCircle(); | ||
const permission = await generator.createPermission(); | ||
|
||
const res = await request({ | ||
uri: '/circles/' + circle.id + '/permissions', | ||
method: 'POST', | ||
headers: { 'X-Auth-Token': token.value }, | ||
body: { permission_id: permission.id } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(403); | ||
expect(res.body.success).toEqual(false); | ||
expect(res.body).toHaveProperty('message'); | ||
expect(res.body).not.toHaveProperty('data'); | ||
}); | ||
|
||
test('should fail if permission is not found', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'put_permissions', object: 'circle' }); | ||
|
||
const circle = await generator.createCircle(); | ||
|
||
const res = await request({ | ||
uri: '/circles/' + circle.id + '/permissions', | ||
method: 'POST', | ||
headers: { 'X-Auth-Token': token.value }, | ||
body: { permission_id: -1 } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(404); | ||
expect(res.body.success).toEqual(false); | ||
expect(res.body).toHaveProperty('message'); | ||
expect(res.body).not.toHaveProperty('data'); | ||
}); | ||
|
||
test('should fail if permission is already there', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'put_permissions', object: 'circle' }); | ||
|
||
const circle = await generator.createCircle(); | ||
const permission = await generator.createPermission(); | ||
await generator.createCirclePermission(circle, permission); | ||
|
||
const res = await request({ | ||
uri: '/circles/' + circle.id + '/permissions', | ||
method: 'POST', | ||
headers: { 'X-Auth-Token': token.value }, | ||
body: { permission_id: permission.id } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(422); | ||
expect(res.body.success).toEqual(false); | ||
expect(res.body).toHaveProperty('errors'); | ||
expect(res.body).not.toHaveProperty('data'); | ||
}); | ||
|
||
test('should succeed if everything\'s okay', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'put_permissions', object: 'circle' }); | ||
|
||
const circle = await generator.createCircle(); | ||
const permission = await generator.createPermission(); | ||
|
||
const res = await request({ | ||
uri: '/circles/' + circle.id + '/permissions', | ||
method: 'POST', | ||
headers: { 'X-Auth-Token': token.value }, | ||
body: { permission_id: permission.id } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).toHaveProperty('message'); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
}); | ||
}); |
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,80 @@ | ||
const { startServer, stopServer } = require('../../lib/server.js'); | ||
const { request } = require('../scripts/helpers'); | ||
const generator = require('../scripts/generator'); | ||
|
||
describe('Circle add permission', () => { | ||
beforeAll(async () => { | ||
await startServer(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await stopServer(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await generator.clearAll(); | ||
}); | ||
|
||
test('should fail without permission', async () => { | ||
const user = await generator.createUser(); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
const circle = await generator.createCircle(); | ||
const permission = await generator.createPermission(); | ||
await generator.createCirclePermission(circle, permission); | ||
|
||
const res = await request({ | ||
uri: '/circles/' + circle.id + '/permissions/' + permission.id, | ||
method: 'DELETE', | ||
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 fail if permission doesn\'t beleong to circle', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'put_permissions', object: 'circle' }); | ||
|
||
const circle = await generator.createCircle(); | ||
const permission = await generator.createPermission(); | ||
|
||
const res = await request({ | ||
uri: '/circles/' + circle.id + '/permissions/' + permission.id, | ||
method: 'DELETE', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(404); | ||
expect(res.body.success).toEqual(false); | ||
expect(res.body).toHaveProperty('message'); | ||
expect(res.body).not.toHaveProperty('data'); | ||
}); | ||
|
||
test('should succeed if everything\'s okay', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'put_permissions', object: 'circle' }); | ||
|
||
const circle = await generator.createCircle(); | ||
const permission = await generator.createPermission(); | ||
await generator.createCirclePermission(circle, permission); | ||
|
||
const res = await request({ | ||
uri: '/circles/' + circle.id + '/permissions/' + permission.id, | ||
method: 'DELETE', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).toHaveProperty('message'); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
}); | ||
}); |