This file contains hidden or 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
| -1,3 +1,4 @@ | |
| export abstract class BookRepository { | |
| abstract save(book: { title: string }): Promise<void>; | |
| + abstract doesBookExist(title: string): Promise<boolean>; | |
| } | |
This file contains hidden or 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
| -0,0 +1,5 @@ | |
| +export class BookAlreadyExistsError extends Error { | |
| + constructor(bookTitle: string) { | |
| + super(`The book ${bookTitle} already exists`); | |
| + } | |
| +} | |
This file contains hidden or 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
| import { BookRepository } from './book-repository.port'; | |
| export class InMemoryBookRepository implements BookRepository { | |
| + booksByTitle = new Map<string, { title: string }>(); // J'en profite ici pour créer une Map référençant les livres par titre. | |
| + | |
| lastSavedBook: { title: string } | undefined; | |
| async save(book: { title: string }): Promise<void> { | |
| this.lastSavedBook = book; | |
| + this.booksByTitle.set(book.title, book); |
This file contains hidden or 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
| + test('Example: User cannot add a book that already exists', async () => { | |
| + const bookRepository = new StubBookRepository(); | |
| + bookRepository.booksByTitle.set('Clean Code', { title: 'Clean Code' }); | |
| + const addBook = new AddBookUseCase(bookRepository); | |
| + | |
| + const addingBook = addBook.execute({ title: 'Clean Code' }); | |
| + | |
| + await expect(addingBook).rejects.toThrowError( | |
| + new BookAlreadyExistsError('The book Clean Code already exists'), | |
| + ); |
This file contains hidden or 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
| + | |
| + test('Example: User cannot add a book that already exists', async ({ | |
| + page, | |
| + }) => { | |
| + await page.goto('http://localhost:3000'); | |
| + await page.getByLabel(/title/i).fill('Clean Code'); | |
| + await page.getByText(/add book/i).click(); | |
| + | |
| + await page.getByLabel(/title/i).fill('Clean Code'); | |
| + await page.getByText(/add book/i).click(); |
This file contains hidden or 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
| -15,6 +15,7 @@ export class AppController { | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| + <script src="https://unpkg.com/htmx.org@2.0.1"></script> | |
| </head> | |
| <body> | |
| <main class="container mx-auto px-4 py-8"> | |
This file contains hidden or 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
| export class AppController { | |
| <html> | |
| <head> | |
| <title>Crafty Reads</title> | |
| + <meta charset="UTF-8"> | |
| + <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| + <script src="https://cdn.tailwindcss.com"></script> | |
| </head> | |
| <body> | |
| - <form> |
This file contains hidden or 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
| -1,10 +1,18 @@ | |
| import { Module } from '@nestjs/common'; | |
| import { AppController } from './app.controller'; | |
| -import { AppService } from './app.service'; | |
| +import { AddBookUseCase } from './add-book.usecase'; | |
| +import { StubBookRepository } from './stub.book-repository'; | |
| +import { BookRepository } from './book-repository.port'; | |
| @Module({ | |
| imports: [], |
This file contains hidden or 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
| -1,5 +1,7 @@ | |
| +import { Injectable } from '@nestjs/common'; | |
| import { BookRepository } from './book-repository.port'; | |
| +@Injectable() | |
| export class AddBookUseCase { | |
| constructor(private readonly bookRepository: BookRepository) {} | |
This file contains hidden or 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
| -1,3 +1,3 @@ | |
| -export interface BookRepository { | |
| - save(book: { title: string }): Promise<void>; | |
| +export abstract class BookRepository { | |
| + abstract save(book: { title: string }): Promise<void>; | |
| } | |