Skip to content

Commit 21ae8f5

Browse files
committed
Added Unit Tests for SiteSettingMapper
1 parent f6814e5 commit 21ae8f5

File tree

3 files changed

+287
-1
lines changed

3 files changed

+287
-1
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@
320320
57BE08D82409B63800F6DCED /* reviews-missing-avatar-urls.json in Resources */ = {isa = PBXBuildFile; fileRef = 57BE08D72409B63700F6DCED /* reviews-missing-avatar-urls.json */; };
321321
57E8FED3246616AC0057CD68 /* Result+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E8FED2246616AC0057CD68 /* Result+Extensions.swift */; };
322322
6647C0161DAC6AB6570C53A7 /* Pods_Networking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F3F25DC15EC1D7C631169CB5 /* Pods_Networking.framework */; };
323+
68C87B342862D40E00A99054 /* setting-all-except-countries.json in Resources */ = {isa = PBXBuildFile; fileRef = 68C87B332862D40E00A99054 /* setting-all-except-countries.json */; };
323324
74002D6A2118B26100A63C19 /* SiteVisitStatsMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74002D692118B26000A63C19 /* SiteVisitStatsMapperTests.swift */; };
324325
74002D6C2118B88200A63C19 /* SiteVisitStatsRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74002D6B2118B88200A63C19 /* SiteVisitStatsRemoteTests.swift */; };
325326
740211DF2193985A002248DA /* comment-moderate-spam.json in Resources */ = {isa = PBXBuildFile; fileRef = 740211DE2193985A002248DA /* comment-moderate-spam.json */; };
@@ -993,6 +994,7 @@
993994
5726F7332460A8F00031CAAC /* CopiableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopiableTests.swift; sourceTree = "<group>"; };
994995
57BE08D72409B63700F6DCED /* reviews-missing-avatar-urls.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "reviews-missing-avatar-urls.json"; sourceTree = "<group>"; };
995996
57E8FED2246616AC0057CD68 /* Result+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Result+Extensions.swift"; sourceTree = "<group>"; };
997+
68C87B332862D40E00A99054 /* setting-all-except-countries.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "setting-all-except-countries.json"; sourceTree = "<group>"; };
996998
69314EDE650855CAF927057E /* Pods_NetworkingTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NetworkingTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
997999
74002D692118B26000A63C19 /* SiteVisitStatsMapperTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SiteVisitStatsMapperTests.swift; sourceTree = "<group>"; };
9981000
74002D6B2118B88200A63C19 /* SiteVisitStatsRemoteTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SiteVisitStatsRemoteTests.swift; sourceTree = "<group>"; };
@@ -2032,6 +2034,7 @@
20322034
45CCFCE927A2E59B0012E8CB /* inbox-note-list.json */,
20332035
4513382727A96DE700AE5E78 /* inbox-note.json */,
20342036
0205021B27C86B9700FB1C6B /* inbox-note-without-isRead.json */,
2037+
68C87B332862D40E00A99054 /* setting-all-except-countries.json */,
20352038
);
20362039
path = Responses;
20372040
sourceTree = "<group>";
@@ -2451,6 +2454,7 @@
24512454
31A451CE27863A2E00FE81AA /* stripe-account-wrong-json.json in Resources */,
24522455
0282DD91233A120A006A5FDB /* products-search-photo.json in Resources */,
24532456
45152825257A8B740076B03C /* product-attribute-update.json in Resources */,
2457+
68C87B342862D40E00A99054 /* setting-all-except-countries.json in Resources */,
24542458
3158FE6026129ADD00E566B9 /* wcpay-account-none.json in Resources */,
24552459
743E84FC22174CE100FAC9D7 /* restnoroute_error.json in Resources */,
24562460
CE20179320E3EFA7005B4C18 /* broken-orders.json in Resources */,

