it(`create challenge - user doesn't have permission to create challenge under specific project`, async () => { const challengeData = _.cloneDeep(testChallengeData) challengeData.projectId = 200 const response = await chai.request(app) .post(basePath) .set('Authorization', `Bearer ${config.COPILOT_TOKEN}`) .send(challengeData) should.equal(response.status, 403) should.equal(response.body.message, 'You do not have permissions to perform this action') })
it(`fully update challenge - project not found`, async () => { const challengeData = _.clone(testChallengeData) challengeData.projectId = 100000 try { await service.fullyUpdateChallenge({ userId: '16096823' }, id, challengeData, config.COPILOT_TOKEN) } catch (e) { should.equal(e.message, `Project with id: 100000 doesn't exist`) return } throw new Error('should not reach here') })
it(`partially update challenge - user doesn't have permission to update challenge under specific project`, async () => { try { await service.partiallyUpdateChallenge({ userId: '16096823' }, id, { projectId: 200 }, config.COPILOT_TOKEN) } catch (e) { should.equal(e.response.data.result.content.message, 'You do not have permissions to perform this action') return } throw new Error('should not reach here') })
it('search challenge type timeline templates successfully 1', async () => { const response = await chai.request(app) .get(basePath) .set('Authorization', `Bearer ${config.COPILOT_TOKEN}`) should.equal(response.status, 200) const result = response.body should.equal(result.length, 1) should.equal(result[0].id, id) should.equal(result[0].typeId, type.id) should.equal(result[0].timelineTemplateId, timelineTemplate.id) })
it('search challenge type timeline templates successfully 4', async () => { const response = await chai.request(app) .get(basePath) .set('Authorization', `Bearer ${config.COPILOT_TOKEN}`) .query({ typeId: notFoundId }) should.equal(response.status, 200) const result = response.body should.equal(result.length, 0) })
const response = await chai.request(app) .get(`${baseUrl}/${data.challenge.id}/attachments/${id}`) .set('Authorization', `Bearer ${config.COPILOT_TOKEN}`) should.equal(response.status, 403) should.equal(response.body.message, 'You are not allowed to download attachment of the challenge.')
const response = await chai.request(app) .get(`${basePath}/${id}`) .set('Authorization', `Bearer ${config.COPILOT_TOKEN}`) should.equal(response.status, 200) const result = response.body
it(`create challenge - user doesn't have permission to create challenge under specific project`, async () => { const challengeData = _.clone(testChallengeData) challengeData.projectId = 200 try { await service.createChallenge({ userId: '16096823' }, challengeData, config.COPILOT_TOKEN) } catch (e) { should.equal(e.response.data.result.content.message, 'You do not have permissions to perform this action') return } throw new Error('should not reach here') })
it('search challenge type timeline templates successfully 2', async () => { const response = await chai.request(app) .get(basePath) .set('Authorization', `Bearer ${config.COPILOT_TOKEN}`) .query({ typeId: type.id }) should.equal(response.status, 200) const result = response.body should.equal(result.length, 1) should.equal(result[0].id, id) should.equal(result[0].typeId, type.id) should.equal(result[0].timelineTemplateId, timelineTemplate.id) })
const response = await chai.request(app) .get(`${basePath}/${id2}`) .set('Authorization', `Bearer ${config.COPILOT_TOKEN}`) should.equal(response.status, 200) const result = response.body
it(`partially update challenge - project not found`, async () => { try { await service.partiallyUpdateChallenge({ userId: '16096823' }, id, { projectId: 100000 }, config.COPILOT_TOKEN) } catch (e) { should.equal(e.message, `Project with id: 100000 doesn't exist`) return } throw new Error('should not reach here') })
const response = await chai.request(app) .get(`${basePath}/${id2}`) .set('Authorization', `Bearer ${config.COPILOT_TOKEN}`) should.equal(response.status, 200) const result = response.body
it(`fully update challenge - user doesn't have permission to update challenge under specific project`, async () => { const challengeData = _.clone(testChallengeData) challengeData.projectId = 200 try { await service.fullyUpdateChallenge({ userId: '16096823' }, id, challengeData, config.COPILOT_TOKEN) } catch (e) { should.equal(e.response.data.result.content.message, 'You do not have permissions to perform this action') return } throw new Error('should not reach here') })
it(`create challenge - project not found`, async () => { const challengeData = _.cloneDeep(testChallengeData) challengeData.projectId = 100000 const response = await chai.request(app) .post(basePath) .set('Authorization', `Bearer ${config.COPILOT_TOKEN}`) .send(challengeData) should.equal(response.status, 400) should.equal(response.body.message, `Project with id: ${challengeData.projectId} doesn't exist`) })
it('search challenge type timeline templates successfully 3', async () => { const response = await chai.request(app) .get(basePath) .set('Authorization', `Bearer ${config.COPILOT_TOKEN}`) .query({ timelineTemplateId: timelineTemplate.id }) should.equal(response.status, 200) const result = response.body should.equal(result.length, 1) should.equal(result[0].id, id) should.equal(result[0].typeId, type.id) should.equal(result[0].timelineTemplateId, timelineTemplate.id) })