forked from mirrors/probot
test: Convert manifest creation test to TS (#884)
This commit is contained in:
parent
620e40b172
commit
b2f3858c7c
|
@ -73,7 +73,7 @@ export class ManifestCreation {
|
||||||
return response.data.html_url
|
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)
|
return updateDotenv(env)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
const { ManifestCreation } = require('../src/manifest-creation')
|
import nock from 'nock'
|
||||||
const nock = require('nock')
|
import pkg from '../package.json'
|
||||||
const package = require('../package.json')
|
import { ManifestCreation } from '../src/manifest-creation'
|
||||||
const response = require('./fixtures/setup/response.json')
|
import response from './fixtures/setup/response.json'
|
||||||
|
|
||||||
describe('ManifestCreation', () => {
|
describe('ManifestCreation', () => {
|
||||||
let setup
|
let setup: ManifestCreation
|
||||||
let SmeeClient
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
setup = new ManifestCreation()
|
setup = new ManifestCreation()
|
||||||
|
@ -19,7 +18,7 @@ describe('ManifestCreation', () => {
|
||||||
|
|
||||||
setup.updateEnv = jest.fn()
|
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')
|
SmeeClient.createChannel = jest.fn().mockReturnValue('https://smee.io/1234abc')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -29,13 +28,13 @@ describe('ManifestCreation', () => {
|
||||||
|
|
||||||
test('writes new webhook channel to .env', async () => {
|
test('writes new webhook channel to .env', async () => {
|
||||||
await setup.createWebhookChannel()
|
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', () => {
|
describe('pkg', () => {
|
||||||
test('gets pkg from package.json', () => {
|
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')
|
const createdApp = await setup.createAppFromCode('123abc')
|
||||||
expect(createdApp).toEqual('https://github.com/apps/testerino0000000')
|
expect(createdApp).toEqual('https://github.com/apps/testerino0000000')
|
||||||
// expect dotenv to be called with id, webhook_secret, pem
|
// 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', () => {
|
describe('getManifest', () => {
|
||||||
test('creates an app from a code', () => {
|
test('creates an app from a code', () => {
|
||||||
// checks that getManifest returns a JSON.stringified manifest
|
// 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"}')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
Loading…
Reference in New Issue