v2: SdkError tests + codemod (#2137)

This commit is contained in:
Konstantin Konstantinov 2026-06-10 20:15:15 +03:00 • committed by GitHub
commit 542d5c9586
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 101 additions and 23 deletions

View file

@ -1590,6 +1590,7 @@ describe('SSEClientTransport', () => {
expect(error).toBeInstanceOf(SdkHttpError);
expect((error as SdkHttpError).code).toBe(SdkErrorCode.ClientHttpAuthentication);
expect((error as SdkHttpError).status).toBe(401);
expect((error as SdkHttpError).statusText).toBe('Unauthorized');
expect(authProvider.onUnauthorized).toHaveBeenCalledTimes(1);
expect(postCount).toBe(2);
});

View file

@ -1875,6 +1875,7 @@ describe('StreamableHTTPClientTransport', () => {
expect(error).toBeInstanceOf(SdkHttpError);
expect((error as SdkHttpError).code).toBe(SdkErrorCode.ClientHttpAuthentication);
expect((error as SdkHttpError).status).toBe(401);
expect((error as SdkHttpError).statusText).toBe('Unauthorized');
expect(mockAuthProvider.saveTokens).toHaveBeenCalledWith({
access_token: 'new-access-token',
token_type: 'Bearer',

View file

@ -95,13 +95,26 @@ describe('StreamableHTTPClientTransport with AuthProvider', () => {
vi.spyOn(globalThis, 'fetch');
(globalThis.fetch as Mock)
.mockResolvedValueOnce({ ok: false, status: 401, headers: new Headers(), text: async () => 'unauthorized' })
.mockResolvedValueOnce({ ok: false, status: 401, headers: new Headers(), text: async () => 'unauthorized' });
.mockResolvedValueOnce({
ok: false,
status: 401,
statusText: 'Unauthorized',
headers: new Headers(),
text: async () => 'unauthorized'
})
.mockResolvedValueOnce({
ok: false,
status: 401,
statusText: 'Unauthorized',
headers: new Headers(),
text: async () => 'unauthorized'
});
const error = await transport.send(message).catch(e => e);
expect(error).toBeInstanceOf(SdkHttpError);
expect((error as SdkHttpError).code).toBe(SdkErrorCode.ClientHttpAuthentication);
expect((error as SdkHttpError).status).toBe(401);
expect((error as SdkHttpError).statusText).toBe('Unauthorized');
expect(authProvider.onUnauthorized).toHaveBeenCalledTimes(1);
});