@@ -3,15 +3,56 @@ import { registerCleanupTask, mockClock, replaceMockable } from '@datadog/browse
33import type { Clock } from '@datadog/browser-core/test'
44import { getProbes , clearProbes } from './probes'
55import type { Probe } from './probes'
6- import { startDeliveryApiPolling , stopDeliveryApiPolling , clearDeliveryApiState } from './deliveryApi'
6+ import { buildDeliveryApiUrl , startDeliveryApiPolling , stopDeliveryApiPolling , clearDeliveryApiState } from './deliveryApi'
77import type { DeliveryApiConfiguration } from './deliveryApi'
88
9+ describe ( 'buildDeliveryApiUrl' , ( ) => {
10+ it ( 'should default to datadoghq.com' , ( ) => {
11+ expect ( buildDeliveryApiUrl ( ) ) . toBe ( 'https://api.datadoghq.com/api/unstable/debugger/frontend/probes' )
12+ } )
13+
14+ it ( 'should build URL for US1 site' , ( ) => {
15+ expect ( buildDeliveryApiUrl ( 'datadoghq.com' ) ) . toBe ( 'https://api.datadoghq.com/api/unstable/debugger/frontend/probes' )
16+ } )
17+
18+ it ( 'should build URL for EU1 site' , ( ) => {
19+ expect ( buildDeliveryApiUrl ( 'datadoghq.eu' ) ) . toBe ( 'https://api.datadoghq.eu/api/unstable/debugger/frontend/probes' )
20+ } )
21+
22+ it ( 'should build URL for US3 site' , ( ) => {
23+ expect ( buildDeliveryApiUrl ( 'us3.datadoghq.com' ) ) . toBe (
24+ 'https://api.us3.datadoghq.com/api/unstable/debugger/frontend/probes'
25+ )
26+ } )
27+
28+ it ( 'should build URL for staging site' , ( ) => {
29+ expect ( buildDeliveryApiUrl ( 'datad0g.com' ) ) . toBe ( 'https://api.datad0g.com/api/unstable/debugger/frontend/probes' )
30+ } )
31+
32+ it ( 'should build URL for gov site' , ( ) => {
33+ expect ( buildDeliveryApiUrl ( 'ddog-gov.com' ) ) . toBe ( 'https://api.ddog-gov.com/api/unstable/debugger/frontend/probes' )
34+ } )
35+
36+ it ( 'should use proxy as origin when provided' , ( ) => {
37+ expect ( buildDeliveryApiUrl ( 'datadoghq.com' , 'http://localhost:9000' ) ) . toBe (
38+ 'http://localhost:9000/api/unstable/debugger/frontend/probes'
39+ )
40+ } )
41+
42+ it ( 'should ignore site when proxy is provided' , ( ) => {
43+ expect ( buildDeliveryApiUrl ( 'datadoghq.eu' , 'http://proxy.example.com' ) ) . toBe (
44+ 'http://proxy.example.com/api/unstable/debugger/frontend/probes'
45+ )
46+ } )
47+ } )
48+
949describe ( 'deliveryApi' , ( ) => {
1050 let fetchSpy : jasmine . Spy
1151 let clock : Clock
1252
1353 function makeConfig ( overrides : Partial < DeliveryApiConfiguration > = { } ) : DeliveryApiConfiguration {
1454 return {
55+ clientToken : 'test-client-token' ,
1556 applicationId : 'test-app-id' ,
1657 env : 'staging' ,
1758 version : '1.0.0' ,
@@ -57,11 +98,19 @@ describe('deliveryApi', () => {
5798
5899 expect ( fetchSpy ) . toHaveBeenCalledTimes ( 1 )
59100 const [ url , options ] = fetchSpy . calls . mostRecent ( ) . args
60- expect ( url ) . toBe ( '/ api/ui/ debugger/probe-delivery ' )
101+ expect ( url ) . toBe ( 'https:// api.datadoghq.com/api/unstable/ debugger/frontend/probes ' )
61102 expect ( options . method ) . toBe ( 'POST' )
62- expect ( options . credentials ) . toBe ( 'same-origin' )
103+ expect ( options . credentials ) . toBeUndefined ( )
63104 expect ( options . headers [ 'Content-Type' ] ) . toBe ( 'application/json; charset=utf-8' )
64105 expect ( options . headers [ 'Accept' ] ) . toBe ( 'application/vnd.datadog.debugger-probes+json; version=1' )
106+ expect ( options . headers [ 'dd-client-token' ] ) . toBe ( 'test-client-token' )
107+ } )
108+
109+ it ( 'should use the configured site for the request URL' , ( ) => {
110+ startDeliveryApiPolling ( makeConfig ( { site : 'datadoghq.eu' } ) )
111+
112+ const [ url ] = fetchSpy . calls . mostRecent ( ) . args
113+ expect ( url ) . toBe ( 'https://api.datadoghq.eu/api/unstable/debugger/frontend/probes' )
65114 } )
66115
67116 it ( 'should send the correct request body' , ( ) => {
0 commit comments