diff --git a/test/task.test.js b/test/task.test.js index cd0ad1c3..efa9716d 100644 --- a/test/task.test.js +++ b/test/task.test.js @@ -17,6 +17,23 @@ const AssignMail = require('../modules/mail/assign') const TaskMail = require('../modules/mail/task') const taskUpdate = require('../modules/tasks/taskUpdate') +const nockAuth = () => { + nock('https://github.com') + .post('/login/oauth/access_token/', {code: 'eb518274e906c68580f7'}) + .basicAuth({user: secrets.github.id, pass: secrets.github.secret}) + .reply(200, {access_token: 'e72e16c7e42f292c6912e7710c838347ae178b4a'}) + nock('https://api.github.com') + .persist() + .get('/repos/worknenjoy/gitpay/issues/1080') + .query({client_id: secrets.github.id, client_secret: secrets.github.secret}) + .reply(200, getSingleIssue.issue) + nock('https://api.github.com') + .persist() + .get('/repos/worknenjoy/gitpay') + .query({client_id: secrets.github.id, client_secret: secrets.github.secret}) + .reply(200, getSingleRepo.repo) +} + describe("tasks", () => { // API rate limit exceeded const createTask = (authorizationHeader, params) => { @@ -110,15 +127,31 @@ describe("tasks", () => { }) describe('Task crud', () => { - xit('should create a new task wiht projects ands organizations', (done) => { + it('should create a new task wiht projects ands organizations', (done) => { + nockAuth() + registerAndLogin(agent).then(res => { - createTask(res.headers.authorization).then(task => { - expect(task.url).to.equal('https://github.com/worknenjoy/truppie/issues/99'); + createTask(res.headers.authorization, {url: 'https://github.com/worknenjoy/truppie/issues/1080'}).then(task => { + expect(task.url).to.equal('https://github.com/worknenjoy/truppie/issues/1080'); done(); }).catch(done) }).catch(done) }) + it('should give error on update if the task already exists', (done) => { + nockAuth() + + registerAndLogin(agent).then(res => { + createTask(res.headers.authorization, {url: 'https://github.com/worknenjoy/truppie/issues/1080'}).then(task => { + createTask(res.headers.authorization, {url: 'https://github.com/worknenjoy/truppie/issues/1080'}).then(task => { + expect(task.errors).exist + expect(task.errors[0].message).to.equal('url must be unique') + done(); + }).catch(done) + }).catch(done) + }).catch(done) + }) + xit('should try to create an invalid task', (done) => { registerAndLogin(agent).then(res => { agent