|
| 1 | +import { beforeAll, describe, expect, test } from 'vitest' |
| 2 | + |
| 3 | +import { get } from '@/tests/helpers/e2etest' |
| 4 | + |
| 5 | +function makeURL(pathname: string, queryParams?: Record<string, string>) { |
| 6 | + const params = new URLSearchParams(queryParams || {}) |
| 7 | + const queryString = params.toString() |
| 8 | + return `/api/article/body?pathname=${encodeURIComponent(pathname)}${queryString ? `&${queryString}` : ''}` |
| 9 | +} |
| 10 | + |
| 11 | +describe('Webhooks transformer', () => { |
| 12 | + beforeAll(() => { |
| 13 | + if (!process.env.ROOT) { |
| 14 | + console.warn( |
| 15 | + 'WARNING: The Webhooks transformer tests require the ROOT environment variable to be set to the fixture root', |
| 16 | + ) |
| 17 | + } |
| 18 | + }) |
| 19 | + |
| 20 | + test('webhook-events-and-payloads page renders with markdown structure', async () => { |
| 21 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 22 | + expect(res.statusCode).toBe(200) |
| 23 | + expect(res.headers['content-type']).toContain('text/markdown') |
| 24 | + |
| 25 | + // Should have title |
| 26 | + expect(res.body).toContain('# Webhook events and payloads') |
| 27 | + |
| 28 | + // Should have intro |
| 29 | + expect(res.body).toContain('Learn about when each webhook event occurs') |
| 30 | + }) |
| 31 | + |
| 32 | + test('webhooks are formatted as sections with headers', async () => { |
| 33 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 34 | + expect(res.statusCode).toBe(200) |
| 35 | + |
| 36 | + // Check for webhook event headers (## webhook_name) |
| 37 | + expect(res.body).toMatch(/^## \w+/m) |
| 38 | + }) |
| 39 | + |
| 40 | + test('webhooks show available actions', async () => { |
| 41 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 42 | + expect(res.statusCode).toBe(200) |
| 43 | + |
| 44 | + // Should list action types for webhooks with multiple actions |
| 45 | + expect(res.body).toContain('**Action type:**') |
| 46 | + }) |
| 47 | + |
| 48 | + test('webhooks show availability information', async () => { |
| 49 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 50 | + expect(res.statusCode).toBe(200) |
| 51 | + |
| 52 | + // Should show availability as a heading |
| 53 | + expect(res.body).toContain('### Availability') |
| 54 | + }) |
| 55 | + |
| 56 | + test('manual content is included', async () => { |
| 57 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 58 | + expect(res.statusCode).toBe(200) |
| 59 | + |
| 60 | + // Check for some known manual content from the markdown file |
| 61 | + expect(res.body).toContain('About webhook events and payloads') |
| 62 | + }) |
| 63 | + |
| 64 | + test('intro is rendered', async () => { |
| 65 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 66 | + expect(res.statusCode).toBe(200) |
| 67 | + |
| 68 | + const introMatch = res.body.match(/^Learn about when each webhook event/m) |
| 69 | + expect(introMatch).toBeTruthy() |
| 70 | + }) |
| 71 | + |
| 72 | + test('Liquid tags are rendered in content', async () => { |
| 73 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 74 | + expect(res.statusCode).toBe(200) |
| 75 | + |
| 76 | + // Check that data variables are rendered (not left as Liquid syntax) |
| 77 | + expect(res.body).not.toContain('{% data') |
| 78 | + expect(res.body).not.toContain('{{') |
| 79 | + }) |
| 80 | + |
| 81 | + test('AUTOTITLE links are resolved', async () => { |
| 82 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 83 | + expect(res.statusCode).toBe(200) |
| 84 | + |
| 85 | + // AUTOTITLE should be replaced with actual titles |
| 86 | + expect(res.body).not.toContain('[AUTOTITLE]') |
| 87 | + }) |
| 88 | + |
| 89 | + test('webhooks show payload parameters table', async () => { |
| 90 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 91 | + expect(res.statusCode).toBe(200) |
| 92 | + |
| 93 | + // Should show payload object parameters section |
| 94 | + expect(res.body).toContain('### Webhook payload object') |
| 95 | + expect(res.body).toContain('#### Webhook payload object parameters') |
| 96 | + // Should have a markdown table with parameter columns |
| 97 | + expect(res.body).toContain('| Name | Type | Description |') |
| 98 | + }) |
| 99 | + |
| 100 | + test('webhooks show descriptions', async () => { |
| 101 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 102 | + expect(res.statusCode).toBe(200) |
| 103 | + |
| 104 | + // Should include webhook descriptions (converted from HTML to plain text) |
| 105 | + // Using actual descriptions from real webhook data |
| 106 | + expect(res.body).toContain('A check run was completed') |
| 107 | + }) |
| 108 | + |
| 109 | + test('webhooks show body parameters in table', async () => { |
| 110 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 111 | + expect(res.statusCode).toBe(200) |
| 112 | + |
| 113 | + // Should show parameter names and types in tables |
| 114 | + expect(res.body).toContain('`action`') |
| 115 | + expect(res.body).toContain('`string`') |
| 116 | + expect(res.body).toContain('`object`') |
| 117 | + // Should mark required parameters |
| 118 | + expect(res.body).toContain('**Required.**') |
| 119 | + }) |
| 120 | + |
| 121 | + test('webhooks show payload examples when available', async () => { |
| 122 | + const res = await get(makeURL('/en/webhooks/webhook-events-and-payloads')) |
| 123 | + expect(res.statusCode).toBe(200) |
| 124 | + |
| 125 | + // NOTE: The current webhook source data does not include payloadExample fields, |
| 126 | + // so this section won't appear in the output. The transformer code (lines 115-120) |
| 127 | + // is ready to display payload examples if/when they are added to the source data. |
| 128 | + // For now, we just verify the transformer doesn't crash on missing examples. |
| 129 | + expect(res.statusCode).toBe(200) |
| 130 | + }) |
| 131 | + |
| 132 | + test('Non-webhooks pages are not transformed', async () => { |
| 133 | + const res = await get(makeURL('/en/get-started/start-your-journey/hello-world')) |
| 134 | + expect(res.statusCode).toBe(200) |
| 135 | + |
| 136 | + // Regular pages should not be transformed by webhooks transformer |
| 137 | + // They should have their normal HTML-like structure |
| 138 | + expect(res.body).toContain('Hello World') |
| 139 | + }) |
| 140 | +}) |
0 commit comments