it('upload attachment - invalid token', async () => { const response = await chai.request(app) .post(`${baseUrl}/${data.challenge.id}/attachments`) .set('Authorization', `Bearer ${config.INVALID_TOKEN}`) .attach('attachment', attachmentContent, 'attachment.txt') should.equal(response.status, 401) should.equal(response.body.message, 'Failed to authenticate token.') })
uploadFiles(){ let req = request .post('http://localhost:3000/upload'); this.state.files.forEach((file)=>{ req.attach('file', file) }); req.end(function(err, res){ // Calling the end function will send the request }); }
request .post(this.config.baseUrl + this.config.apiPath + "/content/" + id + "/child/attachment/" + attachmentId + "/data") .auth(this.config.username, this.config.password) .set("X-Atlassian-Token", "nocheck") .attach("file", filepath ) .end(function(err, res){ processCallback(callback, err, res); });
it('upload attachment - missing token', async () => { const response = await chai.request(app) .post(`${baseUrl}/${data.challenge.id}/attachments`) .attach('attachment', attachmentContent, 'attachment.txt') should.equal(response.status, 401) should.equal(response.body.message, 'No token provided.') })
for(var i in filesArray){ req.attach(filesArray[i][0].name,filesArray[i][0])
r.field(type, media); } else { r.attach(type, media);
it('upload attachment successfully', async () => { const response = await chai.request(app) .post(`${baseUrl}/${data.challenge.id}/attachments`) .set('Authorization', `Bearer ${config.ADMIN_TOKEN}`) .attach('attachment', attachmentContent, 'attachment.txt') should.equal(response.status, 200) const result = response.body should.exist(result.id) id = result.id should.equal(result.fileSize, attachmentContent.length) should.equal(result.fileName, 'attachment.txt') should.equal(result.challengeId, data.challenge.id) })
.post(publishUrl) .type('form') .attach('file', fs.readFileSync(filePath), fileName) .field('name', name) .field('channelName', `@${name}`) .post(publishUrl) .type('form') .attach('file', fs.readFileSync(filePath), fileName) .field('name', name) .field('channelName', channelName) .post(publishUrl) .type('form') .attach('file', fs.readFileSync(filePath), fileName) .field('name', name) .field('channelName', channelName) .post(publishUrl) .type('form') .attach('file', fs.readFileSync(filePath), fileName) .field('name', `${name}-anonymous`) .end(function (err, res) { .post(publishUrl) .type('form') .attach('file', fs.readFileSync(filePath), fileName) .field('name', `${name}-channel`) .field('channelName', channelName)
it('upload attachment - invalid bearer format', async () => { const response = await chai.request(app) .post(`${baseUrl}/${data.challenge.id}/attachments`) .set('Authorization', 'invalid format') .attach('attachment', attachmentContent, 'attachment.txt') should.equal(response.status, 401) should.equal(response.body.message, 'No token provided.') })
it('upload attachment - challenge not found', async () => { const response = await chai.request(app) .post(`${baseUrl}/${notFoundId}/attachments`) .set('Authorization', `Bearer ${config.ADMIN_TOKEN}`) .attach('attachment', attachmentContent, 'attachment.txt') should.equal(response.status, 404) should.equal(response.body.message, `Challenge with id: ${notFoundId} doesn't exist`) })
it('upload attachment - expired token', async () => { const response = await chai.request(app) .post(`${baseUrl}/${data.challenge.id}/attachments`) .set('Authorization', `Bearer ${config.EXPIRED_TOKEN}`) .attach('attachment', attachmentContent, 'attachment.txt') should.equal(response.status, 401) should.equal(response.body.message, 'Failed to authenticate token.') })
it('upload attachment - forbidden', async () => { const response = await chai.request(app) .post(`${baseUrl}/${data.challenge.id}/attachments`) .set('Authorization', `Bearer ${config.USER_TOKEN}`) .attach('attachment', attachmentContent, 'attachment.txt') should.equal(response.status, 403) should.equal(response.body.message, 'You are not allowed to perform this action!') })
it('upload attachment - invalid attachment', async () => { const response = await chai.request(app) .post(`${baseUrl}/${data.challenge.id}/attachments`) .set('Authorization', `Bearer ${config.ADMIN_TOKEN}`) .attach('invalid', attachmentContent, 'attachment.txt') should.equal(response.status, 400) should.equal(response.body.message, '"attachment" is required') })
//https://docs.atlassian.com/atlassian-confluence/REST/latest/#content/{id}/child/attachment-getAttachments request .post(this.config.baseUrl + this.config.apiPath + "/content/" + id + "/child/attachment") .auth(this.config.username, this.config.password) .set("X-Atlassian-Token", "nocheck") .attach("file", filepath ) .end(function(err, res){ processCallback(callback, err, res); });