add tests for postComment

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2018-12-20 16:10:01 +01:00
parent 23299203e5
commit 08de6dcf2b
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
4 changed files with 38 additions and 2 deletions

View File

@ -1,4 +1,9 @@
{
"env": {
"test": {
"plugins": [ "istanbul" ]
}
},
"presets": [
["@babel/env", { "targets": {"node": "current"} }]
],

View File

@ -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",

View File

@ -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',
})
})
})
})

4
test/setup.js Normal file
View File

@ -0,0 +1,4 @@
import chai from 'chai'
import sinonChai from 'sinon-chai'
chai.use(sinonChai)