Skip to content

Commit e32fd13

Browse files
committed
New LoadSites Unit Tests
1 parent 394a320 commit e32fd13

File tree

2 files changed

+251
-1
lines changed

2 files changed

+251
-1
lines changed

Networking/NetworkingTests/Mapper/AccountMapperTests.swift

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ class AccountMapperTests: XCTestCase {
2020
XCTAssertEqual(account.userID, 78972699)
2121
XCTAssertEqual(account.username, "apiexamples")
2222
}
23+
24+
/// Verifies that all of the Site fields are properly parsed.
25+
///
26+
func testSiteFieldsAreProperlyParsed() {
27+
let sites = mapLoadSitesResponse()
28+
XCTAssert(sites?.count == 2)
29+
30+
let first = sites!.first!
31+
XCTAssertEqual(first.siteID, 1112233334444555)
32+
XCTAssertEqual(first.name, "Testing Blog")
33+
XCTAssertEqual(first.description, "Testing Tagline")
34+
XCTAssertEqual(first.url, "https://some-testing-url.testing.blog")
35+
XCTAssertEqual(first.isWordPressStore, true)
36+
37+
let second = sites!.last!
38+
XCTAssertEqual(second.siteID, 11122333344446666)
39+
XCTAssertEqual(second.name, "Thoughts")
40+
XCTAssertEqual(second.description, "Your Favorite Blog")
41+
XCTAssertEqual(second.url, "https://thoughts.testing.blog")
42+
XCTAssertEqual(second.isWordPressStore, false)
43+
}
2344
}
2445

2546

