Skip to content

Commit

Permalink
feat(core): groups tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonny22094 committed Oct 29, 2018
1 parent 5111625 commit e429d15
Showing 1 changed file with 82 additions and 25 deletions.
107 changes: 82 additions & 25 deletions packages/lib-js-core/test/unit/groups.js
Expand Up @@ -8,7 +8,17 @@ chai.should()

describe('Groups', () => {
const instanceName = 'testInstance'
const groupName = "testGroup"
const user = {
id: 1,
username: 'testUser',
}
const testGroup = {
id: 1,
label: "testGroup",
description: ''
}
const GROUPS_URL = `/v2/instances/${instanceName}/groups/`
const USER_GROUPS_URL = `/v2/instances/${instanceName}/users/${user.id}/groups/`
let api
let groups

Expand All @@ -23,57 +33,104 @@ describe('Groups', () => {

describe('#list', () => {
it('get list of groups', async () => {
api.get(GROUPS_URL).reply(200, {next: null, objects: ['admin', 'mod']})

const list = await groups.list()

list.should.be.a('array')
list.should.have.lengthOf(2)
})
})

describe('#create', () => {
it('Create group', async () => {
const group = await groups.create(groupName, 'Test group')
describe('#get', () => {
it('get group', async () => {
api.get(`${GROUPS_URL}1/users/`).reply(200, {objects: []})
api.get(GROUPS_URL).reply(200, {
next: null,
objects: [testGroup]
})

const group = await groups.get(testGroup.label)

group.should.be.a('object')
group.should.have.property('id')
group.should.have.property('label').equal(groupName)
group.should.have.property('label').equal(testGroup.label)
group.should.have.property('users')
})
})

describe('#get', () => {
it('get group', async () => {
const group = await groups.get(groupName)
describe('#create', () => {
it('create group', async () => {
api.get(GROUPS_URL).reply(200, {next: null, objects: []})
api.post(GROUPS_URL, body => {
return body.label && body.description
}).reply(200, (url, {label, description}) => ({
id: 1,
label,
description: ''
}))

const group = await groups.create(testGroup.label, 'Test group')

group.should.be.a('object')
group.should.have.property('id')
group.should.have.property('label').equal(groupName)
group.should.have.property('label').equal(testGroup.label)
})
})

describe('#addUser', () => {
it('add user to group', async () => {
const user = await groups.addUser(groupName, 1)
describe('#delete', () => {
it('delete group', () => {
api.delete(`${GROUPS_URL}1/`).reply(200)
api.get(`${GROUPS_URL}1/users/`).reply(200, {objects: []})
api.get(GROUPS_URL).reply(200, {
next: null,
objects: [testGroup]
})

user.should.be.a('object')
user.should.have.property('user')
groups.delete(testGroup.label)
})
})

describe('#removeUser', () => {
it('remove user from group', () => {
groups.removeUser(groupName, 1)
describe('#user', () => {
it('get user groups', async () => {
api.get(USER_GROUPS_URL).reply(200, {
objects: [testGroup]
})
const userGroups = await groups.user(1)

userGroups.should.be.a('array')
})
})

describe('#delete', () => {
it('delete group', () => {
groups.delete(groupName)
describe('#addUser', () => {
it('add user to group', async () => {
api.get(`${GROUPS_URL}1/users/`).reply(200, {objects: []})
api.get(GROUPS_URL).reply(200, {
next: null,
objects: [testGroup]
})
api.post(`${GROUPS_URL}1/users/`, body => body.user).reply(200, {
user: {
id: 1,
username: 'user'
}
})

const user = await groups.addUser(testGroup.label, 1)

user.should.have.property('user')
})
})

describe('#user', () => {
it('get user groups', async () => {
const userGroups = await groups.user(1)
describe('#removeUser', () => {
it('remove user from group', () => {
api.delete(`${GROUPS_URL}1/users/1/`).reply(200)
api.get(`${GROUPS_URL}1/users/`).reply(200, {objects: []})
api.get(GROUPS_URL).reply(200, {
next: null,
objects: [testGroup]
})

userGroups.should.be.a('object')
groups.removeUser(testGroup.label, 1)
})
})
})

0 comments on commit e429d15

Please sign in to comment.