Skip to content

Commit 3687a4a

Browse files
author
Vikas Agarwal
committed
Github issue#1243, Connect Admin role
— added unit tests for connect admin role, tested that it should have all access similar to topcoder admin
1 parent 2cebeca commit 3687a4a

File tree

6 files changed

+321
-3
lines changed

6 files changed

+321
-3
lines changed

src/routes/projects/delete.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,39 @@ describe('Project delete test', () => {
100100
}
101101
});
102102
});
103+
104+
it('should return 204, for connect admin, if project was successfully removed', (done) => {
105+
request(server)
106+
.delete(`/v4/projects/${project1.id}`)
107+
.set({
108+
Authorization: `Bearer ${testUtil.jwts.admin}`,
109+
})
110+
.expect(204)
111+
.end((err) => {
112+
if (err) {
113+
done(err);
114+
} else {
115+
server.services.pubsub.publish.calledWith('project.deleted').should.be.true;
116+
done();
117+
}
118+
});
119+
});
120+
121+
it('should return 204, for connect admin, if project was successfully removed', (done) => {
122+
request(server)
123+
.delete(`/v4/projects/${project1.id}`)
124+
.set({
125+
Authorization: `Bearer ${testUtil.jwts.admin}`,
126+
})
127+
.expect(204)
128+
.end((err) => {
129+
if (err) {
130+
done(err);
131+
} else {
132+
server.services.pubsub.publish.calledWith('project.deleted').should.be.true;
133+
done();
134+
}
135+
});
136+
});
103137
});
104138
});

src/routes/projects/get.spec.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,25 @@ describe('GET Project', () => {
136136
});
137137
});
138138

