Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E test for project creation #32

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/controller/project/createProject.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import request from 'supertest'
import { app } from '../../app'
import { randomUUID } from 'crypto'
import { PrismaProjectRepository } from '../../repositories/prisma/prisma-project-repository'
import { PrismaUsersRepository } from '../../repositories/prisma/prisma-users-repository'
import { ProjectRepository } from '../../repositories/project-repository'
import { UserRepository } from '../../repositories/user-repository'

let projectRepository: ProjectRepository
let userRepository: UserRepository

describe('createProject E2E', () => {
beforeAll(async () => {
projectRepository = new PrismaProjectRepository()
userRepository = new PrismaUsersRepository()
await app.ready()
})

afterAll(async () => {
await app.close()
})

it('should be able to create a project', async () => {
const createProjectBody = {
title: 'Squad40 Project',
tags: 'Squad40',
link: 'https://Squad40.com',
description: 'Squad40 description',
}

const newUser = await userRepository.create({
email: '[email protected]',
name: 'John',
surname: 'Doe',
password_hash: 'password',
})

const createProjectResponse = await request(app.server)
.post(`/user/${newUser.id}/project`)
.send(createProjectBody)

expect(createProjectResponse.statusCode).toEqual(201)
expect(createProjectResponse.body.project.title).toEqual('Squad40 Project')
})

it('should not be able to create a project without user', async () => {
const createProjectBody = {
title: 'Squad40 Project',
tags: 'Squad40',
link: 'https://Squad40.com',
description: 'Squad40 description',
}

const userId = randomUUID()

const response = await request(app.server)
.post(`/user/${userId}/project`)
.send(createProjectBody)

expect(response.body.message).toContain('User was not Found !')
expect(response.status).toEqual(404)
})
})
2 changes: 1 addition & 1 deletion src/controller/project/createProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function createProject(
userRepository,
)
try {
const project = await createProjectUseCase.execute({
const { project } = await createProjectUseCase.execute({
userId,
title,
tags,
Expand Down
Loading