-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: DB 스키마 변경 및 회원 email 필드 변경 (prgrms-fe-devcourse#236)
* chore: DB 스키마 변경 * style: authService, userRepository에 DB 변동사항 반영 * feat: authController, authValidator에 DB 변동사항 반영 * chore: Model 디렉토리에 있는 모든 파일을 스키마로 사용하도록 수정 * chore: 테스트 파일도 빌드하도록 수정 (IDE에서 import 안되는 문제 해결) * chore: 빌드 안된 test.ts 파일만 테스트 수행하도록 수정 * test: authService 테스트 코드 필드 이름 수정 * refactor: authorizationFilter에 throwsOnError 파라미터 추가 (prgrms-fe-devcourse#237) * feat: authorizationFilter에 throwsOnError 필드 추가 * test: authorizationFilter 테스트 코드 수정 * style: 로그인 validation 응답하지 않도록 수정 및 비밀번호 변경에 500 응답
1 parent
15402a1
commit 837783a
Showing
13 changed files
with
167 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,38 +4,38 @@ import { encryptText } from '@/utils/crypto'; | |
jest.mock('@/domains/users/users.repository'); | ||
|
||
describe('회원가입', () => { | ||
const mockUser = { id: 1, username: '아이디', password: '12341234', name: '이름' }; | ||
const mockUser = { userId: 1, email: '[email protected]', password: '12341234', name: '이름' }; | ||
|
||
it('회원가입 성공', async () => { | ||
UserRepository.findUserByUsername = jest.fn().mockResolvedValueOnce(mockUser); | ||
UserRepository.findUserByEmail = jest.fn().mockResolvedValueOnce(mockUser); | ||
|
||
const user = await authService.signUp(mockUser.username, mockUser.password, mockUser.name); | ||
const user = await authService.signUp(mockUser.email, mockUser.password, mockUser.name); | ||
|
||
expect(user.userId).toBe(mockUser.id); | ||
expect(user.userId).toBe(mockUser.userId); | ||
}); | ||
|
||
it('이미 존재하는 회원일 경우 예외가 발생한다', async () => { | ||
UserRepository.findOneBy = jest.fn().mockResolvedValueOnce(mockUser); | ||
|
||
expect(authService.signUp(mockUser.username, mockUser.password, mockUser.name)).rejects.toThrow(); | ||
expect(authService.signUp(mockUser.email, mockUser.password, mockUser.name)).rejects.toThrow(); | ||
}); | ||
|
||
it('생성된 유저 정보를 찾을 수 없을 경우 예외가 발생한다', async () => { | ||
UserRepository.findUserByUsername = jest.fn().mockResolvedValueOnce(null); | ||
UserRepository.findUserByEmail = jest.fn().mockResolvedValueOnce(null); | ||
|
||
expect(authService.signUp(mockUser.username, mockUser.password, mockUser.name)).rejects.toThrow(); | ||
expect(authService.signUp(mockUser.email, mockUser.password, mockUser.name)).rejects.toThrow(); | ||
}); | ||
}); | ||
|
||
describe('로그인', () => { | ||
const mockUser = { id: 1, password: encryptText('12341234', '시크릿'), salt: '시크릿' }; | ||
const mockUser = { userId: 1, password: encryptText('12341234', '시크릿'), salt: '시크릿' }; | ||
|
||
it('로그인 성공', async () => { | ||
UserRepository.findOneBy = jest.fn().mockResolvedValueOnce(mockUser); | ||
|
||
const user = await authService.signIn('아이디', '12341234'); | ||
|
||
expect(user.userId).toBe(mockUser.id); | ||
expect(user.userId).toBe(mockUser.userId); | ||
}); | ||
|
||
it('존재하지 않는 회원일 경우 예외가 발생한다', async () => { | ||
|
@@ -52,20 +52,20 @@ describe('로그인', () => { | |
}); | ||
|
||
describe('로그인 확인', () => { | ||
const mockUser = { id: 1 }; | ||
const mockUser = { userId: 1 }; | ||
|
||
it('로그인 확인 성공', async () => { | ||
UserRepository.findOneBy = jest.fn().mockResolvedValueOnce(mockUser); | ||
|
||
const user = await authService.signCheck(mockUser.id); | ||
const user = await authService.signCheck(mockUser.userId); | ||
|
||
expect(user.userId).toBe(mockUser.id); | ||
expect(user.userId).toBe(mockUser.userId); | ||
}); | ||
|
||
it('DB에 유저 정보가 없을 경우 예외가 발생한다', async () => { | ||
UserRepository.findOneBy = jest.fn().mockResolvedValueOnce(null); | ||
|
||
expect(authService.signCheck(mockUser.id)).rejects.toThrow(); | ||
expect(authService.signCheck(mockUser.userId)).rejects.toThrow(); | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters