Skip to content

Commit bf8fae5

Browse files
committed
one more test case
1 parent 2dbc94a commit bf8fae5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/unit/apiClient.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,27 @@ describe("ApiClient", () => {
135135
});
136136
});
137137

138+
it("should fall back to unauthenticated endpoint when token is undefined", async () => {
139+
const mockFetch = jest.spyOn(global, "fetch");
140+
mockFetch.mockResolvedValueOnce(new Response(null, { status: 200 }));
141+
142+
// @ts-expect-error accessing private property for testing
143+
apiClient.getAccessToken = jest.fn().mockRejectedValue(undefined);
144+
145+
await apiClient.sendEvents(mockEvents);
146+
147+
const url = new URL("api/private/unauth/telemetry/events", "https://api.test.com");
148+
expect(mockFetch).toHaveBeenCalledWith(url, {
149+
method: "POST",
150+
headers: {
151+
"Content-Type": "application/json",
152+
Accept: "application/json",
153+
"User-Agent": "test-user-agent",
154+
},
155+
body: JSON.stringify(mockEvents),
156+
});
157+
});
158+
138159
it("should fall back to unauthenticated endpoint on 401 error", async () => {
139160
const mockFetch = jest.spyOn(global, "fetch");
140161
mockFetch

0 commit comments

Comments
 (0)