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

Commit

Permalink
Merge pull request #39 from Financial-Times/remove-user-from-licence
Browse files Browse the repository at this point in the history
Remove user from licence
  • Loading branch information
Thurston Tye authored Nov 29, 2017
2 parents 031b394 + 5421779 commit c0d86cb
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 127 deletions.
24 changes: 23 additions & 1 deletion lib/myFTClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ function _createAndTriggerRelationshipRequest (method, node, nodeId, relationshi
*/
function _createAndTriggerKatRelationshipRequest (method, node, data, params, nodeId, memberFollows = false, groupId) {
let theUrl = `${config.MYFT_API_URL}/kat/${node}`;
log.debug({operation: '_createAndTriggerKatRelationshipRequest',node, memberFollows, nodeId,});
log.debug({operation: '_createAndTriggerKatRelationshipRequest',node, memberFollows, nodeId});

if(groupId !== undefined && node === 'group') {
//constructs url to handle relationship request for specific groupIds
Expand Down Expand Up @@ -1025,6 +1025,27 @@ function removeUsersFromLicence (licenceUUID, userUUIDs, options) {
return _addRemoveUsers('DELETE', myftConst.licenceNodeName, licenceUUID, userUUIDs, undefined, options, true);
}

/**
* v3/ Remove users from a licence v3/kat/user/remove
* Special user case were want to remove ALL followed_by_kat and group membership of as user.
* @param {String} licenceUUID - uuid of the licence
* @param {String} userUUID - uuid of the user to remove
* @param {Object} [options] - additional options {supressEvents: true|false, waitForPurge: true|false }
* default behaviour not to supress event generation and wait for a cache purge
* @return {Promise} response -
**/
function removeKatUsersFromLicence (licenceUUID, userUUID) {

const operation = 'myFTClient.removeKatUsersFromLicence';
log.debug({operation, licenceUUID, userUUID});
const theUrl = `${config.MYFT_API_URL}/kat/license/${licenceUUID}/member/user`;
const data = {
userId: userUUID
};

return _doRelationshipRequest ('DELETE', theUrl, data);
}

/**
* Add users to a group
* @param {String} groupUUID - uuid of the licence
Expand Down Expand Up @@ -1359,6 +1380,7 @@ module.exports = {
getGroupsForLicence,
addUsersToLicence,
removeUsersFromLicence,
removeKatUsersFromLicence,
addUsersToGroup,
removeUsersFromGroup,
addGroupsToLicence,
Expand Down
1 change: 0 additions & 1 deletion lib/syncUserFollows.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function userFollows (groupId, userId) {

log.info({operation, subOp: 'newConceptsToFollow', userId, group: groupId, newConceptsCount: newConceptsToFollow.length});
const followProps = Object.assign({}, followedProperties);
followProps.asMemberOf = groupId;
// set the user as being a follower on the new concepts
return myFT.addConceptsFollowedByKatGroupMembSpec(userId, newConceptsToFollow, followProps, groupId)
.then(() => {
Expand Down
266 changes: 141 additions & 125 deletions test/myFTClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const baseUrl = config.MYFT_API_URL;
const extraParams = `?noEvent=${config.MYFT_NO_EVENT}&waitForPurge=${config.MYFT_WAIT_FOR_PURGE_ADD}`;

const myftConst = config.myftClientConstants;
const suppressLogs = false; //for local test if you want logs when test are run
const suppressLogs = true; //for local test if you want logs when test are run

describe('myFT Client proxy', () => {
let logMessageStub;
Expand Down Expand Up @@ -835,172 +835,188 @@ describe('myFT Client proxy', () => {
});
});

//new orgainic v3/kat methods
describe('Followed_by_Kat concepts', () => {
const relProps = Object.assign({}, myFT.followedProperties, {byTool: 'myFTClient.spec', isTest: true});
const {ids, subjects} = require('./mocks/fixtures/userFollowsConceptByKat');
const followedByKatRes = require('./mocks/fixtures/followByKatResp');

afterEach(done => {
nock.cleanAll();
done();
});

it('Should set concept(s) follows by a user ', done => {
nock(baseUrl)
.post('/kat/user/follows')
.query(true)
.reply(200, () => followedByKatRes);

myFT.addConceptsFollowedByKatUser(ids, subjects, relProps)
.then(addResp => {
expect(addResp).to.be.an('array');
expect(addResp[0][0][0]).to.have.deep.property('katRel.type', 'followed_by_kat');
done();
})
.catch(done);
});

it('Should get an array of concepts followed by a group', done => {
nock(baseUrl)
.get(`/group/${uuids.validLicence}/followed_by_kat/concept?page=1&limit=500`)
.reply(200, () => require('./mocks/fixtures/groupFollowedConcept'));
//v3/kat remove users endpoint
describe('Remove user from a licence', () => {

afterEach(() => nock.cleanAll());

myFT.getConceptsFollowedByKatGroup(uuids.validLicence)
.then(followResponse => {
expect(followResponse).to.be.an('array');
expect(followResponse).to.have.lengthOf(1);
expectOwnProperties(followResponse, ['uuid']);
it('should return status of 204 calling /kat/license/:licenceId/member/user remove all of a users relationships related to a given licence', () => {
const removeKatUser = nock(baseUrl)
.delete(`/kat/license/${uuids.validLicence}/member/user`)
.query(true)
.reply(204);

done();
})
.catch(done);
return myFT.removeKatUsersFromLicence(uuids.validLicence, uuids.validUser)
.then((resp) => {
expect(removeKatUser.isDone()).to.equal(true);
expect(resp.status).to.equal(204);
});
});
});

it('Should set concept(s) follows by a group ', done => {

nock(baseUrl)
.post('/kat/group/follows')
.query(true)
.reply(200, () => followedByKatRes);
//new orgainic v3/kat methods
describe('Followed_by_Kat concepts', () => {
const relProps = Object.assign({}, myFT.followedProperties, {byTool: 'myFTClient.spec'});
const {ids, subjects} = require('./mocks/fixtures/userFollowsConceptByKat');
const followedByKatRes = require('./mocks/fixtures/followByKatResp');

myFT.addConceptsFollowedByKatGroup(ids, subjects, relProps)
.then(addResp => {
expect(addResp).to.be.an('array');
expect(addResp[0][0][0]).to.be.an('Object');
expect(addResp[0][0][0]).to.have.deep.property('katRel.type', 'followed_by_kat');
//TODO specify what to expect from addResp
done();
})
.catch(done);
});
afterEach(() => nock.cleanAll());

it('Should remove concept(s) followed by a single user', done => {
const userId = '00000000-0000-0000-0000-000000000002';
it('Should set concept(s) follows by a user ', done => {
nock(baseUrl)
.delete('/kat/user/follows',{
ids: [userId], // The next-myft-api expects an array of user IDs
subjects: subjects
})
.post('/kat/user/follows')
.query(true)
.reply(204, () => ({}));

myFT.removeConceptsFollowedByKatUser(userId, subjects)
.then(addResp => {
expect(addResp).to.be.an('Object');
expect(addResp.status).to.equal(204);
.reply(200, () => followedByKatRes);

done();
})
.catch(done);
});
myFT.addConceptsFollowedByKatUser(ids, subjects, relProps)
.then(addResp => {
expect(addResp).to.be.an('array');
expect(addResp[0][0][0]).to.have.deep.property('katRel.type', 'followed_by_kat');
done();
})
.catch(done);
});

it('Should remove concept(s) followed by a group', done => {
nock(baseUrl)
.delete('/kat/group/follows')
.query(true)
.reply(204);
it('Should get an array of concepts followed by a group', done => {
nock(baseUrl)
.get(`/group/${uuids.validLicence}/followed_by_kat/concept?page=1&limit=500`)
.reply(200, () => require('./mocks/fixtures/groupFollowedConcept'));


myFT.removeConceptsFollowedByKatGroup(ids, subjects)
.then(addResp => {
expect(addResp).to.be.an('Object');
expect(addResp.status).to.equal(204);
myFT.getConceptsFollowedByKatGroup(uuids.validLicence)
.then(followResponse => {
expect(followResponse).to.be.an('array');
expect(followResponse).to.have.lengthOf(1);
expectOwnProperties(followResponse, ['uuid']);

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

it('Should add concept(s) follows for members of a group', done => {
it('Should set concept(s) follows by a group ', done => {

nock(baseUrl)
.post('/kat/group/user/follows')
.query(true)
.reply(200, () => []);
nock(baseUrl)
.post('/kat/group/follows')
.query(true)
.reply(200, () => followedByKatRes);

myFT.addConceptsFollowedByKatGroup(ids, subjects, relProps)
.then(addResp => {
expect(addResp).to.be.an('array');
expect(addResp[0][0][0]).to.be.an('Object');
expect(addResp[0][0][0]).to.have.deep.property('katRel.type', 'followed_by_kat');
//TODO specify what to expect from addResp
done();
})
.catch(done);
});

myFT.addConceptsFollowedByKatGroupMembers(ids, subjects)
.then(addResp => {
expect(addResp).to.be.an('array');
//TODO specify what to expect from addResp Postman returns an empty array in an empty array?
it('Should remove concept(s) followed by a single user', done => {
const userId = '00000000-0000-0000-0000-000000000002';
nock(baseUrl)
.delete('/kat/user/follows',{
ids: [userId], // The next-myft-api expects an array of user IDs
subjects: subjects
})
.query(true)
.reply(204, () => ({}));

done();
})
.catch(done);
});
myFT.removeConceptsFollowedByKatUser(userId, subjects)
.then(addResp => {
expect(addResp).to.be.an('Object');
expect(addResp.status).to.equal(204);

it('Should remove concept(s) follows for user of a group', done => {
done();
})
.catch(done);
});

nock(baseUrl)
.delete('/kat/group/user/follows')
.query(true)
.reply(204);
it('Should remove concept(s) followed by a group', done => {
nock(baseUrl)
.delete('/kat/group/follows')
.query(true)
.reply(204);


myFT.removeConceptsFollowedByKatGroupMembers(ids, subjects)
.then(addResp => {
expect(addResp).to.be.an('array');
myFT.removeConceptsFollowedByKatGroup(ids, subjects)
.then(addResp => {
expect(addResp).to.be.an('Object');
expect(addResp.status).to.equal(204);

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

it('Should add follows to an array users added to a group', done => {
const groupId = '00000000-0000-0000-0000-000000000666';
it('Should add concept(s) follows for members of a group', done => {

nock(baseUrl)
.post(`/kat/group/${groupId}/user/follows`)
.post('/kat/group/user/follows')
.query(true)
.reply(200, () => []);

myFT.addConceptsFollowedByKatGroupMembSpec(ids, subjects,relProps,groupId)
.then(addResp => {
expect(addResp).to.be.an('array');

done();
})
.catch(done);
});
myFT.addConceptsFollowedByKatGroupMembers(ids, subjects)
.then(addResp => {
expect(addResp).to.be.an('array');
//TODO specify what to expect from addResp Postman returns an empty array in an empty array?

it('Should remove follows from an array users associated with a group', done => {
const groupId = '00000000-0000-0000-0000-000000000555';
done();
})
.catch(done);
});

it('Should remove concept(s) follows for user of a group', done => {

nock(baseUrl)
.delete(`/kat/group/${groupId}/user/follows`)
.delete('/kat/group/user/follows')
.query(true)
.reply(204, () => []);
.reply(204);


myFT.removeConceptsFollowedByKatGroupMembers(ids, subjects)
.then(addResp => {
expect(addResp).to.be.an('array');

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

it('Should add follows to an array users added to a group', done => {
const groupId = '00000000-0000-0000-0000-000000000666';

nock(baseUrl)
.post(`/kat/group/${groupId}/user/follows`)
.query(true)
.reply(200, () => []);

myFT.removeConceptsFollowedByKatGroupMembSpec(ids, subjects, relProps, groupId)
myFT.addConceptsFollowedByKatGroupMembSpec(ids, subjects,relProps,groupId)
.then(addResp => {
expect(addResp).to.be.an('array');

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

it('Should remove follows from an array users associated with a group', done => {
const groupId = '00000000-0000-0000-0000-000000000555';

nock(baseUrl)
.delete(`/kat/group/${groupId}/user/follows`)
.query(true)
.reply(204, () => []);

myFT.removeConceptsFollowedByKatGroupMembSpec(ids, subjects, relProps, groupId)
.then(addResp => {
expect(addResp).to.be.an('array');

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

});
});

0 comments on commit c0d86cb

Please sign in to comment.