-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use case correction and unit testing
- Loading branch information
1 parent
9b1bc00
commit 75d13f2
Showing
5 changed files
with
78 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
import { Prisma, Project } from '@prisma/client' | ||
|
||
export interface ProjectRepository { | ||
create( | ||
data: Prisma.ProjectCreateWithoutUserInput, | ||
userId: string, | ||
): Promise<Project> | ||
findById(projectId: string): Promise<Project | null> | ||
create(data: Prisma.ProjectUncheckedCreateInput): Promise<Project> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { expect, describe, it, beforeEach } from 'vitest' | ||
|
||
import { CreateProjectUseCase } from './addProjectUseCase' | ||
|
||
import { InMemoryProjectRepository } from '../repositories/in-memory-db/inMemoryProjectRepository' | ||
import { InMemoryUserRepository } from '../repositories/in-memory-db/inMemoryUserRepository' | ||
|
||
let projectRepository: InMemoryProjectRepository | ||
let userRepository: InMemoryUserRepository | ||
let systemUnderTest: CreateProjectUseCase | ||
|
||
describe('Create Project Use Case', () => { | ||
beforeEach(() => { | ||
projectRepository = new InMemoryProjectRepository() | ||
userRepository = new InMemoryUserRepository() | ||
systemUnderTest = new CreateProjectUseCase( | ||
projectRepository, | ||
userRepository, | ||
) | ||
}) | ||
|
||
it('should be able to create a new project', async () => { | ||
const newUser = await userRepository.create({ | ||
name: 'Luis', | ||
surname: 'Pereira', | ||
email: '[email protected]', | ||
password_hash: '123456', | ||
}) | ||
|
||
const { project } = await systemUnderTest.execute({ | ||
title: 'React Typescript', | ||
description: 'Melhor Projeto', | ||
tags: 'React, Node', | ||
link: 'https://github.com/luiseduardo3/nodets-petcanil', | ||
userId: newUser.id, | ||
}) | ||
|
||
expect(project.id).toEqual(expect.any(String)) | ||
}) | ||
|
||
it('should not create a project if user does not exist', async () => { | ||
try { | ||
await systemUnderTest.execute({ | ||
title: 'Project with nonexistent user', | ||
description: 'Project without a valid user', | ||
tags: 'Invalid, Project', | ||
link: 'https://github.com/example/project-with-nonexistent-user', | ||
userId: 'non-existent-UserId', | ||
}) | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(Error) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.