Skip to content

fix: phase member test spec #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/events/projects/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('projectUpdatedKafkaHandler', () => {
initiatorUserId: 2,
};

const mockedApp = {};
const mockedApp = { logger: console, models };

it('should throw validation exception when payload is empty', async () => {
await expect(projectUpdatedKafkaHandler(mockedApp, topic, {})).to.be.rejectedWith(Error);
Expand Down
4 changes: 3 additions & 1 deletion src/routes/phaseMembers/delete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ describe('Delete phase member', () => {
models.ProjectPhaseMember.create({
phaseId,
userId: copilotUser.userId,
createdBy: 1,
updatedBy: 1,
}).then((phaseMember) => {
_.assign(phase, { members: [phaseMember.toJSON()] });
// Index to ES
Expand All @@ -112,7 +114,7 @@ describe('Delete phase member', () => {
after((done) => {
testUtil.clearDb(done);
});
describe('DELETE /projects/{projectId}/phases/{phaseId}/members/{memberId}', () => {
describe('DELETE /projects/{projectId}/phases/{phaseId}/members/{userId}', () => {
it('should return 403 for anonymous user', (done) => {
request(server)
.delete(`/v5/projects/${id}/phases/${phaseId}/members/${copilotUser.userId}`)
Expand Down
8 changes: 3 additions & 5 deletions src/routes/phaseMembers/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('List phase members', () => {
let id;
let project;
let phaseId;
let memberId;
const copilotUser = {
handle: testUtil.getDecodedToken(testUtil.jwts.copilot).handle,
userId: testUtil.getDecodedToken(testUtil.jwts.copilot).userId,
Expand Down Expand Up @@ -57,8 +56,7 @@ describe('List phase members', () => {
isPrimary: false,
createdBy: 1,
updatedBy: 1,
}).then((member) => {
memberId = member.id;
}).then(() => {
models.ProjectPhase.create({
name: 'test project phase',
projectId: id,
Expand All @@ -77,8 +75,9 @@ describe('List phase members', () => {
phaseId = phase.id;
models.ProjectPhaseMember.create({
phaseId,
memberId,
userId: copilotUser.userId,
createdBy: 1,
updatedBy: 1,
}).then((phaseMember) => {
_.assign(phase, { members: [phaseMember.toJSON()] });
// Index to ES
Expand Down Expand Up @@ -151,7 +150,6 @@ describe('List phase members', () => {
should.exist(resJson);
resJson.should.have.length(1);
resJson[0].userId.should.be.eql(copilotUser.userId);
resJson[0].memberId.should.be.eql(1);
resJson[0].phaseId.should.be.eql(phaseId);
done();
});
Expand Down
12 changes: 7 additions & 5 deletions src/routes/phaseMembers/update.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ describe('Update phase members', () => {
models.ProjectPhaseMember.create({
phaseId,
userId: copilotUser.userId,
createdBy: 1,
updatedBy: 1,
}).then((phaseMember) => {
_.assign(phase, { members: [phaseMember.toJSON()] });
// Index to ES
Expand Down Expand Up @@ -119,7 +121,7 @@ describe('Update phase members', () => {
it('should return 403 for anonymous user', (done) => {
request(server)
.post(`/v5/projects/${id}/phases/${phaseId}/members`)
.send({ memberIds: [copilotUser.userId, memberUser.userId] })
.send({ userIds: [copilotUser.userId, memberUser.userId] })
.expect(403, done);
});

Expand All @@ -129,7 +131,7 @@ describe('Update phase members', () => {
.set({
Authorization: `Bearer ${testUtil.jwts.member}`,
})
.send({ memberIds: [copilotUser.userId, memberUser.userId] })
.send({ userIds: [copilotUser.userId, memberUser.userId] })
.expect(403, done);
});

Expand All @@ -139,7 +141,7 @@ describe('Update phase members', () => {
.set({
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
})
.send({ memberIds: [copilotUser.userId, memberUser.userId] })
.send({ userIds: [copilotUser.userId, memberUser.userId] })
.expect(200)
.end((err, res) => {
const resJson = res.body;
Expand All @@ -155,7 +157,7 @@ describe('Update phase members', () => {
.set({
Authorization: `Bearer ${testUtil.jwts.admin}`,
})
.send({ memberIds: [] })
.send({ userIds: [] })
.expect(200)
.end((err, res) => {
const resJson = res.body;
Expand All @@ -171,7 +173,7 @@ describe('Update phase members', () => {
.set({
Authorization: `Bearer ${testUtil.jwts.copilot}`,
})
.send({ memberIds: [copilotUser.userId, memberUser.userId] })
.send({ userIds: [copilotUser.userId, memberUser.userId] })
.expect(403, done);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/routes/phases/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = [
let phases = _.isArray(doc._source.phases) ? doc._source.phases : []; // eslint-disable-line no-underscore-dangle

if (memberOnly && !isAdmin) {
phases = _.filter(phases, phase => _.includes(_.map(_.get(phase, 'members'), 'userId')), req.authUser.userId);
phases = _.filter(phases, phase => _.includes(_.map(_.get(phase, 'members'), 'userId'), req.authUser.userId));
}
// Sort
phases = _.orderBy(phases, [sortColumnAndOrder[0]], [sortColumnAndOrder[1]]);
Expand Down Expand Up @@ -110,7 +110,7 @@ module.exports = [
phases = _.map(phases, phase => phase.toJSON());
if (memberOnly && !isAdmin) {
phases = _.filter(phases, phase =>
_.includes(_.map(_.get(phase, 'members'), 'userId')), req.authUser.userId);
_.includes(_.map(_.get(phase, 'members'), 'userId'), req.authUser.userId));
}
// Sort
phases = _.orderBy(phases, [sortColumnAndOrder[0]], [sortColumnAndOrder[1]]);
Expand Down
3 changes: 2 additions & 1 deletion src/routes/phases/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ describe('Project Phases', () => {
const phase = ph.toJSON();
models.ProjectPhaseMember.create({
phaseId: phase.id,
memberId: 1,
userId: copilotUser.userId,
createdBy: 1,
updatedBy: 1,
}).then((phaseMember) => {
_.assign(phase, { members: [phaseMember.toJSON()] });
// Index to ES
Expand Down