Skip to content

Commit

Permalink
feat(CC-81): add create clinic e2e test and refactor folder organization
Browse files Browse the repository at this point in the history
  • Loading branch information
luanavfg committed Oct 27, 2023
1 parent 0ffbb4d commit 9cdff17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import request from 'supertest';
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';

import { makePsychologist } from '../../../../../tests/factories/make-psychologist';
import { PostgreSqlPrismaOrmService } from '../../../../database/infra/prisma/prisma.service';
import { ApiModule } from '../../api.module';
import { PsychologistEntity } from '@clinicControl/core-rest-api/core/src/domains/psychologist/entities/psychologist/entity';
import { Plan, Role } from '@clinicControl/core-rest-api/core/src/shared/interfaces/payments';
import { makeClinic } from '@clinicControl/root/libs/core-rest-api/adapters/tests/factories/make-clinic';
import { faker } from '@faker-js/faker';
import { PostgreSqlPrismaOrmService } from '../../../../../database/infra/prisma/prisma.service';
import { ApiModule } from '../../../api.module';

describe('[E2E] - Create Clinic', () => {
let app: INestApplication;
Expand All @@ -24,72 +27,34 @@ describe('[E2E] - Create Clinic', () => {
});

it('[POST] - Should successfully create a new clinic', async () => {
const {id} = makePsychologist();
const newClinic = makePsychologist();

const response = await request(app.getHttpServer())
const newPsychologist =
new PsychologistEntity({
name: 'Novo Usuário Teste',
email: '[email protected]',
password: faker.internet.password({ length: 8 }),
plan: Plan.BASIC,
role: Role.ADMIN
})

await request(app.getHttpServer())
.post('/psychologist/create')
.set('api-key', 'api-key')
.send(newPsychologist);

expect(response.statusCode).toBe(201);

const userOnDatabase = await prisma.psychologist.findUnique({
const createdPsychologist = await prisma.psychologist.findUnique({
where: {
email: '[email protected]',
},
});

expect(userOnDatabase).toBeTruthy();
});

it('[POST] - Should return an error when trying to create a new psychologist without api-key', async () => {
const newPsychologist = makePsychologist({
email: '[email protected]',
});

const response = await request(app.getHttpServer())
.post('/psychologist/create')
.send(newPsychologist);

expect(response.statusCode).toBe(401);

const userOnDatabase = await prisma.psychologist.findUnique({
where: {
email: '[email protected]',
},
});

expect(userOnDatabase).toBeFalsy();
expect(response.body.message).toBe('API key is missing');
});

it('[POST] - Should return an error when trying to create a new psychologist that already exists', async () => {
const newPsychologist = makePsychologist({
email: '[email protected]',
});
const psychologistId = createdPsychologist ? createdPsychologist?.id : ''
const newClinic = makeClinic(psychologistId);

const response = await request(app.getHttpServer())
.post('/psychologist/create')
.post('/clinic/create')
.set('api-key', 'api-key')
.send(newPsychologist);
.send(newClinic);

expect(response.statusCode).toBe(201);

const userOnDatabase = await prisma.psychologist.findUnique({
where: {
email: '[email protected]',
},
});

expect(userOnDatabase).toBeTruthy();

const response_new_post = await request(app.getHttpServer())
.post('/psychologist/create')
.set('api-key', 'api-key')
.send(newPsychologist);

expect(response_new_post.statusCode).toBe(409);
expect(response_new_post.body.message).toBe('psychologist already exists');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import request from 'supertest';
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';

import { makePsychologist } from '../../../../../tests/factories/make-psychologist';
import { PostgreSqlPrismaOrmService } from '../../../../database/infra/prisma/prisma.service';
import { ApiModule } from '../../api.module';
import { makePsychologist } from '../../../../../../tests/factories/make-psychologist';
import { PostgreSqlPrismaOrmService } from '../../../../../database/infra/prisma/prisma.service';
import { ApiModule } from '../../../api.module';

describe('[E2E] - Create Psychologist Account', () => {
let app: INestApplication;
Expand Down

0 comments on commit 9cdff17

Please sign in to comment.