1
0
mirror of synced 2025-12-21 19:06:49 -05:00
Files
docs/tests/content/webhooks.js
Sarah Schneider aa5a62d49d Remove versions feature flag code (#15793)
* remove FEATURE_NEW_VERSIONS from feature-flags.json

* remove process.env.FEATURE_NEW_VERSIONS from include files

* remove process.env.FEATURE_NEW_VERSIONS from lib files

* remove process.env.FEATURE_NEW_VERSIONS from middleware files

* remove process.env.FEATURE_NEW_VERSIONS from script files

* remove process.env.FEATURE_NEW_VERSIONS from test files

* update test fixtures to use new versions as canonical fixtures
2020-09-29 13:36:07 -04:00

62 lines
2.5 KiB
JavaScript

const { difference } = require('lodash')
const { getJSON } = require('../helpers')
const { latest } = require('../../lib/enterprise-server-releases')
const { oldVersions } = require('../../lib/old-versions-utils')
const webhookPayloads = require('../../lib/webhooks')
describe('webhook payloads', () => {
jest.setTimeout(3 * 60 * 1000)
// TODO update this test when we update the webhook payload filepaths
test('have old versions as top-level keys', () => {
oldVersions.forEach(version => {
expect(version in webhookPayloads).toBe(true)
})
})
// TODO update this test when we update the webhook payload filepaths
test('have a reasonable number of payloads per version', () => {
oldVersions.forEach(version => {
const payloadsPerVersion = Object.keys(webhookPayloads[version])
expect(payloadsPerVersion.length).toBeGreaterThan(20)
})
})
test('have payloads that are JSON strings, not objects', () => {
// use the first one found for testing purposes
const firstKey = Object.keys(webhookPayloads.dotcom)[0]
const firstValue = webhookPayloads.dotcom[firstKey]
const payloadString = getPayloadString(firstValue)
const payloadLines = payloadString.split('\n')
expect(payloadLines.length).toBeGreaterThan(5)
expect(payloadLines[2].trim()).toBe('```json')
expect(payloadLines[3].trim()).toBe('{')
expect(payloadLines[payloadLines.length - 3].trim()).toBe('```')
})
test('on GHE, dotcom-only payloads fall back to dotcom', async () => {
const ghePayloads = webhookPayloads[latest]
const dotcomOnlyPayloads = difference(Object.keys(webhookPayloads.dotcom), Object.keys(ghePayloads))
// use the first one found for testing purposes
const dotcomOnlyPayload = dotcomOnlyPayloads[0]
expect(ghePayloads[dotcomOnlyPayload]).toBeUndefined()
// fallback handling is in middleware/contexturalizers/webhooks.js
const ghePayloadsWithFallbacks = await getJSON(`/en/enterprise/${latest}/user/developers?json=webhookPayloadsForCurrentVersion`)
expect(ghePayloadsWithFallbacks[dotcomOnlyPayload]).toBeDefined()
const payloadString = getPayloadString(ghePayloadsWithFallbacks[dotcomOnlyPayload])
expect(payloadString.includes('```json')).toBe(true)
})
})
// accommodate two possible payload string locations
// value of top-level key: `create` (in create.payload.json)
// value of second-level key: `issues.opened` (in issues.opened.payload.json)
function getPayloadString (payload) {
return typeof payload === 'string'
? payload
: payload[Object.keys(payload)[0]]
}