Networking/NetworkingTests/Mapper/SiteSettingMapperTests.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ final class SiteSettingMapperTests: XCTestCase {
1717
XCTAssertEqual(setting.label, "Enable coupons")
1818
XCTAssertEqual(setting.value, "yes")
1919
}
20-
20+
func test_SiteSetting_value_field_is_properly_parsed_when_value_field_is_not_string() throws {
21+
let setting = try XCTUnwrap(loadMultiselectValueSettingResponse())
22+
XCTAssertEqual(setting.settingID, "woocommerce_all_except_countries")
23+
XCTAssertTrue(setting.value.isEmpty)
24+
}
2125
}
2226

2327
private extension SiteSettingMapperTests {
@@ -37,4 +41,9 @@ private extension SiteSettingMapperTests {
3741
func mapLoadCouponSettingResponse() -> SiteSetting? {
3842
return mapSetting(from: "setting-coupon")
3943
}
44+
/// Returns the SiteSettingMapper output upon receiving `setting-all-except-countries`
45+
///
46+
func loadMultiselectValueSettingResponse() -> SiteSetting? {
47+
return mapSetting(from: "setting-all-except-countries")
48+
}
4049
}
Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
{
2+
"data": {
3+
"id": "woocommerce_all_except_countries",
4+
"label": "Sell to all countries, except for&hellip;",
5+
"description": "",
6+
"type": "multiselect",
7+
"default": "",
8+
"value": [],
9+
"options": {
10+
"AX": "&#197;land Islands",
11+
"AF": "Afghanistan",
12+
"AL": "Albania",
13+
"DZ": "Algeria",
14+
"AS": "American Samoa",
15+
"AD": "Andorra",
16+
"AO": "Angola",
17+
"AI": "Anguilla",
18+
"AQ": "Antarctica",
19+
"AG": "Antigua and Barbuda",
20+
"AR": "Argentina",
21+
"AM": "Armenia",
22+
"AW": "Aruba",
23+
"AU": "Australia",
24+
"AT": "Austria",
25+
"AZ": "Azerbaijan",
26+
"BS": "Bahamas",
27+
"BH": "Bahrain",
28+
"BD": "Bangladesh",
29+
"BB": "Barbados",
30+
"BY": "Belarus",
31+
"PW": "Belau",
32+
"BE": "Belgium",
33+
"BZ": "Belize",
34+
"BJ": "Benin",
35+
"BM": "Bermuda",
36+
"BT": "Bhutan",
37+
"BO": "Bolivia",
38+
"BQ": "Bonaire, Saint Eustatius and Saba",
39+
"BA": "Bosnia and Herzegovina",
40+
"BW": "Botswana",
41+
"BV": "Bouvet Island",
42+
"BR": "Brazil",
43+
"IO": "British Indian Ocean Territory",
44+
"VG": "British Virgin Islands",
45+
"BN": "Brunei",
46+
"BG": "Bulgaria",
47+
"BF": "Burkina Faso",
48+
"BI": "Burundi",
49+
"KH": "Cambodia",
50+
"CM": "Cameroon",
51+
"CA": "Canada",
52+
"CV": "Cape Verde",
53+
"KY": "Cayman Islands",
54+
"CF": "Central African Republic",
55+
"TD": "Chad",
56+
"CL": "Chile",
57+
"CN": "China",
58+
"CX": "Christmas Island",
59+
"CC": "Cocos (Keeling) Islands",
60+
"CO": "Colombia",
61+
"KM": "Comoros",
62+
"CG": "Congo (Brazzaville)",
63+
"CD": "Congo (Kinshasa)",
64+
"CK": "Cook Islands",
65+
"CR": "Costa Rica",
66+
"HR": "Croatia",
67+
"CU": "Cuba",
68+
"CW": "Cura&ccedil;ao",
69+
"CY": "Cyprus",
70+
"CZ": "Czech Republic",
71+
"DK": "Denmark",
72+
"DJ": "Djibouti",
73+
"DM": "Dominica",
74+
"DO": "Dominican Republic",
75+
"EC": "Ecuador",
76+
"EG": "Egypt",
77+
"SV": "El Salvador",
78+
"GQ": "Equatorial Guinea",
79+
"ER": "Eritrea",
80+
"EE": "Estonia",
81+
"ET": "Ethiopia",
82+
"FK": "Falkland Islands",
83+
"FO": "Faroe Islands",
84+
"FJ": "Fiji",
85+
"FI": "Finland",
86+
"FR": "France",
87+
"GF": "French Guiana",
88+
"PF": "French Polynesia",
89+
"TF": "French Southern Territories",
90+
"GA": "Gabon",
91+
"GM": "Gambia",
92+
"GE": "Georgia",
93+
"DE": "Germany",
94+
"GH": "Ghana",
95+
"GI": "Gibraltar",
96+
"GR": "Greece",
97+
"GL": "Greenland",
98+
"GD": "Grenada",
99+
"GP": "Guadeloupe",
100+
"GU": "Guam",
101+
"GT": "Guatemala",
102+
"GG": "Guernsey",
103+
"GN": "Guinea",
104+
"GW": "Guinea-Bissau",
105+
"GY": "Guyana",
106+
"HT": "Haiti",
107+
"HM": "Heard Island and McDonald Islands",
108+
"HN": "Honduras",
109+
"HK": "Hong Kong",
110+
"HU": "Hungary",
111+
"IS": "Iceland",
112+
"IN": "India",
113+
"ID": "Indonesia",
114+
"IR": "Iran",
115+
"IQ": "Iraq",
116+
"IE": "Ireland",
117+
"IM": "Isle of Man",
118+
"IL": "Israel",
119+
"IT": "Italy",
120+
"CI": "Ivory Coast",
121+
"JM": "Jamaica",
122+
"JP": "Japan",
123+
"JE": "Jersey",
124+
"JO": "Jordan",
125+
"KZ": "Kazakhstan",
126+
"KE": "Kenya",
127+
"KI": "Kiribati",
128+
"KW": "Kuwait",
129+
"KG": "Kyrgyzstan",
130+
"LA": "Laos",
131+
"LV": "Latvia",
132+
"LB": "Lebanon",
133+
"LS": "Lesotho",
134+
"LR": "Liberia",
135+
"LY": "Libya",
136+
"LI": "Liechtenstein",
137+
"LT": "Lithuania",
138+
"LU": "Luxembourg",
139+
"MO": "Macao S.A.R., China",
140+
"MK": "Macedonia",
141+
"MG": "Madagascar",
142+
"MW": "Malawi",
143+
"MY": "Malaysia",
144+
"MV": "Maldives",
145+
"ML": "Mali",
146+
"MT": "Malta",
147+
"MH": "Marshall Islands",
148+
"MQ": "Martinique",
149+
"MR": "Mauritania",
150+
"MU": "Mauritius",
151+
"YT": "Mayotte",
152+
"MX": "Mexico",
153+
"FM": "Micronesia",
154+
"MD": "Moldova",
155+
"MC": "Monaco",
156+
"MN": "Mongolia",
157+
"ME": "Montenegro",
158+
"MS": "Montserrat",
159+
"MA": "Morocco",
160+
"MZ": "Mozambique",
161+
"MM": "Myanmar",
162+
"NA": "Namibia",
163+
"NR": "Nauru",
164+
"NP": "Nepal",
165+
"NL": "Netherlands",
166+
"NC": "New Caledonia",
167+
"NZ": "New Zealand",
168+
"NI": "Nicaragua",
169+
"NE": "Niger",
170+
"NG": "Nigeria",
171+
"NU": "Niue",
172+
"NF": "Norfolk Island",
173+
"KP": "North Korea",
174+
"MP": "Northern Mariana Islands",
175+
"NO": "Norway",
176+
"OM": "Oman",
177+
"PK": "Pakistan",
178+
"PS": "Palestinian Territory",
179+
"PA": "Panama",
180+
"PG": "Papua New Guinea",
181+
"PY": "Paraguay",
182+
"PE": "Peru",
183+
"PH": "Philippines",
184+
"PN": "Pitcairn",
185+
"PL": "Poland",
186+
"PT": "Portugal",
187+
"PR": "Puerto Rico",
188+
"QA": "Qatar",
189+
"RE": "Reunion",
190+
"RO": "Romania",
191+
"RU": "Russia",
192+
"RW": "Rwanda",
193+
"ST": "S&atilde;o Tom&eacute; and Pr&iacute;ncipe",
194+
"BL": "Saint Barth&eacute;lemy",
195+
"SH": "Saint Helena",
196+
"KN": "Saint Kitts and Nevis",
197+
"LC": "Saint Lucia",
198+
"SX": "Saint Martin (Dutch part)",
199+
"MF": "Saint Martin (French part)",
200+
"PM": "Saint Pierre and Miquelon",
201+
"VC": "Saint Vincent and the Grenadines",
202+
"WS": "Samoa",
203+
"SM": "San Marino",
204+
"SA": "Saudi Arabia",
205+
"SN": "Senegal",
206+
"RS": "Serbia",
207+
"SC": "Seychelles",
208+
"SL": "Sierra Leone",
209+
"SG": "Singapore",
210+
"SK": "Slovakia",
211+
"SI": "Slovenia",
212+
"SB": "Solomon Islands",
213+
"SO": "Somalia",
214+
"ZA": "South Africa",
215+
"GS": "South Georgia/Sandwich Islands",
216+
"KR": "South Korea",
217+
"SS": "South Sudan",
218+
"ES": "Spain",
219+
"LK": "Sri Lanka",
220+
"SD": "Sudan",
221+
"SR": "Suriname",
222+
"SJ": "Svalbard and Jan Mayen",
223+
"SZ": "Swaziland",
224+
"SE": "Sweden",
225+
"CH": "Switzerland",
226+
"SY": "Syria",
227+
"TW": "Taiwan",
228+
"TJ": "Tajikistan",
229+
"TZ": "Tanzania",
230+
"TH": "Thailand",
231+
"TL": "Timor-Leste",
232+
"TG": "Togo",
233+
"TK": "Tokelau",
234+
"TO": "Tonga",
235+
"TT": "Trinidad and Tobago",
236+
"TN": "Tunisia",
237+
"TR": "Turkey",
238+
"TM": "Turkmenistan",
239+
"TC": "Turks and Caicos Islands",
240+
"TV": "Tuvalu",
241+
"UG": "Uganda",
242+
"UA": "Ukraine",
243+
"AE": "United Arab Emirates",
244+
"GB": "United Kingdom (UK)",
245+
"US": "United States (US)",
246+
"UM": "United States (US) Minor Outlying Islands",
247+
"VI": "United States (US) Virgin Islands",
248+
"UY": "Uruguay",
249+
"UZ": "Uzbekistan",
250+
"VU": "Vanuatu",
251+
"VA": "Vatican",
252+
"VE": "Venezuela",
253+
"VN": "Vietnam",
254+
"WF": "Wallis and Futuna",
255+
"EH": "Western Sahara",
256+
"YE": "Yemen",
257+
"ZM": "Zambia",
258+
"ZW": "Zimbabwe"
259+
},
260+
"_links": {
261+
"self": [
262+
{
263+
"href": "https://jamosova3.mystagingwebsite.com/wp-json/wc/v2/settings/general/woocommerce_all_except_countries"
264+
}
265+
],
266+
"collection": [
267+
{
268+
"href": "https://jamosova3.mystagingwebsite.com/wp-json/wc/v2/settings/general"
269+
}
270+
]
271+
}
272+
}
273+
}

0 commit comments

Comments
 (0)