@@ -5,6 +5,8 @@ import ApiClient from "../src/api";
55
66import { createAxiosMock , mockAxios } from "./test-utils/mocks" ;
77
8+ const TEST_BRANCH_SLUG = "lorem-ipsum-dolor-branch" ;
9+
810// Type for accessing global properties
911type GlobalWithWindow = Record < string , unknown > ;
1012
@@ -74,6 +76,7 @@ describe("API Client", () => {
7476 host : "https://api.knock.app" ,
7577 apiKey : "pk_test_12345" ,
7678 userToken : undefined ,
79+ branch : TEST_BRANCH_SLUG ,
7780 } ) ;
7881
7982 expect ( apiClient ) . toBeInstanceOf ( ApiClient ) ;
@@ -515,6 +518,22 @@ describe("API Client", () => {
515518 ) ;
516519 } ) ;
517520
521+ test ( "sets correct x-knock-branch header" , ( ) => {
522+ const apiClient = new ApiClient ( {
523+ host : "https://api.knock.app" ,
524+ apiKey : "pk_test_12345" ,
525+ userToken : undefined ,
526+ branch : TEST_BRANCH_SLUG ,
527+ } ) ;
528+
529+ const axiosClient = ( apiClient as unknown as Record < string , unknown > )
530+ . axiosClient as { defaults : { headers : Record < string , string > } } ;
531+
532+ expect ( axiosClient . defaults . headers [ "X-Knock-Branch" ] ) . toBe (
533+ TEST_BRANCH_SLUG ,
534+ ) ;
535+ } ) ;
536+
518537 test ( "supports various HTTP methods" , async ( ) => {
519538 const mockHttp = createAxiosMock ( ) ;
520539 const apiClient = new ApiClient ( {
0 commit comments