Skip to content

Commit 30006b7

Browse files
committed
AccountStoreTests: New synchronizeSites Action Tests
1 parent a476c59 commit 30006b7

File tree

5 files changed

+264
-5
lines changed

5 files changed

+264
-5
lines changed

Storage/Storage/Model/Site+CoreDataProperties.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ extension Site {
1212
@NSManaged public var name: String?
1313
@NSManaged public var tagline: String?
1414
@NSManaged public var url: String?
15-
@NSManaged public var isWordPressStore: Bool
15+
@NSManaged public var isWordPressStore: NSNumber?
1616
}

Yosemite/Yosemite.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
B5B19DE020E6A45900899568 /* Storage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5B19DDF20E6A45900899568 /* Storage.framework */; };
2525
B5B19DE220E6A45E00899568 /* Networking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5B19DE120E6A45E00899568 /* Networking.framework */; };
2626
B5B5C797208E49B600642956 /* Action+Internal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5B5C796208E49B600642956 /* Action+Internal.swift */; };
27+
B5B914C220EFE03200F2F832 /* sites.json in Resources */ = {isa = PBXBuildFile; fileRef = B5B914C120EFE03200F2F832 /* sites.json */; };
2728
B5BC736520D1A98500B5B6FA /* AccountStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BC736420D1A98500B5B6FA /* AccountStore.swift */; };
2829
B5BC736820D1AA8F00B5B6FA /* AccountStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BC736720D1AA8F00B5B6FA /* AccountStoreTests.swift */; };
2930
B5BC736B20D1AAE900B5B6FA /* me.json in Resources */ = {isa = PBXBuildFile; fileRef = B5BC736A20D1AAE900B5B6FA /* me.json */; };
@@ -74,6 +75,7 @@
7475
B5B19DDF20E6A45900899568 /* Storage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Storage.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7576
B5B19DE120E6A45E00899568 /* Networking.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Networking.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7677
B5B5C796208E49B600642956 /* Action+Internal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Action+Internal.swift"; sourceTree = "<group>"; };
78+
B5B914C120EFE03200F2F832 /* sites.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = sites.json; sourceTree = "<group>"; };
7779
B5BC736420D1A98500B5B6FA /* AccountStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountStore.swift; sourceTree = "<group>"; };
7880
B5BC736720D1AA8F00B5B6FA /* AccountStoreTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountStoreTests.swift; sourceTree = "<group>"; };
7981
B5BC736A20D1AAE900B5B6FA /* me.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = me.json; sourceTree = "<group>"; };
@@ -160,10 +162,11 @@
160162
B5BC736920D1AAE900B5B6FA /* Resources */ = {
161163
isa = PBXGroup;
162164
children = (
165+
745D21C120D8043A00BBE7C3 /* generic_error.json */,
163166
B5BC736A20D1AAE900B5B6FA /* me.json */,
164167
74A7689120D47F9E00F9D437 /* orders.json */,
165168
7424B49320EAD37C00CC62F6 /* order.json */,
166-
745D21C120D8043A00BBE7C3 /* generic_error.json */,
169+
B5B914C120EFE03200F2F832 /* sites.json */,
167170
);
168171
path = Resources;
169172
sourceTree = "<group>";
@@ -405,6 +408,7 @@
405408
files = (
406409
74A7689220D47F9E00F9D437 /* orders.json in Resources */,
407410
B5BC736B20D1AAE900B5B6FA /* me.json in Resources */,
411+
B5B914C220EFE03200F2F832 /* sites.json in Resources */,
408412
7424B49420EAD37C00CC62F6 /* order.json in Resources */,
409413
);
410414
runOnlyForDeploymentPostprocessing = 0;

Yosemite/Yosemite/Model/Site+ReadOnlyConvertible.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension Storage.Site: ReadOnlyConvertible {
1313
name = site.name
1414
tagline = site.description
1515
url = site.url
16-
isWordPressStore = site.isWordPressStore
16+
isWordPressStore = NSNumber(booleanLiteral: site.isWordPressStore)
1717
}
1818

1919
/// Returns a ReadOnly version of the receiver.
@@ -23,6 +23,6 @@ extension Storage.Site: ReadOnlyConvertible {
2323
name: name ?? "",
2424
description: tagline ?? "",
2525
url: url ?? "",
26-
isWordPressStore: isWordPressStore)
26+
isWordPressStore: isWordPressStore?.boolValue ?? false)
2727
}
2828
}
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+
}

Yosemite/YosemiteTests/Stores/AccountStoreTests.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class AccountStoreTests: XCTestCase {
7878

7979
/// Verifies that AccountAction.synchronizeAccount effectively inserts a new Default Account.
8080
///
81-
func testSynchronizeAccountreturnsExpectedAccountDetails() {
81+
func testSynchronizeAccountReturnsExpectedAccountDetails() {
8282
let accountStore = AccountStore(dispatcher: dispatcher, storageManager: storageManager, network: network)
8383
let expectation = self.expectation(description: "Synchronize")
8484

@@ -128,6 +128,42 @@ class AccountStoreTests: XCTestCase {
128128
let storageAccount = viewStorage.loadAccount(userId: remoteAccount.userID)!
129129
compare(storageAccount: storageAccount, remoteAccount: remoteAccount)
130130
}
131+
132+
/// Verifies that `synchronizeSites` returns an error, whenever there is no backend reply.
133+
///
134+
func testSynchronizeSitesReturnsErrorOnEmptyResponse() {
135+
let accountStore = AccountStore(dispatcher: dispatcher, storageManager: storageManager, network: network)
136+
let expectation = self.expectation(description: "Synchronize")
137+
138+
let action = AccountAction.synchronizeSites { error in
139+
XCTAssertNotNil(error)
140+
expectation.fulfill()
141+
}
142+
143+
accountStore.onAction(action)
144+
145+
wait(for: [expectation], timeout: Constants.expectationTimeout)
146+
}
147+
148+
/// Verifies that `synchronizeSites` effectively persists any retrieved sites.
149+
///
150+
func testSynchronizeSitesEffectivelyPersistsRetrievedSites() {
151+
let accountStore = AccountStore(dispatcher: dispatcher, storageManager: storageManager, network: network)
152+
let expectation = self.expectation(description: "Synchronize")
153+
154+
network.simulateResponse(requestUrlSuffix: "me/sites", filename: "sites")
155+
XCTAssertEqual(viewStorage.countObjects(ofType: Storage.Site.self), 0)
156+
157+
let action = AccountAction.synchronizeSites { error in
158+
XCTAssertEqual(self.viewStorage.countObjects(ofType: Storage.Site.self), 2)
159+
XCTAssertNil(error)
160+
expectation.fulfill()
161+
}
162+
163+
accountStore.onAction(action)
164+
165+
wait(for: [expectation], timeout: Constants.expectationTimeout)
166+
}
131167
}
132168

133169

0 commit comments

Comments
 (0)