fix(gateway): accept Kakao already-registered response
This commit is contained in:
@@ -71,7 +71,9 @@ const buildCaller = (
|
||||
};
|
||||
},
|
||||
signup: async () =>
|
||||
options.kakaoSignupAlreadyRegistered ? { msg: 'already registered' as const } : { id: kakaoProfile.id },
|
||||
options.kakaoSignupAlreadyRegistered
|
||||
? { alreadyRegistered: true }
|
||||
: { id: kakaoProfile.id, alreadyRegistered: false },
|
||||
getMe: async () => ({
|
||||
id: kakaoProfile.id,
|
||||
kakaoAccount: {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { KakaoOAuthClient } from '../src/auth/kakaoClient.js';
|
||||
|
||||
const createClient = (): KakaoOAuthClient =>
|
||||
new KakaoOAuthClient({
|
||||
restKey: 'rest-key',
|
||||
redirectUri: 'https://gateway.example.test/oauth/callback',
|
||||
apiHost: 'https://kapi.example.test',
|
||||
});
|
||||
|
||||
describe('Kakao OAuth HTTP transport', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('normalizes Kakao -102 already registered errors into an account recovery result', async () => {
|
||||
const fetchMock = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(
|
||||
new Response(JSON.stringify({ msg: 'already registered', code: -102 }), {
|
||||
status: 400,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
);
|
||||
|
||||
await expect(createClient().signup('access-token')).resolves.toEqual({
|
||||
alreadyRegistered: true,
|
||||
});
|
||||
expect(fetchMock).toHaveBeenCalledWith(new URL('https://kapi.example.test/v1/user/signup'), {
|
||||
headers: {
|
||||
Authorization: 'Bearer access-token',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('continues to reject unrelated Kakao signup errors', async () => {
|
||||
vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(
|
||||
new Response(JSON.stringify({ msg: 'invalid request', code: -201 }), {
|
||||
status: 400,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
);
|
||||
|
||||
await expect(createClient().signup('access-token')).rejects.toThrow(
|
||||
'Kakao signup error: {"msg":"invalid request","code":-201}'
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user