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
-14,12 +15,14 @@ test.describe('Feature: Adding a book', () => { | |
page, | |
}) => { | |
await page.goto('http://localhost:3000'); | |
- await page.getByLabel(/title/i).fill('Clean Code'); | |
+ await page.getByLabel(/title/i).fill('The Pragmatic Programmer'); | |
await page.getByText(/add book/i).click(); | |
- await page.getByLabel(/title/i).fill('Clean Code'); | |
+ await page.getByLabel(/title/i).fill('The Pragmatic Programmer'); |
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
-3,8 +3,9 @@ import { test, expect } from '@playwright/test'; | |
test.describe('Feature: Adding a book', () => { | |
test('Example: User can add a book', async ({ page }) => { | |
await page.goto('http://localhost:3000'); | |
+ const rand = Math.floor(Math.random() * 1000000); | |
- await page.getByLabel(/title/i).fill('Clean Code'); | |
+ await page.getByLabel(/title/i).fill(`Clean Code ${rand}`); | |
await page.getByText(/add book/i).click(); |
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
-10,7 +10,7 @@ import { BookRepository } from './book-repository.port'; | |
providers: [ | |
{ | |
provide: BookRepository, | |
- useValue: InMemoryBookRepository, | |
+ useClass: InMemoryBookRepository, | |
}, | |
AddBookUseCase, | |
], |
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
-35,4 +34,56 @@ export class AppController { | |
</body> | |
</html>`; | |
} | |
+ | |
+ @Post() | |
+ async addBook(@Body() body: { title: string }) { | |
+ try { | |
+ await this.addBookUseCase.execute({ title: body.title }); | |
+ return ` |
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
-15,12 +15,11 @@ 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/[email protected]" integrity="sha384-QWGpdj554B4ETpJJC9z+ZHJcA/i59TyjxEPXiiUgN2WmTyV5OEZWCD6gQhgkdpB/" crossorigin="anonymous"></script> | |
</head> | |
<body> | |
<main class="container mx-auto px-4 py-8"> | |
- ${query?.title ? '<p>Book added</p>' : ''} | |
- <form class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4"> |
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
-6,7 +6,7 @@ export class AppController { | |
constructor(private readonly addBookUseCase: AddBookUseCase) {} | |
@Get() | |
- getHello(@Query() query?: { title: string }): string { | |
+ index(): string { // plus besoin de récupérer la querystring, cette route devient simplement notre page de base | |
return ` | |
<!DOCTYPE html> | |
<html> |
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
-22,6 +22,8 @@ describe('Feature: Adding a book', () => { | |
const addingBook = addBook.execute({ title: 'Clean Code' }); | |
- await expect(addingBook).rejects.toThrow(new BookAlreadyExistsError('Foo')); | |
+ await expect(addingBook).rejects.toThrow( | |
+ new BookAlreadyExistsError('Clean Code'), | |
+ ); | |
}); | |
}); |
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
-1,11 +1,15 @@ | |
import { Injectable } from '@nestjs/common'; | |
import { BookRepository } from './book-repository.port'; | |
+import { BookAlreadyExistsError } from './book-already-exists.error'; | |
@Injectable() | |
export class AddBookUseCase { | |
constructor(private readonly bookRepository: BookRepository) {} | |
- execute(book: { title: string }) { |
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
-21,8 +22,6 @@ describe('Feature: Adding a book', () => { | |
const addingBook = addBook.execute({ title: 'Clean Code' }); | |
- await expect(addingBook).rejects.toThrow( | |
- new BookAlreadyExistsError('The book Clean Code already exists'), | |
- ); | |
+ await expect(addingBook).rejects.toThrow(new BookAlreadyExistsError('Foo')); | |
}); | |
}); |
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
-9,4 +9,8 @@ export class InMemoryBookRepository implements BookRepository { | |
this.lastSavedBook = book; | |
this.booksByTitle.set(book.title, book); | |
} | |
+ | |
+ async doesBookExist(title: string): Promise<boolean> { | |
+ return this.booksByTitle.has(title); | |
+ } | |
} |