Skip to content

Commit

Permalink
Use parametrized test
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Dec 14, 2021
1 parent 62c9430 commit 7fe07f6
Showing 1 changed file with 15 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,54 +139,24 @@ describe('transportConfiguration', () => {
})

describe('isIntakeUrl', () => {
it('should not detect non intake request', () => {
const configuration = computeTransportConfiguration({ clientToken }, buildEnv)
expect(configuration.isIntakeUrl('https://www.foo.com')).toBe(false)
;[
{ site: 'datadoghq.eu', intakeDomain: 'browser-intake-datadoghq.eu' },
{ site: 'datadoghq.com', intakeDomain: 'browser-intake-datadoghq.com' },
{ site: 'us3.datadoghq.com', intakeDomain: 'browser-intake-us3-datadoghq.com' },
{ site: 'us5.datadoghq.com', intakeDomain: 'browser-intake-us5-datadoghq.com' },
{ site: 'ddog-gov.com', intakeDomain: 'browser-intake-ddog-gov.com' },
].forEach(({ site, intakeDomain }) => {
it(`should detect intake request ${site} site`, () => {
const configuration = computeTransportConfiguration({ clientToken, site }, buildEnv)
expect(configuration.isIntakeUrl(`https://rum.${intakeDomain}/api/v2/rum?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://logs.${intakeDomain}/api/v2/logs?xxx`)).toBe(true)
expect(configuration.isIntakeUrl(`https://session-replay.${intakeDomain}/api/v2/replay?xxx`)).toBe(true)
})
})

it('should detect intake request EU site', () => {
const configuration = computeTransportConfiguration({ clientToken, site: 'datadoghq.eu' }, buildEnv)
expect(configuration.isIntakeUrl('https://rum.browser-intake-datadoghq.eu/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-datadoghq.eu/api/v2/logs?xxx')).toBe(true)
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.eu/api/v2/replay?xxx`)).toBe(
true
)
})

it('should detect intake request US site', () => {
it('should not detect non intake request', () => {
const configuration = computeTransportConfiguration({ clientToken }, buildEnv)
expect(configuration.isIntakeUrl('https://rum.browser-intake-datadoghq.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-datadoghq.com/api/v2/logs?xxx')).toBe(true)
expect(configuration.isIntakeUrl(`https://session-replay.browser-intake-datadoghq.com/api/v2/replay?xxx`)).toBe(
true
)
})

it('should detect intake request US3 site', () => {
const configuration = computeTransportConfiguration({ clientToken, site: 'us3.datadoghq.com' }, buildEnv)
expect(configuration.isIntakeUrl('https://rum.browser-intake-us3-datadoghq.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-us3-datadoghq.com/api/v2/logs?xxx')).toBe(true)
expect(
configuration.isIntakeUrl(`https://session-replay.browser-intake-us3-datadoghq.com/api/v2/replay?xxx`)
).toBe(true)
})

it('should detect intake request US5 site', () => {
const configuration = computeTransportConfiguration({ clientToken, site: 'us5.datadoghq.com' }, buildEnv)
expect(configuration.isIntakeUrl('https://rum.browser-intake-us5-datadoghq.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-us5-datadoghq.com/api/v2/logs?xxx')).toBe(true)
expect(
configuration.isIntakeUrl(`https://session-replay.browser-intake-us5-datadoghq.com/api/v2/replay?xxx`)
).toBe(true)
})

it('should detect intake request gov-cloud site', () => {
const configuration = computeTransportConfiguration({ clientToken, site: 'ddog-gov.com' }, buildEnv)
expect(configuration.isIntakeUrl('https://rum.browser-intake-ddog-gov.com/api/v2/rum?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://logs.browser-intake-ddog-gov.com/api/v2/logs?xxx')).toBe(true)
expect(configuration.isIntakeUrl('https://session-replay.browser-intake-ddog-gov.com/api/v2/replay?xxx')).toBe(
true
)
expect(configuration.isIntakeUrl('https://www.foo.com')).toBe(false)
})

it('should handle sites with subdomains', () => {
Expand Down

0 comments on commit 7fe07f6

Please sign in to comment.