-
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]: add improved error handling (#118)
* [fix]: fix error handling logic and add swagger examples * [fix]: add Date object transform logic * [refactor]: add testing fixture * [fix]: fix to return dtos * [fix]: fix to not check user email duplicate in guard * [fix]: add unauthorized error when getting kakao/goolge userinfo * [refactor]: add controller tests and refactor user modify dto * [refactor]: add domain tests
- Loading branch information
Showing
56 changed files
with
1,907 additions
and
429 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,53 @@ | ||
import { IsNotEmpty, IsString } from 'class-validator'; | ||
import { Expose } from 'class-transformer'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { UserDto } from '@app/user/dto/user.dto'; | ||
import { ApiExpose } from '@app/common/decorators/api-expose.decorator'; | ||
import { Type } from 'class-transformer'; | ||
|
||
export class GoogleLoginDto { | ||
@ApiProperty({ name: 'access_token' }) | ||
@Expose({ name: 'access_token' }) | ||
@ApiExpose({ name: 'access_token' }) | ||
@IsString() | ||
@IsNotEmpty() | ||
readonly accessToken: string; | ||
|
||
constructor(accessToken: string) { | ||
this.accessToken = accessToken; | ||
} | ||
} | ||
|
||
export class KakaoLoginDto { | ||
@ApiProperty({ name: 'access_token' }) | ||
@Expose({ name: 'access_token' }) | ||
@ApiExpose({ name: 'access_token' }) | ||
@IsString() | ||
@IsNotEmpty() | ||
readonly accessToken: string; | ||
|
||
constructor(accessToken: string) { | ||
this.accessToken = accessToken; | ||
} | ||
} | ||
|
||
export class OAuthLoginSessionDto { | ||
@ApiProperty({ name: 'is_exist' }) | ||
@Expose({ name: 'is_exist' }) | ||
@ApiExpose({ name: 'is_exist' }) | ||
readonly isExist: boolean; | ||
|
||
@ApiProperty({ name: 'session_token' }) | ||
@Expose({ name: 'session_token' }) | ||
@ApiExpose({ name: 'session_token' }) | ||
readonly sessionToken?: string; | ||
|
||
@ApiProperty({ name: 'user' }) | ||
@Expose({ name: 'user' }) | ||
@Type(() => UserDto) | ||
@ApiExpose({ name: 'user' }) | ||
readonly user?: UserDto; | ||
|
||
@ApiProperty({ name: 'register_token' }) | ||
@Expose({ name: 'register_token' }) | ||
@ApiExpose({ name: 'register_token' }) | ||
readonly registerToken?: string; | ||
|
||
constructor(props: { | ||
isExist: boolean; | ||
sessionToken?: string; | ||
user?: UserDto; | ||
registerToken?: string; | ||
}) { | ||
this.isExist = props.isExist; | ||
this.sessionToken = props.sessionToken; | ||
this.user = props.user; | ||
this.registerToken = props.registerToken; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { SessionEntity } from '@app/auth/domain/session.entity'; | ||
import { UserInfo } from '@app/auth/types/user-info.type'; | ||
import { LoginSessionDto } from '@app/auth/dto/token.dto'; | ||
import { | ||
GoogleLoginDto, | ||
KakaoLoginDto, | ||
OAuthLoginSessionDto, | ||
} from '@app/auth/dto/oauth.dto'; | ||
import { userDto, userEntity } from '../../../user/test/fixture/user.fixture'; | ||
|
||
export const sessionEntity: SessionEntity = { | ||
id: 1, | ||
sessionToken: 'token', | ||
userId: 1, | ||
user: userEntity, | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}; | ||
|
||
export const userInfo: UserInfo = { | ||
email: '[email protected]', | ||
username: 'test', | ||
}; | ||
|
||
export const loginSessionDto: LoginSessionDto = { | ||
sessionToken: 'sessToken', | ||
user: userDto, | ||
}; | ||
|
||
export const googleLoginDto: GoogleLoginDto = new GoogleLoginDto('accessToken'); | ||
|
||
export const kakaoLoginDto: KakaoLoginDto = new KakaoLoginDto('accessToken'); | ||
|
||
export const oAuthLoginSessionDto: OAuthLoginSessionDto = | ||
new OAuthLoginSessionDto({ | ||
isExist: true, | ||
sessionToken: loginSessionDto.sessionToken, | ||
user: loginSessionDto.user, | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { AuthService } from '@app/auth/auth.service'; | ||
import { SessionAuthGuard } from '@app/auth/guards/session-auth.guard'; | ||
import { RegisterAuthGuard } from '@app/auth/guards/register-auth.guard'; | ||
|
||
export const MockedAuthService = { | ||
provide: AuthService, | ||
useValue: { | ||
register: jest.fn(), | ||
verifyRegisterToken: jest.fn(), | ||
findBySessionToken: jest.fn(), | ||
login: jest.fn(), | ||
OAuthLoginByEmail: jest.fn(), | ||
googleLogin: jest.fn(), | ||
kakaoLogin: jest.fn(), | ||
logout: jest.fn(), | ||
}, | ||
}; | ||
|
||
export const MockedSessionAuthGuard = { | ||
provide: SessionAuthGuard, | ||
useValue: { | ||
canActivate: jest.fn(), | ||
}, | ||
}; | ||
|
||
export const MockedRegisterAuthGuard = { | ||
provide: RegisterAuthGuard, | ||
useValue: { | ||
canActivate: jest.fn(), | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.