probot/test/serializers.test.ts

76 lines
1.9 KiB
TypeScript
Raw Normal View History

import { serializers } from '../src/serializers'
describe('serializers', () => {
2017-12-14 00:13:46 +08:00
describe('repository', () => {
it("returns the repository's full name", () => {
2017-12-14 00:13:46 +08:00
const repo = { full_name: 'probot/JasonEtco' }
expect(serializers.repository(repo)).toBe('probot/JasonEtco')
})
})
describe('installation', () => {
it("returns the installation's account login", () => {
2017-12-14 00:13:46 +08:00
const inst = { account: { login: 'JasonEtco' } }
expect(serializers.installation(inst)).toBe('JasonEtco')
})
it('returns the installation if no account exists', () => {
const inst = { foo: true, bar: false }
expect(serializers.installation(inst)).toEqual(inst)
})
})
describe('event', () => {
it('works with a legit event', () => {
const event = {
id: 1,
name: 'test',
2017-08-23 11:06:31 +08:00
payload: {
action: 'test',
installation: { id: 1 },
repository: { full_name: 'probot/test' }
}
}
expect(serializers.event(event)).toEqual({
event: 'test.test',
id: 1,
installation: 1,
repository: 'probot/test'
})
})
it('works a malformed event', () => {
const event = {
id: 1,
name: 'test',
payload: {}
}
expect(serializers.event(event)).toEqual({
event: 'test',
id: 1,
installation: undefined,
repository: undefined
2017-08-23 11:06:31 +08:00
})
})
it('works with boolean', () => {
2017-08-23 11:06:31 +08:00
expect(serializers.event(false)).toBe(false)
})
it('works empty object', () => {
2017-08-23 11:06:31 +08:00
expect(serializers.event({})).toEqual({})
})
})
2017-12-14 00:13:46 +08:00
describe('res', () => {
it('returns the provided object if no status exists', () => {
const res = { foo: true, bar: false }
expect(serializers.res(res)).toEqual(res)
})
it('returns nothing when passed nothing', () => {
expect(serializers.res(undefined)).toBe(undefined)
2017-12-14 00:13:46 +08:00
})
})
2017-08-23 11:06:31 +08:00
})