From 908ceaad7cace8acc4a3ae95cbe504c0fba3d3d7 Mon Sep 17 00:00:00 2001 From: Steve Winton Date: Tue, 17 Jul 2018 17:18:21 -0500 Subject: [PATCH] Test some things --- test/index.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/index.test.js b/test/index.test.js index 18ba19c..21cd818 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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 @@ -18,6 +23,12 @@ 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) @@ -25,6 +36,12 @@ describe('index', () => { 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') }) })