139+
it('should return the project for connect admin ', (done) => {
140+
request(server)
141+
.get(`/v4/projects/${project1.id}`)
142+
.set({
143+
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
144+
})
145+
.expect('Content-Type', /json/)
146+
.expect(200)
147+
.end((err, res) => {
148+
if (err) {
149+
done(err);
150+
} else {
151+
const resJson = res.body.result.content;
152+
should.exist(resJson);
153+
done();
154+
}
155+
});
156+
});
157+
139158
it('should return attachment with downloadUrl', (done) => {
140159
models.ProjectAttachment.create({
141160
projectId: project1.id,
@@ -172,6 +191,7 @@ describe('GET Project', () => {
172191
.expect('Content-Type', /json/)
173192
.expect(200)
174193
.end((err, res) => {
194+
stub.restore();
175195
if (err) {
176196
done(err);
177197
} else {
@@ -181,7 +201,6 @@ describe('GET Project', () => {
181201
resJson.attachments.should.have.lengthOf(1);
182202
resJson.attachments[0].filePath.should.equal(attachment.filePath);
183203
resJson.attachments[0].downloadUrl.should.exist;
184-
stub.restore();
185204
done();
186205
}
187206
});

src/routes/projects/list-db.spec.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,109 @@ describe('LIST Project db', () => {
300300
}
301301
});
302302
});
303+
304+
describe('for connect admin ', () => {
305+
it('should return the project ', (done) => {
306+
request(server)
307+
.get('/v4/projects/db/?fields=id%2Cmembers.id')
308+
.set({
309+
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
310+
})
311+
.expect('Content-Type', /json/)
312+
.expect(200)
313+
.end((err, res) => {
314+
if (err) {
315+
done(err);
316+
} else {
317+
const resJson = res.body.result.content;
318+
should.exist(resJson);
319+
resJson.should.have.lengthOf(3);
320+
done();
321+
}
322+
});
323+
});
324+
325+
it('should return all projects that match when filtering by name', (done) => {
326+
request(server)
327+
.get('/v4/projects/db/?filter=keyword%3Dtest')
328+
.set({
329+
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
330+
})
331+
.expect('Content-Type', /json/)
332+
.expect(200)
333+
.end((err, res) => {
334+
if (err) {
335+
done(err);
336+
} else {
337+
const resJson = res.body.result.content;
338+
should.exist(resJson);
339+
resJson.should.have.lengthOf(3);
340+
done();
341+
}
342+
});
343+
});
344+
345+
it('should return the project when filtering by keyword, which matches the name', (done) => {
346+
request(server)
347+
.get('/v4/projects/db/?filter=keyword%3D1')
348+
.set({
349+
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
350+
})
351+
.expect('Content-Type', /json/)
352+
.expect(200)
353+
.end((err, res) => {
354+
if (err) {
355+
done(err);
356+
} else {
357+
const resJson = res.body.result.content;
358+
should.exist(resJson);
359+
resJson.should.have.lengthOf(1);
360+
resJson[0].name.should.equal('test1');
361+
done();
362+
}
363+
});
364+
});
365+
366+
it('should return the project when filtering by keyword, which matches the description', (done) => {
367+
request(server)
368+
.get('/v4/projects/db/?filter=keyword%3Dproject')
369+
.set({
370+
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
371+
})
372+
.expect('Content-Type', /json/)
373+
.expect(200)
374+
.end((err, res) => {
375+
if (err) {
376+
done(err);
377+
} else {
378+
const resJson = res.body.result.content;
379+
should.exist(resJson);
380+
resJson.should.have.lengthOf(3);
381+
done();
382+
}
383+
});
384+
});
385+
386+
it('should return the project when filtering by keyword, which matches the details', (done) => {
387+
request(server)
388+
.get('/v4/projects/db/?filter=keyword%3Dcode')
389+
.set({
390+
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
391+
})
392+
.expect('Content-Type', /json/)
393+
.expect(200)
394+
.end((err, res) => {
395+
if (err) {
396+
done(err);
397+
} else {
398+
const resJson = res.body.result.content;
399+
should.exist(resJson);
400+
resJson.should.have.lengthOf(1);
401+
resJson[0].name.should.equal('test1');
402+
done();
403+
}
404+
});
405+
});
406+
});
303407
});
304408
});

src/routes/projects/list.spec.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,109 @@ describe('LIST Project', () => {
387387
}
388388
});
389389
});
390+
391+
describe('GET All /projects/ for Connect Admin, ', () => {
392+
it('should return the project ', (done) => {
393+
request(server)
394+
.get('/v4/projects/?fields=id%2Cmembers.id')
395+
.set({
396+
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
397+
})
398+
.expect('Content-Type', /json/)
399+
.expect(200)
400+
.end((err, res) => {
401+
if (err) {
402+
done(err);
403+
} else {
404+
const resJson = res.body.result.content;
405+
should.exist(resJson);
406+
resJson.should.have.lengthOf(3);
407+
done();
408+
}
409+
});
410+
});
411+
412+
it('should return all projects, that match when filtering by name', (done) => {
413+
request(server)
414+
.get('/v4/projects/?filter=keyword%3Dtest')
415+
.set({
416+
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
417+
})
418+
.expect('Content-Type', /json/)
419+
.expect(200)
420+
.end((err, res) => {
421+
if (err) {
422+
done(err);
423+
} else {
424+
const resJson = res.body.result.content;
425+
should.exist(resJson);
426+
resJson.should.have.lengthOf(3);
427+
done();
428+
}
429+
});
430+
});
431+
432+
it('should return the project, when filtering by keyword, which matches the name', (done) => {
433+
request(server)
434+
.get('/v4/projects/?filter=keyword%3D1')
435+
.set({
436+
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
437+
})
438+
.expect('Content-Type', /json/)
439+
.expect(200)
440+
.end((err, res) => {
441+
if (err) {
442+
done(err);
443+
} else {
444+
const resJson = res.body.result.content;
445+
should.exist(resJson);
446+
resJson.should.have.lengthOf(1);
447+
resJson[0].name.should.equal('test1');
448+
done();
449+
}
450+
});
451+
});
452+
453+
it('should return the project, when filtering by keyword, which matches the description', (done) => {
454+
request(server)
455+
.get('/v4/projects/?filter=keyword%3Dproject')
456+
.set({
457+
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
458+
})
459+
.expect('Content-Type', /json/)
460+
.expect(200)
461+
.end((err, res) => {
462+
if (err) {
463+
done(err);
464+
} else {
465+
const resJson = res.body.result.content;
466+
should.exist(resJson);
467+
resJson.should.have.lengthOf(3);
468+
done();
469+
}
470+
});
471+
});
472+
473+
it('should return the project, when filtering by keyword, which matches the member handle', (done) => {
474+
request(server)
475+
.get('/v4/projects/?filter=keyword%3Dtourist')
476+
.set({
477+
Authorization: `Bearer ${testUtil.jwts.connectAdmin}`,
478+
})
479+
.expect('Content-Type', /json/)
480+
.expect(200)
481+
.end((err, res) => {
482+
if (err) {
483+
done(err);
484+
} else {
485+
const resJson = res.body.result.content;
486+
should.exist(resJson);
487+
resJson.should.have.lengthOf(1);
488+
resJson[0].name.should.equal('test1');
489+
done();
490+
}
491+
});
492+
});
493+
});
390494
});
391495
});

src/routes/projects/update.spec.js

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('Project', () => {
127127
});
128128
});
129129

