File tree 1 file changed +26
-1
lines changed
1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 4
4
} from "@angular/common/http/testing" ;
5
5
import { TestBed } from "@angular/core/testing" ;
6
6
import { COURSES , findCourseById } from "../../../../server/db-data" ;
7
+ import { Course } from "../model/course" ;
7
8
import { CoursesService } from "./courses.service" ;
8
9
describe ( "CoursesService" , ( ) => {
9
10
let coursesService : CoursesService ,
@@ -52,7 +53,31 @@ describe("CoursesService", () => {
52
53
httpTestingController . verify ( ) ;
53
54
} ) ;
54
55
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
56
81
57
82
afterEach ( ( ) => {
58
83
httpTestingController . verify ( ) ;
You can’t perform that action at this time.
0 commit comments