@@ -31,7 +31,8 @@ class UpdatesTests: XCTestCase {
3131
3232 let data = json. data ( using: . utf8) !
3333
34- let stubResult : Update . Result = try ! Constants . customJSONDecoder. decode ( Update . Result. self, from: data)
34+ let stubResult : Update . Result = try ! Constants . customJSONDecoder. decode (
35+ Update . Result. self, from: data)
3536
3637 session. pushData ( json)
3738
@@ -46,10 +47,51 @@ class UpdatesTests: XCTestCase {
4647 switch result {
4748 case . success( let result) :
4849 XCTAssertEqual ( stubResult, result)
49- expectation. fulfill ( )
5050 case . failure:
5151 XCTFail ( " Failed to get settings " )
5252 }
53+ expectation. fulfill ( )
54+ }
55+
56+ self . wait ( for: [ expectation] , timeout: 1.0 )
57+
58+ }
59+
60+ func testGetUpdateInvalidStatus( ) {
61+
62+ //Prepare the mock server
63+
64+ let badStatusUpdateJson = """
65+ {
66+ " status " : " something " ,
67+ " updateId " : 1,
68+ " type " : {
69+ " name " : " DocumentsAddition " ,
70+ " number " : 4
71+ },
72+ " duration " : 0.076980613,
73+ " enqueuedAt " : " 2019-12-07T21:16:09.623944Z " ,
74+ " processedAt " : " 2019-12-07T21:16:09.703509Z "
75+ }
76+ """
77+
78+ session. pushData ( badStatusUpdateJson)
79+
80+ // Start the test with the mocked server
81+
82+ let UID : String = " movies "
83+ let update = Update ( updateId: 1 )
84+
85+ let expectation = XCTestExpectation ( description: " Get settings " )
86+
87+ self . client. getUpdate ( UID: UID, update) { result in
88+ switch result {
89+ case . success:
90+ XCTFail ( " The server send a invalid status and it should not succeed " )
91+ case . failure( let error) :
92+ XCTAssertTrue ( error is Update . Status . StatusError )
93+ expectation. fulfill ( )
94+ }
5395 }
5496
5597 self . wait ( for: [ expectation] , timeout: 1.0 )
@@ -92,10 +134,10 @@ class UpdatesTests: XCTestCase {
92134 switch result {
93135 case . success( let results) :
94136 XCTAssertEqual ( stubResults, results)
95- expectation. fulfill ( )
96137 case . failure:
97138 XCTFail ( " Failed to get settings " )
98139 }
140+ expectation. fulfill ( )
99141 }
100142
101143 self . wait ( for: [ expectation] , timeout: 1.0 )
0 commit comments