From 455e34dd0f5ecd12d8e9ecc84b5304f0721b3e82 Mon Sep 17 00:00:00 2001 From: r0hit-gupta Date: Fri, 5 Jul 2019 17:07:26 +0530 Subject: [PATCH 1/2] add tests for templateId --- src/routes/projects/update.spec.js | 81 ++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/src/routes/projects/update.spec.js b/src/routes/projects/update.spec.js index f1cb51ef..4d1ec1d9 100644 --- a/src/routes/projects/update.spec.js +++ b/src/routes/projects/update.spec.js @@ -66,6 +66,7 @@ describe('Project', () => { details: {}, createdBy: 1, updatedBy: 1, + templateId: 1, lastActivityAt: 1, lastActivityUserId: '1', createdAt: '2016-06-30 00:33:07+00', @@ -79,6 +80,7 @@ describe('Project', () => { details: {}, createdBy: 1, updatedBy: 1, + templateId: 1, lastActivityAt: 1, lastActivityUserId: '1', createdAt: '2016-06-30 00:33:07+00', @@ -91,6 +93,7 @@ describe('Project', () => { details: {}, createdBy: 1, updatedBy: 1, + templateId: 1, lastActivityAt: 1, lastActivityUserId: '1', createdAt: '2016-06-30 00:33:07+00', @@ -179,6 +182,84 @@ describe('Project', () => { }); }); + it('should not update the templateId for admin', (done) => { + request(server) + .patch(`/v4/projects/${project1.id}`) + .set({ + Authorization: `Bearer ${testUtil.jwts.admin}`, + }) + .send({ + param: { + templateId: '2', + }, + }) + .expect('Content-Type', /json/) + .expect(200) + .end((err, res) => { + if (err) { + done(err); + } else { + const result = res.body.result; + result.success.should.be.true; + result.status.should.equal(200); + result.content.templateId.should.not.equal('2'); + done(); + } + }); + }); + + it('should not update the templateId for manager', (done) => { + request(server) + .patch(`/v4/projects/${project1.id}`) + .set({ + Authorization: `Bearer ${testUtil.jwts.manager}`, + }) + .send({ + param: { + templateId: '2', + }, + }) + .expect('Content-Type', /json/) + .expect(200) + .end((err, res) => { + if (err) { + done(err); + } else { + const result = res.body.result; + result.success.should.be.true; + result.status.should.equal(200); + result.content.templateId.should.not.equal('2'); + done(); + } + }); + }); + + it('should not update the templateId for user', (done) => { + request(server) + .patch(`/v4/projects/${project1.id}`) + .set({ + Authorization: `Bearer ${testUtil.jwts.member}`, + }) + .send({ + param: { + templateId: '2', + }, + }) + .expect('Content-Type', /json/) + .expect(403) + .end((err, res) => { + if (err) { + done(err); + } else { + const result = res.body.result; + result.success.should.be.false; + result.status.should.equal(403); + result.content.message.should.equal('You do not have permissions to perform this action'); + done(); + } + }); + }); + it('should return 200 if topcoder manager user will update a project', (done) => { request(server) .patch(`/v4/projects/${project1.id}`) From 0c86bfa0cebe1904502b00aa162cab4c640786b6 Mon Sep 17 00:00:00 2001 From: r0hit-gupta Date: Mon, 8 Jul 2019 16:45:46 +0530 Subject: [PATCH 2/2] update tests --- src/routes/projects/update.spec.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/routes/projects/update.spec.js b/src/routes/projects/update.spec.js index 4d1ec1d9..8f76cc57 100644 --- a/src/routes/projects/update.spec.js +++ b/src/routes/projects/update.spec.js @@ -122,6 +122,12 @@ describe('Project', () => { userId: 40051332, createdBy: 1, updatedBy: 1, + }, { + projectId: project1.id, + role: 'member', + userId: 40051331, + createdBy: 1, + updatedBy: 1, }]); }).then(() => done()); }); @@ -190,7 +196,7 @@ describe('Project', () => { }) .send({ param: { - templateId: '2', + templateId: 2, }, }) .expect('Content-Type', /json/) @@ -202,7 +208,7 @@ describe('Project', () => { const result = res.body.result; result.success.should.be.true; result.status.should.equal(200); - result.content.templateId.should.not.equal('2'); + result.content.templateId.should.equal(project1.templateId); done(); } }); @@ -216,7 +222,7 @@ describe('Project', () => { }) .send({ param: { - templateId: '2', + templateId: 2, }, }) .expect('Content-Type', /json/) @@ -228,7 +234,7 @@ describe('Project', () => { const result = res.body.result; result.success.should.be.true; result.status.should.equal(200); - result.content.templateId.should.not.equal('2'); + result.content.templateId.should.equal(project1.templateId); done(); } }); @@ -242,19 +248,19 @@ describe('Project', () => { }) .send({ param: { - templateId: '2', + templateId: 2, }, }) .expect('Content-Type', /json/) - .expect(403) + .expect(200) .end((err, res) => { if (err) { done(err); } else { const result = res.body.result; - result.success.should.be.false; - result.status.should.equal(403); - result.content.message.should.equal('You do not have permissions to perform this action'); + result.success.should.be.true; + result.status.should.equal(200); + result.content.templateId.should.equal(project1.templateId); done(); } });