|
| 1 | +import { describe, expect, it } from 'bun:test'; |
| 2 | +import { getContentTestURL } from './utils'; |
| 3 | + |
| 4 | +const EMBED_SCRIPT_URL = getContentTestURL( |
| 5 | + 'https://gitbook.gitbook.io/test-gitbook-open/~gitbook/embed/script.js' |
| 6 | +); |
| 7 | + |
| 8 | +describe('embed script', () => { |
| 9 | + it('serves the embeddable script with permissive headers', async () => { |
| 10 | + const response = await fetch(EMBED_SCRIPT_URL, { |
| 11 | + headers: { |
| 12 | + Origin: 'https://example.com', |
| 13 | + }, |
| 14 | + }); |
| 15 | + |
| 16 | + expect(response.status).toBe(200); |
| 17 | + expect(response.headers.get('content-type')).toContain('application/javascript'); |
| 18 | + expect(response.headers.get('access-control-allow-origin')).toBe('*'); |
| 19 | + expect(response.headers.get('cross-origin-resource-policy')).toBe('cross-origin'); |
| 20 | + |
| 21 | + const body = await response.text(); |
| 22 | + expect(body).toContain('w.GitBook'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('responds to OPTIONS requests with CORS headers for cross-domain insertion', async () => { |
| 26 | + const response = await fetch(EMBED_SCRIPT_URL, { |
| 27 | + method: 'OPTIONS', |
| 28 | + headers: { |
| 29 | + Origin: 'https://example.com', |
| 30 | + 'Access-Control-Request-Method': 'GET', |
| 31 | + }, |
| 32 | + }); |
| 33 | + |
| 34 | + expect(response.status).toBe(204); |
| 35 | + expect(response.headers.get('access-control-allow-origin')).toBe('*'); |
| 36 | + expect(response.headers.get('access-control-allow-methods')).toContain('GET'); |
| 37 | + }); |
| 38 | +}); |
0 commit comments