Skip to content
This repository has been archived by the owner on Jul 4, 2019. It is now read-only.

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciprian Lujeru authored and Ciprian Lujeru committed Jul 19, 2017
1 parent 2b68b32 commit a7c2848
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/mocks/fixtures/getGroupFromLicence.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"uuid": "8619e7a0-65b7-446b-9931-4197b3fe0cbf",
"name": "All users",
"_rel": {
"byTool": "KAT",
"created": 1472335707780,
Expand Down
25 changes: 25 additions & 0 deletions test/mocks/fixtures/getGroupUsersByPage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"group": {
"_id": 1,
"labels": ["Group"],
"properties": {
"name": "All users",
"updated": 1500377383712,
"uuid": "8eb26ed7-68c8-44c6-b6ce-52d61500f301"
}
},
"total": 1,
"items": [
{
"uuid": "b2697f93-52d3-4d42-8409-bdf91b09e894",
"_rel": {
"byTool": "KAT",
"created": 1498743272070,
"count": 1,
"updated": 1498743272070,
"byUser": "c62c4485-7183-494c-a947-d754f5cd0a15"
}
}
],
"count": 1
}
52 changes: 52 additions & 0 deletions test/myFTClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,34 @@ describe('myFT Client proxy', () => {
.catch(done);
});

it ('Should be able to update a group', done => {
const newGroupName = 'All users';
if (mockAPI) {
nock(baseUrl)
.put(`/${myftConst.groupNodeName}/${uuids.validLicence}`)
.reply(200, () => ({}));

nock(baseUrl)
.get(`/${myftConst.licenceNodeName}/${uuids.validLicence}/${myftConst.memberRelName}/${myftConst.groupNodeName}/${uuids.validLicence}`)
.reply(200, () => require('./mocks/fixtures/getGroupFromLicence'));
}

myFT.updateGroup(uuids.validLicence, {"name": newGroupName})
.then(resp => {
expect(resp).to.be.an('object');

return myFT.getGroupFromLicence(uuids.validLicence, uuids.validLicence);
})
.then(resp => {
expectOwnProperties(resp, ['uuid', 'name', '_rel']);
expect(resp.uuid).to.equal(uuids.validLicence);
expect(resp.name).to.equal(newGroupName);

done();
})
.catch(done);
});

it ('Should be able to get a valid licence', done => {
if (mockAPI) {
nock(baseUrl)
Expand Down Expand Up @@ -497,6 +525,30 @@ describe('myFT Client proxy', () => {
.catch(done);
});

it ('Should get users registered to a group by pages', done => {
const page = 1;
const limit = 10;
if (mockAPI) {
nock(baseUrl)
.get(`/${myftConst.groupNodeName}/${uuids.validLicence}/${myftConst.memberRelName}/${myftConst.userNodeName}?page=${page}&limit=${limit}`)
.reply(200, () => require('./mocks/fixtures/getGroupUsersByPage'));
}

myFT.getUsersForGroupByPage(uuids.validLicence, { page, limit })
.then(usersResponse => {
expect(usersResponse).to.be.an('object');
expectOwnProperties(usersResponse, ['group', 'total', 'items', 'count']);

const items = usersResponse.items;
expect(items).to.be.an('array');
expect(items.length).to.be.at.least(1);
expectOwnProperties(items, ['uuid']);

done();
})
.catch(done);
});

it ('Should get groups registered to a licence', done => {
if (mockAPI) {
nock(baseUrl)
Expand Down

0 comments on commit a7c2848

Please sign in to comment.