Skip to content

Commit 506745f

Browse files
committed
Update courses.service.spec.ts
1 parent 6d3bad7 commit 506745f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/app/courses/services/courses.service.spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from "@angular/common/http/testing";
55
import { TestBed } from "@angular/core/testing";
66
import { COURSES, findCourseById } from "../../../../server/db-data";
7+
import { Course } from "../model/course";
78
import { CoursesService } from "./courses.service";
89
describe("CoursesService", () => {
910
let coursesService: CoursesService,
@@ -52,7 +53,31 @@ describe("CoursesService", () => {
5253
httpTestingController.verify();
5354
});
5455

55-
//
56+
it("should save the course data", () => {
57+
const changes: Partial<Course> = {
58+
titles: { description: "Testing Course" },
59+
};
60+
61+
coursesService.saveCourse(12, changes).subscribe((course) => {
62+
expect(course.id).toBe(12);
63+
});
64+
65+
const req = httpTestingController.expectOne("/api/courses/12");
66+
67+
expect(req.request.method).toEqual("PUT");
68+
69+
expect(req.request.body.titles.description).toEqual(
70+
changes.titles.description
71+
);
72+
73+
// what would server return after saving the data in db
74+
req.flush({
75+
...COURSES[12],
76+
...changes,
77+
});
78+
});
79+
80+
//will be called after each spec got executed
5681

5782
afterEach(() => {
5883
httpTestingController.verify();

0 commit comments

Comments
 (0)