Files
Unciv/uncivbot/test/index.test.js

59 lines
1.5 KiB
JavaScript
Raw Normal View History

const nock = require('nock')
// Requiring our app implementation
const myProbotApp = require('..')
const { Probot } = require('probot')
// Requiring our fixtures
const payload = require('./fixtures/issues.opened')
const issueCreatedBody = { body: 'Thanks for opening this issue!' }
const fs = require('fs')
const path = require('path')
describe('My Probot app', () => {
let probot
let mockCert
beforeAll((done) => {
fs.readFile(path.join(__dirname, 'fixtures/mock-cert.pem'), (err, cert) => {
if (err) return done(err)
mockCert = cert
done()
})
})
beforeEach(() => {
nock.disableNetConnect()
probot = new Probot({ id: 123, cert: mockCert })
// Load our app into probot
probot.load(myProbotApp)
})
test('creates a comment when an issue is opened', async () => {
// Test that we correctly return a test token
nock('https://api.github.com')
.post('/app/installations/2/access_tokens')
.reply(200, { token: 'test' })
// Test that a comment is posted
nock('https://api.github.com')
.post('/repos/hiimbex/testing-things/issues/1/comments', (body) => {
expect(body).toMatchObject(issueCreatedBody)
return true
})
.reply(200)
// Receive a webhook event
await probot.receive({ name: 'issues', payload })
})
afterEach(() => {
nock.cleanAll()
nock.enableNetConnect()
})
})
// For more information about testing with Jest see:
// https://facebook.github.io/jest/
// For more information about testing with Nock see:
// https://github.com/nock/nock