|
| 1 | +import { createEnvelope, addHeaderToEnvelope, addItemToEnvelope, serializeEnvelope } from '../src/envelope'; |
| 2 | +import { EventEnvelope } from '@sentry/types'; |
| 3 | + |
| 4 | +describe('envelope', () => { |
| 5 | + describe('createEnvelope()', () => { |
| 6 | + const testTable: Array<[string, Parameters<typeof createEnvelope>[0], Parameters<typeof createEnvelope>[1]]> = [ |
| 7 | + ['creates an empty envelope', {}, []], |
| 8 | + ['creates an envelope with a header but no items', { dsn: 'https://[email protected]/1', sdk: {} }, []], |
| 9 | + ]; |
| 10 | + it.each(testTable)('%s', (_: string, headers, items) => { |
| 11 | + const env = createEnvelope(headers, items); |
| 12 | + expect(env).toHaveLength(2); |
| 13 | + expect(env[0]).toStrictEqual(headers); |
| 14 | + expect(env[1]).toStrictEqual(items); |
| 15 | + }); |
| 16 | + }); |
| 17 | + |
| 18 | + describe('addHeaderToEnvelope()', () => { |
| 19 | + it('adds a header to the envelope', () => { |
| 20 | + const env = createEnvelope({}, []); |
| 21 | + expect(serializeEnvelope(env)).toMatchInlineSnapshot(`"{}"`); |
| 22 | + const newEnv = addHeaderToEnvelope(env, { dsn: 'https://[email protected]/' }); |
| 23 | + expect(serializeEnvelope(newEnv)).toMatchInlineSnapshot(`"{\\"dsn\\":\\"https://[email protected]/\\"}"`); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe('addItemToEnvelope()', () => { |
| 28 | + const env = createEnvelope<EventEnvelope>({ event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', sent_at: '123' }, []); |
| 29 | + expect(serializeEnvelope(env)).toMatchInlineSnapshot( |
| 30 | + `"{\\"event_id\\":\\"aa3ff046696b4bc6b609ce6d28fde9e2\\",\\"sent_at\\":\\"123\\"}"`, |
| 31 | + ); |
| 32 | + const newEnv = addItemToEnvelope<EventEnvelope>(env, [ |
| 33 | + { type: 'event' }, |
| 34 | + { event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2' }, |
| 35 | + ]); |
| 36 | + expect(serializeEnvelope(newEnv)).toMatchInlineSnapshot(` |
| 37 | + "{\\"event_id\\":\\"aa3ff046696b4bc6b609ce6d28fde9e2\\",\\"sent_at\\":\\"123\\"} |
| 38 | + {\\"type\\":\\"event\\"} |
| 39 | + {\\"event_id\\":\\"aa3ff046696b4bc6b609ce6d28fde9e2\\"}" |
| 40 | + `); |
| 41 | + }); |
| 42 | +}); |
0 commit comments