|
1 | 1 | import { FileCourseRepository } from '../../../../../src/Contexts/Mooc/Courses/infrastructure/FileCourseRepository'; |
2 | 2 | import { Course } from '../../../../../src/Contexts/Mooc/Courses/domain/Course'; |
3 | 3 | import { CourseId } from '../../../../../src/Contexts/Mooc/Shared/domain/Courses/CourseId'; |
| 4 | +import { CourseName } from '../../../../../src/Contexts/Mooc/Courses/domain/CourseName'; |
| 5 | +import { CourseDuration } from '../../../../../src/Contexts/Mooc/Courses/domain/CourseDuration'; |
4 | 6 |
|
5 | 7 | describe('Save Course', () => { |
6 | | - it('should have a course', () => { |
| 8 | + it('should have a course', async () => { |
7 | 9 | const repository = new FileCourseRepository(); |
8 | | - const course = new Course(new CourseId('0766c602-d4d4-48b6-9d50-d3253123275e'), 'name', 'duration'); |
| 10 | + const course = new Course( |
| 11 | + new CourseId('0766c602-d4d4-48b6-9d50-d3253123275e'), |
| 12 | + new CourseName('name'), |
| 13 | + new CourseDuration('duration') |
| 14 | + ); |
9 | 15 |
|
10 | | - repository.save(course); |
| 16 | + await repository.save(course); |
| 17 | + }); |
| 18 | +}); |
| 19 | + |
| 20 | +describe('Search Course', () => { |
| 21 | + it('should return an existing course', async () => { |
| 22 | + const repository = new FileCourseRepository(); |
| 23 | + const course = new Course( |
| 24 | + new CourseId('0766c602-d4d4-48b6-9d50-d3253123275e'), |
| 25 | + new CourseName('name'), |
| 26 | + new CourseDuration('duration') |
| 27 | + ); |
| 28 | + |
| 29 | + await repository.save(course); |
| 30 | + |
| 31 | + expect(course).toEqual(await repository.search(course.id)); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should not return a non existing course', async () => { |
| 35 | + const repository = new FileCourseRepository(); |
| 36 | + |
| 37 | + expect(await repository.search(new CourseId('de8c20b5-1181-415b-bb82-1f15bf1b67f1'))).toBeFalsy(); |
11 | 38 | }); |
12 | 39 | }); |
0 commit comments