Files
sb-front/src/api/authApi.spec.js
T

61 lines
2.0 KiB
JavaScript
Raw Normal View History

import { describe, it, expect, vi } from 'vitest'
// http(axios 인스턴스)를 모킹 — 실제 네트워크 없이 호출 형태만 검증
vi.mock('@/api/http', () => ({
default: {
get: vi.fn(() => Promise.resolve({})),
post: vi.fn(() => Promise.resolve({})),
put: vi.fn(() => Promise.resolve({})),
delete: vi.fn(() => Promise.resolve({})),
},
}))
import http from '@/api/http'
import { authApi } from '@/api/authApi'
describe('authApi 엔드포인트 와이어링', () => {
it('signup → POST /auth/signup', () => {
const payload = { loginId: 'u1', password: 'pw', name: '홍길동' }
authApi.signup(payload)
expect(http.post).toHaveBeenCalledWith('/auth/signup', payload)
})
it('signupEnabled → GET /auth/signup-enabled', () => {
authApi.signupEnabled()
expect(http.get).toHaveBeenCalledWith('/auth/signup-enabled')
})
it('login → POST /auth/login', () => {
const payload = { loginId: 'u1', password: 'pw', rememberMe: true }
authApi.login(payload)
expect(http.post).toHaveBeenCalledWith('/auth/login', payload)
})
it('logout → POST /auth/logout', () => {
authApi.logout()
expect(http.post).toHaveBeenCalledWith('/auth/logout')
})
it('me → GET /auth/me', () => {
authApi.me()
expect(http.get).toHaveBeenCalledWith('/auth/me')
})
it('changePassword → PUT /auth/password', () => {
const payload = { currentPassword: 'a', newPassword: 'bbbbbbbb' }
authApi.changePassword(payload)
expect(http.put).toHaveBeenCalledWith('/auth/password', payload)
})
it('verifyPassword → POST /auth/verify-password (password 래핑)', () => {
authApi.verifyPassword('secret')
expect(http.post).toHaveBeenCalledWith('/auth/verify-password', { password: 'secret' })
})
it('updateProfile → PUT /auth/profile', () => {
const payload = { name: '새이름', email: 'a@b.com' }
authApi.updateProfile(payload)
expect(http.put).toHaveBeenCalledWith('/auth/profile', payload)
})
})