@@ -3,6 +3,7 @@ import {TestBed} from '@angular/core/testing';
3
3
import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ;
4
4
import { COURSES } from '../../../../server/db-data' ;
5
5
import { Course } from '../model/course' ;
6
+ import { HttpErrorResponse } from '@angular/common/http' ;
6
7
7
8
8
9
describe ( 'CoursesService' , ( ) => {
@@ -69,8 +70,6 @@ describe('CoursesService', () => {
69
70
70
71
} ) ;
71
72
72
-
73
-
74
73
it ( 'should save the course data' , ( ) => {
75
74
76
75
const changes :Partial < Course > =
@@ -97,6 +96,27 @@ describe('CoursesService', () => {
97
96
98
97
} ) ;
99
98
99
+ it ( 'should give an error if save course fails' , ( ) => {
100
+
101
+ const changes :Partial < Course > =
102
+ { titles :{ description : 'Testing Course' } } ;
103
+
104
+ coursesService . saveCourse ( 12 , changes )
105
+ . subscribe (
106
+ ( ) => fail ( "the save course operation should have failed" ) ,
107
+
108
+ ( error : HttpErrorResponse ) => {
109
+ expect ( error . status ) . toBe ( 500 ) ;
110
+ }
111
+ ) ;
112
+
113
+ const req = httpTestingController . expectOne ( '/api/courses/12' ) ;
114
+
115
+ expect ( req . request . method ) . toEqual ( "PUT" ) ;
116
+
117
+ req . flush ( 'Save course failed' , { status :500 ,
118
+ statusText :'Internal Server Error' } ) ;
119
+ } ) ;
100
120
101
121
102
122
afterEach ( ( ) => {
@@ -108,3 +128,15 @@ describe('CoursesService', () => {
108
128
109
129
110
130
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
0 commit comments