@@ -3,15 +3,61 @@ 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 {
7+ buildDeliveryApiUrl ,
8+ startDeliveryApiPolling ,
9+ stopDeliveryApiPolling ,
10+ clearDeliveryApiState ,
11+ } from './deliveryApi'
712import type { DeliveryApiConfiguration } from './deliveryApi'
813
14+ describe ( 'buildDeliveryApiUrl' , ( ) => {
15+ it ( 'should default to datadoghq.com' , ( ) => {
16+ expect ( buildDeliveryApiUrl ( ) ) . toBe ( 'https://api.datadoghq.com/api/unstable/debugger/frontend/probes' )
17+ } )
18+
19+ it ( 'should build URL for US1 site' , ( ) => {
20+ expect ( buildDeliveryApiUrl ( 'datadoghq.com' ) ) . toBe ( 'https://api.datadoghq.com/api/unstable/debugger/frontend/probes' )
21+ } )
22+
23+ it ( 'should build URL for EU1 site' , ( ) => {
24+ expect ( buildDeliveryApiUrl ( 'datadoghq.eu' ) ) . toBe ( 'https://api.datadoghq.eu/api/unstable/debugger/frontend/probes' )
25+ } )
26+
27+ it ( 'should build URL for US3 site' , ( ) => {
28+ expect ( buildDeliveryApiUrl ( 'us3.datadoghq.com' ) ) . toBe (
29+ 'https://api.us3.datadoghq.com/api/unstable/debugger/frontend/probes'
30+ )
31+ } )
32+
33+ it ( 'should build URL for staging site' , ( ) => {
34+ expect ( buildDeliveryApiUrl ( 'datad0g.com' ) ) . toBe ( 'https://api.datad0g.com/api/unstable/debugger/frontend/probes' )
35+ } )
36+
37+ it ( 'should build URL for gov site' , ( ) => {
38+ expect ( buildDeliveryApiUrl ( 'ddog-gov.com' ) ) . toBe ( 'https://api.ddog-gov.com/api/unstable/debugger/frontend/probes' )
39+ } )
40+
41+ it ( 'should use proxy as origin when provided' , ( ) => {
42+ expect ( buildDeliveryApiUrl ( 'datadoghq.com' , 'http://localhost:9000' ) ) . toBe (
43+ 'http://localhost:9000/api/unstable/debugger/frontend/probes'
44+ )
45+ } )
46+
47+ it ( 'should ignore site when proxy is provided' , ( ) => {
48+ expect ( buildDeliveryApiUrl ( 'datadoghq.eu' , 'http://proxy.example.com' ) ) . toBe (
49+ 'http://proxy.example.com/api/unstable/debugger/frontend/probes'
50+ )
51+ } )
52+ } )
53+
954describe ( 'deliveryApi' , ( ) => {
1055 let fetchSpy : jasmine . Spy
1156 let clock : Clock
1257
1358 function makeConfig ( overrides : Partial < DeliveryApiConfiguration > = { } ) : DeliveryApiConfiguration {
1459 return {
60+ clientToken : 'test-client-token' ,
1561 applicationId : 'test-app-id' ,
1662 env : 'staging' ,
1763 version : '1.0.0' ,
@@ -57,11 +103,19 @@ describe('deliveryApi', () => {
57103
58104 expect ( fetchSpy ) . toHaveBeenCalledTimes ( 1 )
59105 const [ url , options ] = fetchSpy . calls . mostRecent ( ) . args
60- expect ( url ) . toBe ( '/ api/ui/ debugger/probe-delivery ' )
106+ expect ( url ) . toBe ( 'https:// api.datadoghq.com/api/unstable/ debugger/frontend/probes ' )
61107 expect ( options . method ) . toBe ( 'POST' )
62- expect ( options . credentials ) . toBe ( 'same-origin' )
108+ expect ( options . credentials ) . toBeUndefined ( )
63109 expect ( options . headers [ 'Content-Type' ] ) . toBe ( 'application/json; charset=utf-8' )
64110 expect ( options . headers [ 'Accept' ] ) . toBe ( 'application/vnd.datadog.debugger-probes+json; version=1' )
111+ expect ( options . headers [ 'dd-client-token' ] ) . toBe ( 'test-client-token' )
112+ } )
113+
114+ it ( 'should use the configured site for the request URL' , ( ) => {
115+ startDeliveryApiPolling ( makeConfig ( { site : 'datadoghq.eu' } ) )
116+
117+ const [ url ] = fetchSpy . calls . mostRecent ( ) . args
118+ expect ( url ) . toBe ( 'https://api.datadoghq.eu/api/unstable/debugger/frontend/probes' )
65119 } )
66120
67121 it ( 'should send the correct request body' , ( ) => {
0 commit comments