v2: SdkError tests + codemod (#2137)
This commit is contained in:
parent
f563440cfd
commit
542d5c9586
3 changed files with 101 additions and 23 deletions
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue