Skip to content

Commit f6c0657

Browse files
authored
Merge pull request #658 from eisbilir/feature/new-milestone-concept
fix: phase member test spec
2 parents 61363cd + 3c6f384 commit f6c0657

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

src/events/projects/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('projectUpdatedKafkaHandler', () => {
2525
initiatorUserId: 2,
2626
};
2727

28-
const mockedApp = {};
28+
const mockedApp = { logger: console, models };
2929

3030
it('should throw validation exception when payload is empty', async () => {
3131
await expect(projectUpdatedKafkaHandler(mockedApp, topic, {})).to.be.rejectedWith(Error);

src/routes/phaseMembers/delete.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ describe('Delete phase member', () => {
8888
models.ProjectPhaseMember.create({
8989
phaseId,
9090
userId: copilotUser.userId,
91+
createdBy: 1,
92+
updatedBy: 1,
9193
}).then((phaseMember) => {
9294
_.assign(phase, { members: [phaseMember.toJSON()] });
9395
// Index to ES
@@ -112,7 +114,7 @@ describe('Delete phase member', () => {
112114
after((done) => {
113115
testUtil.clearDb(done);
114116
});
115-
describe('DELETE /projects/{projectId}/phases/{phaseId}/members/{memberId}', () => {
117+
describe('DELETE /projects/{projectId}/phases/{phaseId}/members/{userId}', () => {
116118
it('should return 403 for anonymous user', (done) => {
117119
request(server)
118120
.delete(`/v5/projects/${id}/phases/${phaseId}/members/${copilotUser.userId}`)

src/routes/phaseMembers/list.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ describe('List phase members', () => {
2020
let id;
2121
let project;
2222
let phaseId;
23-
let memberId;
2423
const copilotUser = {
2524
handle: testUtil.getDecodedToken(testUtil.jwts.copilot).handle,
2625
userId: testUtil.getDecodedToken(testUtil.jwts.copilot).userId,
@@ -57,8 +56,7 @@ describe('List phase members', () => {
5756
isPrimary: false,
5857
createdBy: 1,
5958
updatedBy: 1,
60-
}).then((member) => {
61-
memberId = member.id;
59+
}).then(() => {
6260
models.ProjectPhase.create({
6361
name: 'test project phase',
6462
projectId: id,
@@ -77,8 +75,9 @@ describe('List phase members', () => {
7775
phaseId = phase.id;
7876
models.ProjectPhaseMember.create({
7977
phaseId,
80-
memberId,
8178
userId: copilotUser.userId,
79+
createdBy: 1,
80+
updatedBy: 1,
8281
}).then((phaseMember) => {
8382
_.assign(phase, { members: [phaseMember.toJSON()] });
8483
// Index to ES
@@ -151,7 +150,6 @@ describe('List phase members', () => {
151150
should.exist(resJson);
152151
resJson.should.have.length(1);
153152
resJson[0].userId.should.be.eql(copilotUser.userId);
154-
resJson[0].memberId.should.be.eql(1);
155153
resJson[0].phaseId.should.be.eql(phaseId);
156154
done();
157155
});

src/routes/phaseMembers/update.spec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ describe('Update phase members', () => {
9191
models.ProjectPhaseMember.create({
9292
phaseId,
9393
userId: copilotUser.userId,
94+
createdBy: 1,
95+
updatedBy: 1,
9496
}).then((phaseMember) => {
9597
_.assign(phase, { members: [phaseMember.toJSON()] });
9698
// Index to ES
@@ -119,7 +121,7 @@ describe('Update phase members', () => {
119121
it('should return 403 for anonymous user', (done) => {
120122
request(server)
121123
.post(`/v5/projects/${id}/phases/${phaseId}/members`)
122-
.send({ memberIds: [copilotUser.userId, memberUser.userId] })
124+
.send({ userIds: [copilotUser.userId, memberUser.userId] })
123125
.expect(403, done);
124126
});
125127

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

@@ -139,7 +141,7 @@ describe('Update phase members', () => {
139141
.set({
140142
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
141143
})
142-
.send({ memberIds: [copilotUser.userId, memberUser.userId] })
144+
.send({ userIds: [copilotUser.userId, memberUser.userId] })
143145
.expect(200)
144146
.end((err, res) => {
145147
const resJson = res.body;
@@ -155,7 +157,7 @@ describe('Update phase members', () => {
155157
.set({
156158
Authorization: `Bearer ${testUtil.jwts.admin}`,
157159
})
158-
.send({ memberIds: [] })
160+
.send({ userIds: [] })
159161
.expect(200)
160162
.end((err, res) => {
161163
const resJson = res.body;
@@ -171,7 +173,7 @@ describe('Update phase members', () => {
171173
.set({
172174
Authorization: `Bearer ${testUtil.jwts.copilot}`,
173175
})
174-
.send({ memberIds: [copilotUser.userId, memberUser.userId] })
176+
.send({ userIds: [copilotUser.userId, memberUser.userId] })
175177
.expect(403, done);
176178
});
177179
});

src/routes/phases/list.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = [
5959
let phases = _.isArray(doc._source.phases) ? doc._source.phases : []; // eslint-disable-line no-underscore-dangle
6060

6161
if (memberOnly && !isAdmin) {
62-
phases = _.filter(phases, phase => _.includes(_.map(_.get(phase, 'members'), 'userId')), req.authUser.userId);
62+
phases = _.filter(phases, phase => _.includes(_.map(_.get(phase, 'members'), 'userId'), req.authUser.userId));
6363
}
6464
// Sort
6565
phases = _.orderBy(phases, [sortColumnAndOrder[0]], [sortColumnAndOrder[1]]);
@@ -110,7 +110,7 @@ module.exports = [
110110
phases = _.map(phases, phase => phase.toJSON());
111111
if (memberOnly && !isAdmin) {
112112
phases = _.filter(phases, phase =>
113-
_.includes(_.map(_.get(phase, 'members'), 'userId')), req.authUser.userId);
113+
_.includes(_.map(_.get(phase, 'members'), 'userId'), req.authUser.userId));
114114
}
115115
// Sort
116116
phases = _.orderBy(phases, [sortColumnAndOrder[0]], [sortColumnAndOrder[1]]);

src/routes/phases/list.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ describe('Project Phases', () => {
8989
const phase = ph.toJSON();
9090
models.ProjectPhaseMember.create({
9191
phaseId: phase.id,
92-
memberId: 1,
9392
userId: copilotUser.userId,
93+
createdBy: 1,
94+
updatedBy: 1,
9495
}).then((phaseMember) => {
9596
_.assign(phase, { members: [phaseMember.toJSON()] });
9697
// Index to ES

0 commit comments

Comments
 (0)