Skip to content

Commit 09f0715

Browse files
#175 - Update tests
1 parent b23e56b commit 09f0715

File tree

4 files changed

+74
-23
lines changed

4 files changed

+74
-23
lines changed

test/common/testData.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ const testSubmissionWoLegacy = {
155155

156156
const testSubmissionWReview = {
157157
Item: {
158-
challengeId: 30055732,
158+
challengeId: 30055733,
159159
id: 'a12a4180-65aa-42ec-a945-5fd21dec0503',
160160
type: 'ContestSubmission',
161161
url: 'https://s3.amazonaws.com/test-submission/123456',
@@ -164,13 +164,13 @@ const testSubmissionWReview = {
164164
submissionPhaseId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
165165
review: [
166166
{
167-
id: 'd24d4180-65aa-42ec-a945-5fd21dec0501',
167+
id: 'd24d4180-65aa-42ec-a945-5fd21dec0502',
168168
score: 95.5,
169169
legacyReviewId: 1234567891,
170170
typeId: 'c56a4180-65aa-42ec-a945-5fd21dec0503',
171171
reviewerId: 'c23a4180-65aa-42ec-a945-5fd21dec0503',
172172
scoreCardId: 123456789,
173-
submissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0501',
173+
submissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0503',
174174
metadata: {
175175
public: 'public data',
176176
private: 'private data'
@@ -184,7 +184,7 @@ const testSubmissionWReview = {
184184
reviewSummation: [
185185
{
186186
id: 'e45e4180-65aa-42ec-a945-5fd21dec1504',
187-
submissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0501',
187+
submissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0503',
188188
aggregateScore: 99.0,
189189
scoreCardId: 123456789,
190190
isPassing: true,

test/e2e/SubmissionService.test.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const binaryParser = function (res, cb) {
3535
})
3636
}
3737

38-
let submissionId // Used to store submissionId after creating submission
38+
let submissionId // Used to store submissionId after creating submission (Admin user role)
39+
let userSubmissionId // Used to store submissionId after creating submission (Topcoder user role)
3940
let fileSubmissionId // Used to store submissionId after upload file
4041
let fileWithLegacySubmissionId // Used to store submissionId after upload file with legacy
4142

@@ -232,6 +233,25 @@ describe('Submission Service tests', () => {
232233
done()
233234
})
234235
}).timeout(20000)
236+
237+
it('Creating another submission with url passing should get succeeded with user token', (done) => {
238+
chai.request(app)
239+
.post(`${config.API_VERSION}/submissions`)
240+
.set('Authorization', `Bearer ${config.ADMIN_TOKEN}`)
241+
.send(_.omit(testSubmission.Item, ['id', 'created', 'updated', 'createdBy', 'updatedBy']))
242+
.end((err, res) => {
243+
res.should.have.status(200)
244+
res.body.should.have.keys(Object.keys(_.extend({ fileType: 'zip' }, testSubmission.Item)))
245+
res.body.id.should.not.be.eql(null)
246+
userSubmissionId = res.body.id // To be used in future requests
247+
res.body.challengeId.should.be.eql(testSubmission.Item.challengeId)
248+
res.body.type.should.be.eql(testSubmission.Item.type)
249+
res.body.url.should.be.eql(testSubmission.Item.url)
250+
res.body.fileType.should.be.eql('zip')
251+
res.body.submissionPhaseId.should.be.eql(testSubmission.Item.submissionPhaseId)
252+
done()
253+
})
254+
}).timeout(20000)
235255
})
236256

237257
/*
@@ -624,17 +644,6 @@ describe('Submission Service tests', () => {
624644
})
625645
})
626646

627-
it('Deleting submission with user token should throw 403', (done) => {
628-
chai.request(app)
629-
.delete(`${config.API_VERSION}/submissions/${submissionId}`)
630-
.set('Authorization', `Bearer ${config.USER_TOKEN}`)
631-
.end((err, res) => {
632-
res.should.have.status(403)
633-
res.body.message.should.be.eql('You are not allowed to perform this action!')
634-
done()
635-
})
636-
})
637-
638647
it('Deleting non-existent submission should throw 404', (done) => {
639648
chai.request(app)
640649
.delete(`${config.API_VERSION}/submissions/${nonExSubmissionId}`)
@@ -646,6 +655,17 @@ describe('Submission Service tests', () => {
646655
})
647656
}).timeout(20000)
648657

658+
it('Deleting submission with copilot token should throw 403', (done) => {
659+
chai.request(app)
660+
.delete(`${config.API_VERSION}/submissions/${userSubmissionId}`)
661+
.set('Authorization', `Bearer ${config.COPILOT_TOKEN}`)
662+
.end((err, res) => {
663+
res.should.have.status(403)
664+
res.body.message.should.be.eql('You cannot access other member\'s submission')
665+
done()
666+
})
667+
}).timeout(20000)
668+
649669
it('Deleting submission with Admin token should get succeeded', (done) => {
650670
chai.request(app)
651671
.delete(`${config.API_VERSION}/submissions/${submissionId}`)

test/unit/SubmissionService.test.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,31 +519,59 @@ describe('Submission Service tests', () => {
519519
})
520520
})
521521

522+
/**
523+
* START
524+
*/
525+
it('Deleting non-existent submission should throw 404', (done) => {
526+
chai.request(app)
527+
.delete(`${config.API_VERSION}/submissions/${nonExSubmissionId}`)
528+
.set('Authorization', `Bearer ${config.ADMIN_TOKEN}`)
529+
.end((err, res) => {
530+
res.should.have.status(404)
531+
res.body.message.should.be.eql(`Submission with ID = ${nonExSubmissionId} is not found`)
532+
done()
533+
})
534+
})
535+
536+
// Non admin users should not be able to delete submissions that they don't own
522537
it('Deleting submission with copilot token should throw 403', (done) => {
523538
chai.request(app)
524539
.delete(`${config.API_VERSION}/submissions/${testSubmission.Item.id}`)
525540
.set('Authorization', `Bearer ${config.COPILOT_TOKEN}`)
526541
.end((err, res) => {
527542
res.should.have.status(403)
528-
res.body.message.should.be.eql('You are not allowed to perform this action!')
543+
res.body.message.should.be.eql('You cannot access other member\'s submission')
529544
done()
530545
})
531546
})
532547

533-
it('Deleting non-existent submission should throw 404', (done) => {
548+
it('Deleting submission while submission phase is inactive should throw 403', (done) => {
534549
chai.request(app)
535-
.delete(`${config.API_VERSION}/submissions/${nonExSubmissionId}`)
536-
.set('Authorization', `Bearer ${config.ADMIN_TOKEN}`)
550+
.delete(`${config.API_VERSION}/submissions/${testSubmissionWReview.Item.id}`)
551+
.set('Authorization', `Bearer ${config.USER_TOKEN}`)
537552
.end((err, res) => {
538-
res.should.have.status(404)
539-
res.body.message.should.be.eql(`Submission with ID = ${nonExSubmissionId} is not found`)
553+
res.should.have.status(403)
554+
res.body.message.should.be.eql('You cannot delete the submission because submission phase is not active')
540555
done()
541556
})
542557
})
543558

544-
it('Deleting submission with Admin token should get succeeded', (done) => {
559+
it('Deleting submission with User token should get succeeded', (done) => {
545560
chai.request(app)
546561
.delete(`${config.API_VERSION}/submissions/${testSubmission.Item.id}`)
562+
.set('Authorization', `Bearer ${config.USER_TOKEN}`)
563+
.end((err, res) => {
564+
res.should.have.status(204)
565+
done()
566+
})
567+
}).timeout(10000)
568+
/**
569+
* END
570+
*/
571+
572+
it('Deleting submission with Admin token should get succeeded', (done) => {
573+
chai.request(app)
574+
.delete(`${config.API_VERSION}/submissions/${testSubmissionWReview.Item.id}`)
547575
.set('Authorization', `Bearer ${config.ADMIN_TOKEN}`)
548576
.end((err, res) => {
549577
res.should.have.status(204)

test/unit/prepare.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ prepare(function (done) {
101101
const authUrl = URL.parse(config.AUTH0_URL)
102102
const busUrl = URL.parse(config.BUSAPI_EVENTS_URL)
103103
const challengeApiUrl = URL.parse(`${config.CHALLENGEAPI_URL}/${testData.testSubmissionWoLegacy.Item.challengeId}/phases`)
104+
const challengeApiUrl2 = URL.parse(`${config.CHALLENGEAPI_URL}/${testData.testSubmission.Item.challengeId}/phases`)
104105
const challengeDetailUrl = URL.parse(`${config.CHALLENGEAPI_URL}?filter=id=${testData.testSubmission.Item.challengeId}`)
105106
const challengeWoLegacyUrl = URL.parse(`${config.CHALLENGEAPI_URL}?filter=id=${testData.testSubmissionWoLegacy.Item.challengeId}`)
106107

@@ -130,6 +131,8 @@ prepare(function (done) {
130131
.reply(204)
131132
.get(challengeApiUrl.path)
132133
.reply(200, testData.testChallengeAPIResponse)
134+
.get(challengeApiUrl2.path)
135+
.reply(200, testData.testChallengeAPIResponse)
133136
.get(challengeDetailUrl.path)
134137
.reply(200, testData.testChallengeDetailResponse)
135138
.get(challengeWoLegacyUrl.path)

0 commit comments

Comments
 (0)