From 08de6dcf2b0aaa9ffabd2604c89dce9a6a9e219a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 20 Dec 2018 16:10:01 +0100 Subject: [PATCH] add tests for postComment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- .babelrc | 5 +++++ package.json | 10 ++++++++++ test/comments.js | 21 +++++++++++++++++++-- test/setup.js | 4 ++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 test/setup.js diff --git a/.babelrc b/.babelrc index b050e07..3c8daf6 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,9 @@ { + "env": { + "test": { + "plugins": [ "istanbul" ] + } + }, "presets": [ ["@babel/env", { "targets": {"node": "current"} }] ], diff --git a/package.json b/package.json index 8529c48..30e3e54 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@babel/plugin-transform-async-to-generator": "^7.1.0", "@babel/preset-env": "^7.1.0", "babel-core": "^7.0.0-bridge.0", + "babel-plugin-istanbul": "^5.1.0", "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "gulp": "^3.9.1", @@ -32,19 +33,28 @@ "gulp-print": "^5.0.0", "mocha": "^5.2.0", "nodemon": "^1.18.4", + "nyc": "^13.1.0", "sinon": "^7.1.1", + "sinon-chai": "^3.3.0", "supertest": "^3.3.0" }, "scripts": { "start": "node server.js", "test": "mocha --require @babel/register", "testw": "mocha --require @babel/register --watch", + "cover": "nyc mocha", "devel": "gulp devel", "clean": "gulp clean", "build": "gulp build", "image": "docker build -t statusteam/ghcmgr .", "push": "docker push statusteam/ghcmgr" }, + "mocha": [ + "@babel/register" + ], + "require": [ + "@babel/register" + ], "keywords": [ "github", "comments", diff --git a/test/comments.js b/test/comments.js index 4217c27..1078768 100644 --- a/test/comments.js +++ b/test/comments.js @@ -1,6 +1,5 @@ import { expect } from 'chai' import sinon from 'sinon' -import Octokit from '@octokit/rest' import Builds from '../src/builds' import Comments from '../src/comments' @@ -42,7 +41,12 @@ const COMMENT = ` describe('Comments', () => { beforeEach(() => { - //client = sinon.createStubInstance(Octokit, {what: 2}) + client = { + issues: { + createComment: sinon.stub().returns({ data: { id: 'ISSUE-ID' }}), + updateComment: sinon.stub().returns({ data: { id: 'ISSUE-ID' }}), + }, + } builds = sinon.createStubInstance(Builds, { getBuilds: BUILDS, }) @@ -64,4 +68,17 @@ describe('Comments', () => { expect(body).to.eq(COMMENT) }) }) + + describe('postComment', () => { + it('should create a new comment', async () => { + let id = await comments.postComment('PR') + expect(id).to.eq('ISSUE-ID') + expect(client.issues.createComment).calledOnceWith({ + body: sinon.match.any, + number: 'PR', + owner: 'owner', + repo: 'repo', + }) + }) + }) }) diff --git a/test/setup.js b/test/setup.js new file mode 100644 index 0000000..94e100e --- /dev/null +++ b/test/setup.js @@ -0,0 +1,4 @@ +import chai from 'chai' +import sinonChai from 'sinon-chai' + +chai.use(sinonChai)