@@ -28,7 +49,7 @@ class AccountMapperTests: XCTestCase {
2849
//
2950
private extension AccountMapperTests {
3051

31-
/// Returns the AccountMapper output upon receiving `me` (Data Encoded)
52+
/// Returns the AccountMapper output upon receiving `me` mockup response (Data Encoded).
3253
///
3354
func mapLoadAccountResponse() -> Account? {
3455
guard let response = Loader.contentsOf("me") else {
@@ -37,4 +58,14 @@ private extension AccountMapperTests {
3758

3859
return try? AccountMapper().map(response: response)
3960
}
61+
62+
/// Returns the SiteListMapper output upon receiving `me/sites` mockup response (Data Encoded).
63+
///
64+
func mapLoadSitesResponse() -> [Site]? {
65+
guard let response = Loader.contentsOf("sites") else {
66+
return nil
67+
}
68+
69+
return try? SiteListMapper().map(response: response)
70+
}
4071
}
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
{
2+
"sites": [
3+
{
4+
"ID": 1112233334444555,
5+
"name": "Testing Blog",
6+
"description": "Testing Tagline",
7+
"URL": "https:\/\/some-testing-url.testing.blog",
8+
"options": {
9+
"timezone": "",
10+
"gmt_offset": 0,
11+
"blog_public": 1,
12+
"videopress_enabled": false,
13+
"upgraded_filetypes_enabled": true,
14+
"login_url": "https:\/\/some-testing-url.here\/wp-login.php",
15+
"admin_url": "https:\/\/some-testing-url.here\/wp-admin\/",
16+
"is_mapped_domain": true,
17+
"is_redirect": false,
18+
"unmapped_url": "https:\/\/some-testing-url.here",
19+
"featured_images_enabled": false,
20+
"theme_slug": "storefront",
21+
"header_image": false,
22+
"background_color": false,
23+
"image_default_link_type": "file",
24+
"image_thumbnail_width": 150,
25+
"image_thumbnail_height": 150,
26+
"image_thumbnail_crop": 0,
27+
"image_medium_width": 300,
28+
"image_medium_height": 300,
29+
"image_large_width": 1024,
30+
"image_large_height": 1024,
31+
"permalink_structure": "\/%year%\/%monthnum%\/%day%\/%postname%\/",
32+
"post_formats": [],
33+
"default_post_format": "0",
34+
"default_category": 12,
35+
"allowed_file_types": [
36+
"jpg",
37+
"jpeg",
38+
"png",
39+
"gif",
40+
"pdf",
41+
"doc",
42+
"ppt",
43+
"odt",
44+
"pptx",
45+
"docx",
46+
"pps",
47+
"ppsx",
48+
"xls",
49+
"xlsx",
50+
"key",
51+
"ogv",
52+
"mp4",
53+
"m4v",
54+
"mov",
55+
"wmv",
56+
"avi",
57+
"mpg",
58+
"3gp",
59+
"3g2"
60+
],
61+
"show_on_front": "page",
62+
"default_likes_enabled": true,
63+
"default_sharing_status": true,
64+
"default_comment_status": true,
65+
"default_ping_status": true,
66+
"software_version": "4.9.6",
67+
"created_at": "2014-03-28T15:03:03+00:00",
68+
"wordads": false,
69+
"publicize_permanently_disabled": false,
70+
"frame_nonce": "73ae7163d8",
71+
"page_on_front": 1455,
72+
"page_for_posts": 0,
73+
"headstart": false,
74+
"headstart_is_fresh": false,
75+
"ak_vp_bundle_enabled": false,
76+
"advanced_seo_front_page_description": "",
77+
"advanced_seo_title_formats": [],
78+
"verification_services_codes": null,
79+
"podcasting_archive": null,
80+
"is_domain_only": false,
81+
"is_automated_transfer": true,
82+
"is_wpcom_store": true,
83+
"woocommerce_is_active": true,
84+
"design_type": null,
85+
"site_goals": null,
86+
"jetpack_version": "6.2.1",
87+
"main_network_site": "https:\/\/some-testing-url.here",
88+
"active_modules": [
89+
"after-the-deadline",
90+
"contact-form",
91+
"custom-content-types",
92+
"custom-css",
93+
"enhanced-distribution",
94+
"gravatar-hovercards",
95+
"json-api",
96+
"latex",
97+
"manage",
98+
"notes",
99+
"post-by-email",
100+
"protect",
101+
"publicize",
102+
"sharedaddy",
103+
"shortcodes",
104+
"shortlinks",
105+
"sitemaps",
106+
"stats",
107+
"subscriptions",
108+
"verification-tools",
109+
"widget-visibility",
110+
"widgets",
111+
"sso",
112+
"tiled-gallery",
113+
"likes",
114+
"comments",
115+
"comment-likes",
116+
"videopress",
117+
"carousel",
118+
"photon",
119+
"seo-tools",
120+
"google-analytics",
121+
"infinite-scroll",
122+
"masterbar",
123+
"vaultpress"
124+
],
125+
"max_upload_size": false,
126+
"wp_memory_limit": "268435456",
127+
"wp_max_memory_limit": "268435456",
128+
"is_multi_network": false,
129+
"is_multi_site": false,
130+
"file_mod_disabled": false
131+
},
132+
"updates": {
133+
"plugins": 3,
134+
"themes": 1,
135+
"wordpress": 0,
136+
"translations": 0,
137+
"total": 4
138+
}
139+
},
140+
{
141+
"ID": 11122333344446666,
142+
"name": "Thoughts",
143+
"description": "Your Favorite Blog",
144+
"URL": "https:\/\/thoughts.testing.blog",
145+
"options": {
146+
"timezone": "",
147+
"gmt_offset": 0,
148+
"blog_public": 1,
149+
"videopress_enabled": false,
150+
"upgraded_filetypes_enabled": false,
151+
"login_url": "https:\/\/thoughts.testing.blog\/wp-login.php",
152+
"admin_url": "https:\/\/thoughts.testing.blog\/wp-admin\/",
153+
"is_mapped_domain": false,
154+
"is_redirect": false,
155+
"unmapped_url": "https:\/\/thoughts.testing.blog",
156+
"featured_images_enabled": false,
157+
"theme_slug": "pub\/p2-breathe",
158+
"header_image": {
159+
"thumbnail_url": "https:\/\/thoughts.testing.blog\/2016\/07\/blur.jpg?resize=520,108.33333333333",
160+
"url": "https:\/\/thoughts.testing.blog\/2016\/07\/blur.jpg?resize=1200,250",
161+
"description": "Blurred Lights"
162+
},
163+
"background_color": "2b2b2b",
164+
"image_default_link_type": "file",
165+
"image_thumbnail_width": 150,
166+
"image_thumbnail_height": 150,
167+
"image_thumbnail_crop": 0,
168+
"image_medium_width": 300,
169+
"image_medium_height": 300,
170+
"image_large_width": 1024,
171+
"image_large_height": 1024,
172+
"permalink_structure": "\/%year%\/%monthnum%\/%day%\/%postname%\/",
173+
"post_formats": [],
174+
"default_post_format": "standard",
175+
"default_category": 1,
176+
"allowed_file_types": [
177+
"jpg",
178+
"jpeg",
179+
"png",
180+
"gif",
181+
"pdf",
182+
"doc",
183+
"ppt",
184+
"odt",
185+
"pptx",
186+
"docx",
187+
"pps",
188+
"ppsx",
189+
"xls",
190+
"xlsx",
191+
"key"
192+
],
193+
"show_on_front": "posts",
194+
"default_likes_enabled": true,
195+
"default_sharing_status": false,
196+
"default_comment_status": true,
197+
"default_ping_status": true,
198+
"software_version": "4.9.7-alpha-43298",
199+
"created_at": "2013-08-05T16:39:48+00:00",
200+
"wordads": false,
201+
"publicize_permanently_disabled": false,
202+
"frame_nonce": "e7bfd785f0",
203+
"headstart": false,
204+
"headstart_is_fresh": false,
205+
"ak_vp_bundle_enabled": null,
206+
"advanced_seo_front_page_description": "",
207+
"advanced_seo_title_formats": [],
208+
"verification_services_codes": null,
209+
"podcasting_archive": null,
210+
"is_domain_only": false,
211+
"is_automated_transfer": false,
212+
"is_wpcom_store": false,
213+
"woocommerce_is_active": false,
214+
"design_type": null,
215+
"site_goals": null
216+
}
217+
}
218+
]
219+
}

0 commit comments

Comments
 (0)