Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@nestjs/common';
- import { PrismaService } from '../prisma/prisma.service';
- import { EditUserDto } from './dto';
- @Injectable()
- export class UserService {
- constructor(private prisma: PrismaService) {}
- async editUser(userId: number, dto: EditUserDto) {
- const user = await this.prisma.user.update({
- where: {
- id: userId,
- },
- data: {
- ...dto,
- },
- });
- delete user.hash;
- return user;
- }
- }
- ============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
- //HERE IS test file im running:
- import { Test } from '@nestjs/testing';
- import { INestApplication, ValidationPipe } from '@nestjs/common';
- import { AppModule } from '../src/app.module';
- import { PrismaService } from '../src/prisma/prisma.service';
- import * as pactum from 'pactum';
- import { AuthDto } from 'src/auth/dto';
- import { EditUserDto } from 'src/user/dto';
- describe('App e2e', () => {
- let app: INestApplication;
- let prisma: PrismaService;
- beforeAll(async () => {
- const moduleRef = await Test.createTestingModule({
- imports: [AppModule],
- }).compile();
- app = moduleRef.createNestApplication();
- app.useGlobalPipes(
- new ValidationPipe({
- whitelist: true,
- }),
- );
- await app.init();
- await app.listen(3333);
- prisma = app.get(PrismaService);
- await prisma.cleanDb();
- pactum.request.setBaseUrl('http://localhost:3333');
- });
- afterAll(() => {
- app.close();
- });
- describe('Auth', () => {
- const dto: AuthDto = {
- email: 'vlad@gmail.com',
- password: '123',
- };
- //Signup test process
- describe('Signup', () => {
- it('should throw if email empty', () => {
- return pactum
- .spec()
- .post('/auth/signup')
- .withBody({
- password: dto.password,
- })
- .expectStatus(400);
- });
- it('should throw if password empty', () => {
- return pactum
- .spec()
- .post('/auth/signup')
- .withBody({
- email: dto.email,
- })
- .expectStatus(400);
- });
- it('should throw if no body (no email, nor password)', () => {
- return pactum.spec().post('/auth/signup').expectStatus(400);
- });
- it('should signup', () => {
- return pactum
- .spec()
- .post('/auth/signup')
- .withBody(dto)
- .expectStatus(201);
- });
- });
- //Signin test process
- describe('Signin', () => {
- it('should throw if email empty', () => {
- return pactum
- .spec()
- .post('/auth/signin')
- .withBody({
- password: dto.password,
- })
- .expectStatus(400);
- });
- it('should throw if password empty', () => {
- return pactum
- .spec()
- .post('/auth/signin')
- .withBody({
- email: dto.email,
- })
- .expectStatus(400);
- });
- it('should throw if no body (no email, nor password)', () => {
- return pactum.spec().post('/auth/signin').expectStatus(400);
- });
- it('should signin', () => {
- return pactum
- .spec()
- .post('/auth/signin')
- .withBody(dto)
- .expectStatus(200)
- .stores('userAt', 'access_token');
- });
- });
- });
- describe('User', () => {
- describe('Get me', () => {
- it('should get current user', () => {
- return pactum
- .spec()
- .get('/users/me')
- .withHeaders({
- Authorization: 'Bearer $S{userAt}',
- })
- .expectStatus(200);
- });
- });
- describe('Edit user', () => {
- it('should edit user', () => {
- const dto: EditUserDto = {
- firstName: 'Daniel',
- email: 'ddanielfenoll@gmail.com',
- };
- return pactum
- .spec()
- .patch('/users')
- .withBody(dto)
- .withHeaders({
- Authorization: 'Bearer $S{userAt}',
- })
- .expectStatus(200)
- .inspect();
- });
- });
- });
- describe('Bookmarks', () => {
- describe('Create bookmark', () => {});
- describe('Get bookmarks', () => {});
- describe('Get bookmark by id', () => {});
- describe('Edit bookmark by id', () => {});
- describe('Delete bookmark by id', () => {});
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment