* First run of script * Get the app running --- ish * Get NextJS working * Remove `node:` * Get more tests passing in unit directory * Update FailBot test to use nock * Update test.yml * Update Dockerfile * tests/content fixes * Update page.js * Update build-changelog.js * updating tests/routing * Update orphan-tests.js * updating tests/rendering * Update .eslintrc.js * Update .eslintrc.js * Install jest/globals * "linting" tests * staging update to server.mjs * Change '.github/allowed-actions.js' to a ESM export * Lint * Fixes for the main package.json * Move Jest to be last in the npm test command so we can pass args * Just use 'npm run lint' in the npm test command * update algolia label script * update openapi script * update require on openapi * Update enterprise-algolia-label.js * forgot JSON.parse * Update lunr-search-index.js * Always explicitly include process.cwd() for JSON file reads pathed from project root * update graphql/update-files.js script * Update other npm scripts using jest to pass ESM NODE_OPTIONS * Update check-for-enterprise-issues-by-label.js for ESM * Update create-enterprise-issue.js for ESM * Import jest global for browser tests * Convert 'script/deploy' to ESM Co-authored-by: Grace Park <gracepark@github.com> Co-authored-by: James M. Greene <jamesmgreene@github.com>
83 lines
3.5 KiB
JavaScript
83 lines
3.5 KiB
JavaScript
import { difference } from 'lodash-es'
|
|
import { getJSON } from '../helpers/supertest.js'
|
|
import { latest } from '../../lib/enterprise-server-releases.js'
|
|
import xAllVersions from '../../lib/all-versions.js'
|
|
import webhookPayloads from '../../lib/webhooks'
|
|
import { jest } from '@jest/globals'
|
|
|
|
const allVersions = Object.values(xAllVersions)
|
|
const payloadVersions = allVersions.map(v => v.miscVersionName)
|
|
|
|
// grab some values for testing
|
|
const nonEnterpriseDefaultPayloadVersion = allVersions
|
|
.find(version => version.nonEnterpriseDefault)
|
|
.miscVersionName
|
|
|
|
const latestGhesPayloadVersion = allVersions
|
|
.find(version => version.currentRelease === latest)
|
|
.miscVersionName
|
|
|
|
const ghaePayloadVersion = allVersions
|
|
.find(version => version.plan === 'github-ae')
|
|
.miscVersionName
|
|
|
|
describe('webhook payloads', () => {
|
|
jest.setTimeout(3 * 60 * 1000)
|
|
|
|
test('have expected top-level keys', () => {
|
|
payloadVersions.forEach(version => {
|
|
expect(version in webhookPayloads).toBe(true)
|
|
})
|
|
})
|
|
|
|
test('have a reasonable number of payloads per version', () => {
|
|
payloadVersions.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[nonEnterpriseDefaultPayloadVersion])[0]
|
|
const firstValue = webhookPayloads[nonEnterpriseDefaultPayloadVersion][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 non-dotcom versions, dotcom-only payloads fall back to dotcom', async () => {
|
|
const ghesPayloads = webhookPayloads[latestGhesPayloadVersion]
|
|
const ghaePayloads = webhookPayloads[ghaePayloadVersion]
|
|
const dotcomOnlyPayloads = difference(Object.keys(webhookPayloads[nonEnterpriseDefaultPayloadVersion]), Object.keys(ghesPayloads))
|
|
// use the first one found for testing purposes
|
|
const dotcomOnlyPayload = dotcomOnlyPayloads[0]
|
|
expect(ghesPayloads[dotcomOnlyPayload]).toBeUndefined()
|
|
expect(ghaePayloads[dotcomOnlyPayload]).toBeUndefined()
|
|
|
|
// fallback handling is in middleware/contextualizers/webhooks.js
|
|
const ghesPayloadsWithFallbacks = await getJSON(`/en/enterprise-server@${latest}/developers/webhooks-and-events?json=webhookPayloadsForCurrentVersion`)
|
|
const ghaePayloadsWithFallbacks = await getJSON('/en/github-ae@latest/developers/webhooks-and-events?json=webhookPayloadsForCurrentVersion')
|
|
expect(ghesPayloadsWithFallbacks[dotcomOnlyPayload]).toBeDefined()
|
|
expect(ghaePayloadsWithFallbacks[dotcomOnlyPayload]).toBeDefined()
|
|
|
|
const ghesPayloadString = getPayloadString(ghesPayloadsWithFallbacks[dotcomOnlyPayload])
|
|
const ghaePayloadString = getPayloadString(ghaePayloadsWithFallbacks[dotcomOnlyPayload])
|
|
expect(ghesPayloadString.includes('```json')).toBe(true)
|
|
expect(ghaePayloadString.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]]
|
|
}
|