Skip to content
This repository has been archived by the owner on Jan 3, 2020. It is now read-only.

Commit

Permalink
Test some things
Browse files Browse the repository at this point in the history
  • Loading branch information
swinton committed Jul 17, 2018
1 parent bfb1a14 commit 908ceaa
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const {createRobot} = require('probot')
const app = require('..')
const payload = require('./fixtures/check_suite.requested')

// Mock out the analysis implementation for these tests
// https://jestjs.io/docs/en/mock-functions#mock-implementations
jest.mock('../lib/analysis.js')
const analyzeTree = require('../lib/analysis')

describe('index', () => {
let robot
let github
Expand All @@ -18,13 +23,25 @@ describe('index', () => {

// Mock out the GitHub API
github = {}
github.request = jest
.fn()
.mockResolvedValueOnce({data: {id: 42, url: "https://api.github.com/repos/foo/bar/check-runs/42"}})
.mockResolvedValueOnce({data: {id: 42, url: "https://api.github.com/repos/foo/bar/check-runs/42"}})

analyzeTree.mockResolvedValueOnce([])

// Pass mocked out GitHub API into out robot instance
robot.auth = () => Promise.resolve(github)
})

it('works', async () => {
await robot.receive(event)

expect(analyzeTree).toHaveBeenCalledTimes(1)
expect(analyzeTree.mock.calls[0][0]).toBeDefined()
expect(analyzeTree.mock.calls[0][1]).toBe('wintron')
expect(analyzeTree.mock.calls[0][2]).toBe('example')
expect(analyzeTree.mock.calls[0][3]).toBe('9875bf915c118e6369a610770288cf7f0a415124')
})
})

Expand Down

0 comments on commit 908ceaa

Please sign in to comment.