test: Convert manifest creation test to TS (#884)

This commit is contained in:
wolfy1339 2019-03-12 18:24:03 -04:00 committed by Gregor Martynus
parent 620e40b172
commit b2f3858c7c
2 changed files with 11 additions and 12 deletions

View File

@ -73,7 +73,7 @@ export class ManifestCreation {
return response.data.html_url
}
private async updateEnv (env: any) {
public async updateEnv (env: any) { // Needs to be public due to tests
return updateDotenv(env)
}

View File

@ -1,11 +1,10 @@
const { ManifestCreation } = require('../src/manifest-creation')
const nock = require('nock')
const package = require('../package.json')
const response = require('./fixtures/setup/response.json')
import nock from 'nock'
import pkg from '../package.json'
import { ManifestCreation } from '../src/manifest-creation'
import response from './fixtures/setup/response.json'
describe('ManifestCreation', () => {
let setup
let SmeeClient
let setup: ManifestCreation
beforeEach(() => {
setup = new ManifestCreation()
@ -19,7 +18,7 @@ describe('ManifestCreation', () => {
setup.updateEnv = jest.fn()
const SmeeClient = require('smee-client')
const SmeeClient: typeof import('smee-client') = require('smee-client')
SmeeClient.createChannel = jest.fn().mockReturnValue('https://smee.io/1234abc')
})
@ -29,13 +28,13 @@ describe('ManifestCreation', () => {
test('writes new webhook channel to .env', async () => {
await setup.createWebhookChannel()
expect(setup.updateEnv).toHaveBeenCalledWith({"WEBHOOK_PROXY_URL": "https://smee.io/1234abc"})
expect(setup.updateEnv).toHaveBeenCalledWith({ 'WEBHOOK_PROXY_URL': 'https://smee.io/1234abc' })
})
})
describe('pkg', () => {
test('gets pkg from package.json', () => {
expect(setup.pkg).toEqual(package)
expect(setup.pkg).toEqual(pkg)
})
})
@ -73,14 +72,14 @@ describe('ManifestCreation', () => {
const createdApp = await setup.createAppFromCode('123abc')
expect(createdApp).toEqual('https://github.com/apps/testerino0000000')
// expect dotenv to be called with id, webhook_secret, pem
expect(setup.updateEnv).toHaveBeenCalledWith({"APP_ID": "6666", "PRIVATE_KEY": '"-----BEGIN RSA PRIVATE KEY-----\nsecrets\n-----END RSA PRIVATE KEY-----\n"', "WEBHOOK_SECRET": "12345abcde"})
expect(setup.updateEnv).toHaveBeenCalledWith({ 'APP_ID': '6666', 'PRIVATE_KEY': '"-----BEGIN RSA PRIVATE KEY-----\nsecrets\n-----END RSA PRIVATE KEY-----\n"', 'WEBHOOK_SECRET': '12345abcde' })
})
})
describe('getManifest', () => {
test('creates an app from a code', () => {
// checks that getManifest returns a JSON.stringified manifest
expect(setup.getManifest(package, 'localhost://3000')).toEqual('{"description":"🤖 A framework for building GitHub Apps to automate and improve your workflow","hook_attributes":{"url":"localhost://3000/"},"name":"probot","public":true,"redirect_url":"localhost://3000/probot/setup","url":"https://probot.github.io","version":"v1"}')
expect(setup.getManifest(pkg, 'localhost://3000')).toEqual('{"description":"🤖 A framework for building GitHub Apps to automate and improve your workflow","hook_attributes":{"url":"localhost://3000/"},"name":"probot","public":true,"redirect_url":"localhost://3000/probot/setup","url":"https://probot.github.io","version":"v1"}')
})
})
})