Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Dec 18, 2024
1 parent c114bf9 commit d73a9c7
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion packages/browser/src/plugins/segmentio/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,74 @@ describe('Segment.io', () => {
})
})

describe('configuring a keep alive', () => {
describe('configuring additionalHeaders', () => {
it('should accept additional headers', async () => {
const analytics = new Analytics({ writeKey: 'foo' })

await analytics.register(
await segmentio(analytics, {
apiKey: '',
deliveryStrategy: {
config: {
additionalHeaders: {
'X-My-Header': 'foo',
},
},
},
})
)

await analytics.track('foo')
const [_, params] = spyMock.mock.lastCall
expect(params.headers['X-My-Header']).toBe('foo')
expect(params.headers['Content-Type']).toBe('text/plain')
})

it('should allow additional headers to be a function', async () => {
const analytics = new Analytics({ writeKey: 'foo' })

await analytics.register(
await segmentio(analytics, {
apiKey: '',
deliveryStrategy: {
config: {
additionalHeaders: () => ({
'X-My-Header': 'foo',
}),
},
},
})
)

await analytics.track('foo')
const [_, params] = spyMock.mock.lastCall
expect(params.headers['X-My-Header']).toBe('foo')
expect(params.headers['Content-Type']).toBe('text/plain')
})
})

describe('configuring fetch priority', () => {
it('should accept fetch priority configuration', async () => {
const analytics = new Analytics({ writeKey: 'foo' })

await analytics.register(
await segmentio(analytics, {
apiKey: '',
deliveryStrategy: {
config: {
fetchPriority: 'high',
},
},
})
)

await analytics.track('foo')
const [_, params] = spyMock.mock.lastCall
expect(params.priority).toBe('high')
})
})

describe('configuring keepalive', () => {
it('should accept keepalive configuration', async () => {
const analytics = new Analytics({ writeKey: 'foo' })

Expand Down

0 comments on commit d73a9c7

Please sign in to comment.