From 80eda4d8bbc9b33ef692349dbe2fce8db85a245e Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Mon, 21 Aug 2017 12:32:16 -0400 Subject: [PATCH] adding test to investigate #8, better logging for failures and details --- index.js | 24 ++++++++++++++++-------- test/index.js | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 84f3fd7..9b29c8c 100644 --- a/index.js +++ b/index.js @@ -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'); } diff --git a/test/index.js b/test/index.js index f843305..938ba3f 100644 --- a/test/index.js +++ b/test/index.js @@ -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 } }; @@ -165,7 +168,7 @@ perform: true }); }); - it('test visitor activation', async () => { + it('test scheduled thaw success', async () => { await robot.receive({ event: 'schedule', payload: { @@ -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 = [