130-
it('should return 403 if invalid user will launch a project', (done) => {
130+
it('should return 403 if invalid user will update a project', (done) => {
131131
request(server)
132132
.patch(`/v4/projects/${project1.id}`)
133133
.set({
@@ -154,7 +154,7 @@ describe('Project', () => {
154154
});
155155
});
156156

157-
it('should return 200 if topcoder manager user will launch a project', (done) => {
157+
it('should return 200 if topcoder manager user will update a project', (done) => {
158158
request(server)
159159
.patch(`/v4/projects/${project1.id}`)
160160
.set({
@@ -723,5 +723,60 @@ describe('Project', () => {
723723
}
724724
});
725725
});
726+
727+
xdescribe('for connect admin, ', () => {
728+
it('should return 200, connect admin is allowed to transition project out of cancel status', (done) => {
729+
models.Project.update({
730+
status: PROJECT_STATUS.CANCELLED,
731+
}, {
732+
where: {
733+
id: project1.id,
734+
},
735+
})
736+
.then(() => {
737+
const mbody = {
738+
param: {
739+
name: 'updatedProject name',
740+
status: PROJECT_STATUS.ACTIVE,
741+
},
742+
};
743+
request(server)
744+
.patch(`/v4/projects/${project1.id}`)
745+
.set({
746+
Authorization: `Bearer ${testUtil.jwts.admin}`,
747+
})
748+
.send(mbody)
749+
.expect('Content-Type', /json/)
750+
.expect(200)
751+
.end((err, res) => {
752+
if (err) {
753+
done(err);
754+
} else {
755+
const resJson = res.body.result.content;
756+
should.exist(resJson);
757+
resJson.name.should.equal('updatedProject name');
758+
resJson.updatedAt.should.not.equal('2016-06-30 00:33:07+00');
759+
resJson.updatedBy.should.equal(40051333);
760+
server.services.pubsub.publish.calledWith('project.updated').should.be.true;
761+
// validate that project history is updated
762+
models.ProjectHistory.findAll({
763+
where: {
764+
projectId: project1.id,
765+
},
766+
}).then((histories) => {
767+
should.exist(histories);
768+
histories.length.should.equal(1);
769+
const history = histories[0].get({
770+
plain: true,
771+
});
772+
history.status.should.equal(PROJECT_STATUS.ACTIVE);
773+
history.projectId.should.equal(project1.id);
774+
done();
775+
});
776+
}
777+
});
778+
});
779+
});
780+
});
726781
});
727782
});

src/tests/util.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ export default {
2222
manager: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiQ29ubmVjdCBNYW5hZ2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJ0ZXN0MSIsImV4cCI6MjU2MzA3NjY4OSwidXNlcklkIjoiNDAwNTEzMzQiLCJpYXQiOjE0NjMwNzYwODksImVtYWlsIjoidGVzdEB0b3Bjb2Rlci5jb20iLCJqdGkiOiJiMzNiNzdjZC1iNTJlLTQwZmUtODM3ZS1iZWI4ZTBhZTZhNGEifQ.J5VtOEQVph5jfe2Ji-NH7txEDcx_5gthhFeD-MzX9ck',
2323
// userId = 40051335, [ 'Topcoder User' ],handle: 'member2',email: 'test@topcoder.com'
2424
member2: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJtZW1iZXIyIiwiZXhwIjoyNTYzMDc2Njg5LCJ1c2VySWQiOiI0MDA1MTMzNSIsImlhdCI6MTQ2MzA3NjA4OSwiZW1haWwiOiJ0ZXN0QHRvcGNvZGVyLmNvbSIsImp0aSI6ImIzM2I3N2NkLWI1MmUtNDBmZS04MzdlLWJlYjhlMGFlNmE0YSJ9.Mh4bw3wm-cn5Kcf96gLFVlD0kySOqqk4xN3qnreAKL4',
25+
// userId = 40051336, [ 'Connect Admin' ], handle: 'connect_admin1', email: 'connect_admin1@topcoder.com'
26+
connectAdmin: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJDb25uZWN0IEFkbWluIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJjb25uZWN0X2FkbWluMSIsImV4cCI6MjU2MzA3NjY4OSwidXNlcklkIjoiNDAwNTEzMzYiLCJpYXQiOjE0NjMwNzYwODksImVtYWlsIjoiY29ubmVjdF9hZG1pbjFAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.nSGfXMl02NZ90ZKLiEKPg75iAjU92mfteaY6xgqkM30',
2527
},
2628
};

0 commit comments

Comments
 (0)