|
1 | 1 | import {CoursesService} from './courses.service';
|
2 | 2 | import {TestBed} from '@angular/core/testing';
|
3 | 3 | import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
4 |
| -import {COURSES} from '../../../../server/db-data'; |
| 4 | +import {COURSES, findLessonsForCourse} from '../../../../server/db-data'; |
5 | 5 | import {Course} from '../model/course';
|
6 | 6 | import {HttpErrorResponse} from '@angular/common/http';
|
7 | 7 |
|
@@ -118,6 +118,33 @@ describe('CoursesService', () => {
|
118 | 118 | statusText:'Internal Server Error'});
|
119 | 119 | });
|
120 | 120 |
|
| 121 | + it('should find a list of lessons', () => { |
| 122 | + |
| 123 | + coursesService.findLessons(12) |
| 124 | + .subscribe(lessons => { |
| 125 | + |
| 126 | + expect(lessons).toBeTruthy(); |
| 127 | + |
| 128 | + expect(lessons.length).toBe(3); |
| 129 | + |
| 130 | + }); |
| 131 | + |
| 132 | + const req = httpTestingController.expectOne( |
| 133 | + req => req.url == '/api/lessons'); |
| 134 | + |
| 135 | + expect(req.request.method).toEqual("GET"); |
| 136 | + expect(req.request.params.get("courseId")).toEqual("12"); |
| 137 | + expect(req.request.params.get("filter")).toEqual(""); |
| 138 | + expect(req.request.params.get("sortOrder")).toEqual("asc"); |
| 139 | + expect(req.request.params.get("pageNumber")).toEqual("0"); |
| 140 | + expect(req.request.params.get("pageSize")).toEqual("3"); |
| 141 | + |
| 142 | + req.flush({ |
| 143 | + payload: findLessonsForCourse(12).slice(0,3) |
| 144 | + }); |
| 145 | + |
| 146 | + |
| 147 | + }); |
121 | 148 |
|
122 | 149 | afterEach(() => {
|
123 | 150 |
|
|
0 commit comments