Skip to content

Commit

Permalink
refactor: Add endpoint to create test account
Browse files Browse the repository at this point in the history
  • Loading branch information
PleBea committed Jul 18, 2024
1 parent e815bfd commit 9d19143
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Controller, Get, Req, UseGuards } from '@nestjs/common';
import { Controller, Get, Post, Req, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiOkResponse, ApiOperation, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';

import { OAuthResponseDTO } from 'src/common';
import { AuthType, OAuthResponseDTO } from 'src/common';

import { AuthService } from './auth.service';

Expand All @@ -21,4 +21,13 @@ export class AuthController {
async refresh(@Req() req: any): Promise<OAuthResponseDTO> {
return await this.authService.createTokens(req.user.id);
}

@Post('test-account')
@ApiOperation({ summary: 'Create test account' })
@ApiOkResponse({ description: 'Test account created', type: OAuthResponseDTO })
async createTestAccount(): Promise<OAuthResponseDTO> {
const user = await this.authService.createUser(AuthType.test);

return await this.authService.createTokens(user.id);
}
}
4 changes: 2 additions & 2 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export class AuthService {
private readonly configService: ConfigService,
) {}

async createUser(provider: AuthType, providerId: string) {
async createUser(provider: AuthType, providerId?: string) {
return await this.prisma.user.create({
data: {
id: randomUUID(),
provider,
providerId,
providerId: providerId || randomUUID(),
},
});
}
Expand Down
1 change: 1 addition & 0 deletions src/common/models/auth.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export const enum AuthType {
kakao = 'kakao',
google = 'google',
apple = 'apple',
test = 'test',
}

0 comments on commit 9d19143

Please sign in to comment.