Merge branch 'webhook-types' into github-app-webhooks

* webhook-types:
  Test for context.isBot
  Add test for deprecated receive behavior
  Add strong typing for exported webhooks property
  Fix deprecation warnings
  Make most webhook payload properties optional for now
  Move webhook type declarations
This commit is contained in:
Brandon Keepers
2018-07-15 13:52:41 -05:00
9 changed files with 62 additions and 20 deletions

View File

@@ -76,13 +76,14 @@ describe('Application', () => {
})
it('calls callback x amount of times when an array of x actions is passed', async () => {
const event2 = {
const event2: WebhookEvent = {
id: '123',
name: 'arrayTest',
payload: {
action: 'bar',
installation: { id: 2 }
}
} as any
}
const spy = jest.fn()
app.on(['test.foo', 'arrayTest.bar'], spy)
@@ -269,5 +270,19 @@ describe('Application', () => {
expect(await app.auth(1, 'a logger' as any)).toEqual('a github client')
expect(github.auth).toHaveBeenCalledWith(1, 'a logger')
})
test('recieve() accepts param with {event}', async () => {
const spy = jest.fn()
app.events.on('deprecated', spy)
await app.receive({ event: 'deprecated', payload: { action: 'test' } } as any)
expect(spy).toHaveBeenCalled()
})
test('recieve() accepts param with {name,event}', async () => {
const spy = jest.fn()
app.events.on('real-event-name', spy)
await app.receive({ name: 'real-event-name', event: 'deprecated', payload: { action: 'test' } } as any)
expect(spy).toHaveBeenCalled()
})
})
})

View File

@@ -1,15 +1,17 @@
import fs = require('fs')
import path = require('path')
import { WebhookEvent } from '@octokit/webhooks'
import { Context } from '../src/context'
import { GitHubAPI, OctokitError } from '../src/github'
describe('Context', () => {
let event: any
let event: WebhookEvent
let context: Context
beforeEach(() => {
event = {
id: '123',
name: 'push',
payload: {
issue: { number: 4 },
@@ -27,8 +29,9 @@ describe('Context', () => {
expect(context.payload).toBe(event.payload)
})
it('aliases name to event', () => {
expect(context.event).toEqual(event.name)
it('aliases the event name', () => {
expect(context.name).toEqual('push')
expect(context.event).toEqual('push')
})
describe('repo', () => {
@@ -218,4 +221,20 @@ describe('Context', () => {
})
})
})
describe('isBot', () => {
test('returns true if sender is a bot', () => {
event.payload.sender = { type: 'Bot' }
context = new Context(event, {} as any, {} as any)
expect(context.isBot).toBe(true)
})
test('returns false if sender is not a bot', () => {
event.payload.sender = { type: 'User' }
context = new Context(event, {} as any, {} as any)
expect(context.isBot).toBe(false)
})
})
})

View File

@@ -23,7 +23,7 @@ describe('serializers', () => {
describe('event', () => {
it('works with a legit event', () => {
const event = {id: 1,
event: 'test',
name: 'test',
payload: {
action: 'test',
repository: {full_name: 'probot/test'},
@@ -40,7 +40,7 @@ describe('serializers', () => {
it('works a malformed event', () => {
const event = {id: 1,
event: 'test',
name: 'test',
payload: {}}
expect(serializers.event(event)).toEqual({
id: 1,