Skip to content

Commit

Permalink
Add signup controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mapeveri committed Dec 6, 2024
1 parent 4b0eb0b commit 6a4d3a2
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/languages/_dependencyInjection/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import LikeTermPostController from '@src/languages/app/controllers/v1/terms/like
import DislikeTermPostController from '@src/languages/app/controllers/v1/terms/dislikeTermPostController';
import WordPutController from '@src/languages/app/controllers/v1/terms/words/wordPutController';
import TermGetController from '@src/languages/app/controllers/v1/terms/termGetController';
import SignupPostController from '@src/languages/app/controllers/v1/auth/signupPostController';

export const controllers = [
LoginPostController,
SignupPostController,
RefreshTokenPostController,
MeGetController,
SearchTermsGetController,
Expand Down
17 changes: 17 additions & 0 deletions src/languages/app/controllers/v1/auth/signupPostController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Body, Controller, HttpCode, Post } from '@nestjs/common';
import { ApiBadRequestResponse, ApiInternalServerErrorResponse, ApiTags } from '@nestjs/swagger';
import SignupPostDto from '@src/languages/app/controllers/v1/auth/signupPostDto';

@ApiTags('Auth')
@Controller()
export default class SignupPostController {
public constructor() {}

@Post('auth/signup')
@HttpCode(201)
@ApiBadRequestResponse({ description: 'Bad Request.' })
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' })
async run(@Body() _payload: SignupPostDto): Promise<void> {
throw new Error('Not implemented');
}
}
28 changes: 28 additions & 0 deletions src/languages/app/controllers/v1/auth/signupPostDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';

export default class SignupPostDto {
@ApiProperty()
@IsNotEmpty()
@IsString()
name: string;

@ApiProperty()
@IsNotEmpty()
@IsEmail()
email: string;

@ApiProperty()
@IsNotEmpty()
@IsString()
token: string;

@ApiProperty()
@IsNotEmpty()
@IsString()
provider: string;

@ApiProperty()
@IsString()
photo: string;
}
52 changes: 52 additions & 0 deletions test/acceptance/auth/signupPostController.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { beforeAll, describe, beforeEach, afterAll, it } from '@jest/globals';
import { INestApplication } from '@nestjs/common';
import request = require('supertest');
import { MikroORM } from '@mikro-orm/core';
import { createApplication, truncateTables } from '@test/acceptance/createApplication';

describe('Given a SignupPostController to handle', () => {
let app: INestApplication;
let orm: MikroORM;

const prepareApp = async () => {
const setup = await createApplication();
app = setup.app;
orm = setup.orm;
};

const closeApp = async () => {
await orm.close(true);
await app.close();
};

beforeAll(async () => {
await prepareApp();
});

afterAll(async () => {
await closeApp();
});

describe('As a user I want to signup in the app', () => {
async function startScenario() {
await truncateTables(orm);
}

beforeEach(startScenario);

it('should create the user', async () => {
await request(app.getHttpServer())
.post('/auth/signup')
.set('Authorization', 'Bearer mock-token')
.send({
email: '[email protected]',
password: 'test123',
name: 'test',
token: '123',
provider: 'google',
photo: '',
})
.expect(201);
});
});
});

0 comments on commit 6a4d3a2

Please sign in to comment.