From 203d5f2072ab17aa0519a2da73e9b55066e06dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Wed, 19 Dec 2018 00:43:16 +0100 Subject: [PATCH] add test for formatting of comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- test/comments.js | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/test/comments.js b/test/comments.js index 0e1bf2e..1b46b31 100644 --- a/test/comments.js +++ b/test/comments.js @@ -7,22 +7,59 @@ import Comments from '../src/comments' let comments, client, builds +const BUILDS = [ + { + id: 'ID-1', + commit: 'COMMIT-1', + success: true, + platform: 'PLATFORM-1', + duration: 'DURATION-1', + url: 'URL-1', + pkg_url: 'PKG_URL-1', + }, + { + id: 'ID-2', + commit: 'COMMIT-2', + success: false, + platform: 'PLATFORM-2', + duration: 'DURATION-2', + url: 'URL-2', + pkg_url: 'PKG_URL-2', + }, +] + +/* expected comment based on given builds */ +const COMMENT = ` +### Jenkins Builds +| :grey_question: | Commit | :hash: | Finished | Duration | Platform | Result | +|-|-|-|-|-|-|-| +| :heavy_check_mark: | COMMIT-1 | [ID-1](URL-1) | Invalid Date | DURATION-1 | \`PLATFORM-1\` | [:package: package](PKG_URL-1) | +| | | | | | | | +| :x: | COMMIT-2 | [ID-2](URL-2) | Invalid Date | DURATION-2 | \`PLATFORM-2\` | [:page_facing_up: build log](PKG_URL-2consoleText) | +` + describe('Comments', () => { - before(() => { + beforeEach(() => { //client = sinon.createStubInstance(Octokit, {what: 2}) builds = sinon.createStubInstance(Builds, { - getBuilds: [] + getBuilds: BUILDS, }) comments = new Comments(client, 'owner', 'repo', builds) }) describe('renderComment', () => { it('should fail with no builds', async () => { + builds.getBuilds.returns([]) try { await comments.renderComment('PR') } catch(err) { expect(err.message).to.eq('No builds exist for this PR') } }) + + it('should render correctly', async () => { + let body = await comments.renderComment('PR') + expect(body).to.eq(COMMENT) + }) }) })