@@ -21,6 +21,20 @@ class CountryListMapperTests: XCTestCase {
2121 XCTAssertEqual ( countries [ 1 ] . states. count, 18 )
2222 XCTAssertEqual ( countries [ 1 ] . states. first, StateOfACountry ( code: " PY-ASU " , name: " Asunción " ) )
2323 }
24+
25+ func test_countries_are_properly_parsed_if_the_response_has_no_data_envelope( ) {
26+ guard let countries = mapCountriesResponseWithoutDataEnvelope ( ) else {
27+ XCTFail ( )
28+ return
29+ }
30+
31+ XCTAssertEqual ( countries. count, 3 )
32+ XCTAssertEqual ( countries. first? . states. isEmpty, true )
33+ XCTAssertEqual ( countries [ 1 ] . code, " PY " )
34+ XCTAssertEqual ( countries [ 1 ] . name, " Paraguay " )
35+ XCTAssertEqual ( countries [ 1 ] . states. count, 18 )
36+ XCTAssertEqual ( countries [ 1 ] . states. first, StateOfACountry ( code: " PY-ASU " , name: " Asunción " ) )
37+ }
2438}
2539
2640/// Private Helpers
@@ -37,9 +51,15 @@ private extension CountryListMapperTests {
3751 return try ! CountryListMapper ( ) . map ( response: response)
3852 }
3953
40- /// Returns the CountryListMapper output upon receiving `countries`
54+ /// Returns the [Country] output upon receiving `countries`
4155 ///
4256 func mapCountriesResponse( ) -> [ Country ] ? {
4357 return mapCountries ( from: " countries " )
4458 }
59+
60+ /// Returns the [Country] output upon receiving `countries-without-data`
61+ ///
62+ func mapCountriesResponseWithoutDataEnvelope( ) -> [ Country ] ? {
63+ return mapCountries ( from: " countries-without-data " )
64+ }
4565}
0 commit comments