Skip to content

Commit

Permalink
adding test to investigate #8, better logging for failures and details
Browse files Browse the repository at this point in the history
  • Loading branch information
jbjonesjr committed Aug 21, 2017
1 parent f87c9ba commit 80eda4d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
24 changes: 16 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,23 @@ module.exports = robot => {
const freeze = new Freeze(context.github, config);

context.github.search.issues({q:'label:' + freeze.config.labelName, repo:context.repo().full_name}).then(resp => {
resp.data.items.forEach(issue => {
context.github.issues.getComments(githubHelper.parseCommentURL(issue.comments_url)).then(resp => {
return freeze.getLastFreeze(resp.data);
}).then(lastFreezeComment => {
if (freeze.unfreezable(lastFreezeComment)) {
freeze.unfreeze(issue, formatParser.propFromComment(lastFreezeComment));
}
if (resp.data.total_count > 0) {
resp.data.items.forEach(issue => {
context.github.issues.getComments(githubHelper.parseCommentURL(issue.comments_url)).then(resp => {
return freeze.getLastFreeze(resp.data);
}).then(lastFreezeComment => {
if (Object.prototype.hasOwnProperty.call(lastFreezeComment, 'body')) {
if (freeze.unfreezable(lastFreezeComment)) {
freeze.unfreeze(issue, formatParser.propFromComment(lastFreezeComment));
}
} else {
robot.log(new Date() + ': ' + issue.comments_url + ' didn\'t find the snooze comment');
}
});
});
});
} else {
console.log(new Date() + ': No issues found to thaw at this time');
}
});
console.log('scheduled thaw run complete');
}
Expand Down
40 changes: 33 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ perform: true
},
search: {
issues: expect.createSpy().andReturn(Promise.resolve({
data:{items: [{comments_url:'https://api.github.com/repos/baxterthehacker/public-repo/issues/2/comments',
labels:[{
url: 'https://api.github.com/repos/baxterthehacker/public-repo/labels/probot:freeze',
name: 'probot:freeze',
color: 'fc2929'
}]}]
data:{
total_count: 1,
incomplete_results: false,
items: [{comments_url:'https://api.github.com/repos/baxterthehacker/public-repo/issues/2/comments',
labels:[{
url: 'https://api.github.com/repos/baxterthehacker/public-repo/labels/probot:freeze',
name: 'probot:freeze',
color: 'fc2929'
}]}]
}})) // Q:'label:' + this.labelName
}
};
Expand Down Expand Up @@ -165,7 +168,7 @@ perform: true
});
});

it('test visitor activation', async () => {
it('test scheduled thaw success', async () => {
await robot.receive({
event: 'schedule',
payload: {
Expand Down Expand Up @@ -200,6 +203,29 @@ perform: true
});
});

it('test scheduled thaw failure', async () => {
github.search.issues = expect.createSpy().andReturn(Promise.resolve({
data:{
total_count: 0,
incomplete_results: false,
items: []
}
})); // Q:'label:' + this.labelName

await robot.receive({
event: 'schedule',
payload: {
action: 'repository',
repository: {
owner: {
login:'baxterthehacker'
},
name:'public-repo'
},
installation: {
id: 13055
}}});
});
it('test valid comments', async () => {
const defaultFreezeDuration = 7;
const validMessages = [
Expand Down

0 comments on commit 80eda4d

Please sign in to comment.