Skip to content

Commit

Permalink
covering status change sync with Githug on taskFetch module
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanmtz committed Apr 18, 2024
1 parent 89da128 commit 411c6c5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
18 changes: 13 additions & 5 deletions modules/tasks/taskFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ module.exports = Promise.method(function taskFetch (taskParams) {
const repoInfoJSON = JSON.parse(repoInfo)
const repoUrl = repoInfoJSON.html_url
const ownerUrl = repoInfoJSON.owner.html_url
const responseGithub = {
let responseGithub = {
id: data.dataValues.id,
url: issueUrl,
private: data.dataValues.private,
Expand Down Expand Up @@ -164,16 +164,25 @@ module.exports = Promise.method(function taskFetch (taskParams) {
}
if (data.status !== 'in_progress' && data.status !== issueDataJsonGithub.state) {
// eslint-disable no-unused-vars
data
const dataStatusUpdateInProgress = await data
.update({ status: issueDataJsonGithub.state }, {
where: {
id: data.id
},
returning: true,
})
.then(task => {
return responseGithub
responseGithub.status = dataStatusUpdateInProgress.status
}
if (issueDataJsonGithub.state === 'closed' && data.status !== 'closed') {
// eslint-disable no-unused-vars
const dataStatusUpdatedClosed = await data
.update({ status: issueDataJsonGithub.state }, {
where: {
id: data.id
},
returning: true,
})
responseGithub.status = dataStatusUpdatedClosed.status
}
if (data.Labels.length !== issueDataJsonGithub.labels.length) {
// eslint-disable no-unused-vars
Expand All @@ -196,7 +205,6 @@ module.exports = Promise.method(function taskFetch (taskParams) {
console.log('error', e)
}
}

return responseGithub
})
.catch(e => {
Expand Down
41 changes: 40 additions & 1 deletion test/task.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const spies = require('chai-spies')
const AssignMail = require('../modules/mail/assign')
const TaskMail = require('../modules/mail/task')
const taskUpdate = require('../modules/tasks/taskUpdate')
const { get } = require('request')

const nockAuth = () => {
nock('https://github.com')
Expand Down Expand Up @@ -363,7 +364,7 @@ describe("tasks", () => {
}).catch(done)
});

it('should fetch task and not sync status in_progress', (done) => {
it('should fetch task and not sync status in_progress on Gitpay and open on Github', (done) => {
const github_url = 'https://github.com/worknenjoy/gitpay/issues/1080';

nock('https://github.com')
Expand Down Expand Up @@ -398,6 +399,44 @@ describe("tasks", () => {
}).catch(done)
});

it('should fetch task and sync status in_progress on Gitpay and closed on Github', (done) => {
const github_url = 'https://github.com/worknenjoy/gitpay/issues/1080';

const closedIssue = getSingleIssue.issue
closedIssue.state = 'closed'

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, closedIssue)
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)

models.Task.build({url: github_url, provider: 'github', title: 'foo'}).save().then((task) => {
models.Task.update({status: 'in_progress'}, {where: {id: task.dataValues.id}}).then(() => {
agent
.get(`/tasks/fetch/${task.dataValues.id}`)
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
expect(res.statusCode).to.equal(200);
expect(res.body).to.exist;
expect(res.body.metadata.id).to.equal('1080');
expect(res.body.status).to.equal('closed');
done(err);
})
}).catch(done)
}).catch(done)
});

it('should update task value', (done) => {
const github_url = 'https://github.com/worknenjoy/truppie/issues/98';

Expand Down

0 comments on commit 411c6c5

Please sign in to comment.