Skip to content

Commit 7e97394

Browse files
authored
Merge pull request #5420 from woocommerce/feat/5364-site-jetpack-properties
Jetpack CP site detection: add `isJetpackConnected` and `isJetpackThePluginInstalled` attributes to `Networking.Site`
2 parents 018b01e + 37832ec commit 7e97394

File tree

9 files changed

+51
-13
lines changed

9 files changed

+51
-13
lines changed

Fakes/Fakes/Networking.generated.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,8 @@ extension Site {
13141314
description: .fake(),
13151315
url: .fake(),
13161316
plan: .fake(),
1317+
isJetpackThePluginInstalled: .fake(),
1318+
isJetpackConnected: .fake(),
13171319
isWooCommerceActive: .fake(),
13181320
isWordPressStore: .fake(),
13191321
timezone: .fake(),

Networking/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,8 @@ extension Site {
11511151
description: CopiableProp<String> = .copy,
11521152
url: CopiableProp<String> = .copy,
11531153
plan: CopiableProp<String> = .copy,
1154+
isJetpackThePluginInstalled: CopiableProp<Bool> = .copy,
1155+
isJetpackConnected: CopiableProp<Bool> = .copy,
11541156
isWooCommerceActive: CopiableProp<Bool> = .copy,
11551157
isWordPressStore: CopiableProp<Bool> = .copy,
11561158
timezone: CopiableProp<String> = .copy,
@@ -1161,6 +1163,8 @@ extension Site {
11611163
let description = description ?? self.description
11621164
let url = url ?? self.url
11631165
let plan = plan ?? self.plan
1166+
let isJetpackThePluginInstalled = isJetpackThePluginInstalled ?? self.isJetpackThePluginInstalled
1167+
let isJetpackConnected = isJetpackConnected ?? self.isJetpackConnected
11641168
let isWooCommerceActive = isWooCommerceActive ?? self.isWooCommerceActive
11651169
let isWordPressStore = isWordPressStore ?? self.isWordPressStore
11661170
let timezone = timezone ?? self.timezone
@@ -1172,6 +1176,8 @@ extension Site {
11721176
description: description,
11731177
url: url,
11741178
plan: plan,
1179+
isJetpackThePluginInstalled: isJetpackThePluginInstalled,
1180+
isJetpackConnected: isJetpackConnected,
11751181
isWooCommerceActive: isWooCommerceActive,
11761182
isWordPressStore: isWordPressStore,
11771183
timezone: timezone,

Networking/Networking/Model/Site.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ public struct Site: Decodable, Equatable, GeneratedFakeable, GeneratedCopiable {
2525
///
2626
public let plan: String
2727

28+
/// Whether the site has Jetpack-the-plugin installed.
29+
///
30+
public let isJetpackThePluginInstalled: Bool
31+
32+
/// Whether the site is connected to Jetpack, either through Jetpack-the-plugin or other plugins that include Jetpack Connection Package.
33+
///
34+
public let isJetpackConnected: Bool
35+
2836
/// Indicates if there is a WooCommerce Store Active.
2937
///
3038
public let isWooCommerceActive: Bool
@@ -50,6 +58,8 @@ public struct Site: Decodable, Equatable, GeneratedFakeable, GeneratedCopiable {
5058
let name = try siteContainer.decode(String.self, forKey: .name)
5159
let description = try siteContainer.decode(String.self, forKey: .description)
5260
let url = try siteContainer.decode(String.self, forKey: .url)
61+
let isJetpackThePluginInstalled = try siteContainer.decode(Bool.self, forKey: .isJetpackThePluginInstalled)
62+
let isJetpackConnected = try siteContainer.decode(Bool.self, forKey: .isJetpackConnected)
5363

5464
let optionsContainer = try siteContainer.nestedContainer(keyedBy: OptionKeys.self, forKey: .options)
5565
let isWordPressStore = try optionsContainer.decode(Bool.self, forKey: .isWordPressStore)
@@ -62,6 +72,8 @@ public struct Site: Decodable, Equatable, GeneratedFakeable, GeneratedCopiable {
6272
description: description,
6373
url: url,
6474
plan: String(), // Not created on init. Added in supplementary API request.
75+
isJetpackThePluginInstalled: isJetpackThePluginInstalled,
76+
isJetpackConnected: isJetpackConnected,
6577
isWooCommerceActive: isWooCommerceActive,
6678
isWordPressStore: isWordPressStore,
6779
timezone: timezone,
@@ -75,6 +87,8 @@ public struct Site: Decodable, Equatable, GeneratedFakeable, GeneratedCopiable {
7587
description: String,
7688
url: String,
7789
plan: String,
90+
isJetpackThePluginInstalled: Bool,
91+
isJetpackConnected: Bool,
7892
isWooCommerceActive: Bool,
7993
isWordPressStore: Bool,
8094
timezone: String,
@@ -84,13 +98,22 @@ public struct Site: Decodable, Equatable, GeneratedFakeable, GeneratedCopiable {
8498
self.description = description
8599
self.url = url
86100
self.plan = plan
101+
self.isJetpackThePluginInstalled = isJetpackThePluginInstalled
102+
self.isJetpackConnected = isJetpackConnected
87103
self.isWordPressStore = isWordPressStore
88104
self.isWooCommerceActive = isWooCommerceActive
89105
self.timezone = timezone
90106
self.gmtOffset = gmtOffset
91107
}
92108
}
93109

110+
public extension Site {
111+
/// Whether the site is connected to Jetpack with Jetpack Connection Package, and not with Jetpack-the-plugin.
112+
///
113+
var isJetpackCPConnected: Bool {
114+
isJetpackConnected && !isJetpackThePluginInstalled
115+
}
116+
}
94117

95118
/// Defines all of the Site CodingKeys.
96119
///
@@ -103,6 +126,8 @@ private extension Site {
103126
case url = "URL"
104127
case options = "options"
105128
case plan = "plan"
129+
case isJetpackThePluginInstalled = "jetpack"
130+
case isJetpackConnected = "jetpack_connection"
106131
}
107132

108133
enum OptionKeys: String, CodingKey {

Networking/Networking/Remote/AccountRemote.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class AccountRemote: Remote {
5353
public func loadSites(completion: @escaping (Result<[Site], Error>) -> Void) {
5454
let path = "me/sites"
5555
let parameters = [
56-
"fields": "ID,name,description,URL,options",
56+
"fields": "ID,name,description,URL,options,jetpack,jetpack_connection",
5757
"options": "timezone,is_wpcom_store,woocommerce_is_active,gmt_offset"
5858
]
5959

Networking/NetworkingTests/Responses/sites-malformed.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"description": "Testing Tagline",
77
"URL": "https:\/\/some-testing-url.testing.blog",
88
"jetpack": true,
9+
"jetpack_connection": true,
910
"updates": {
1011
"plugins": 3,
1112
"themes": 1,
@@ -20,6 +21,7 @@
2021
"description": "Your Favorite Blog",
2122
"URL": "https:\/\/thoughts.testing.blog",
2223
"jetpack": false,
24+
"jetpack_connection": true,
2325
"options": {
2426
"timezone": "",
2527
"gmt_offset": -4,

Networking/NetworkingTests/Responses/sites.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"description": "Testing Tagline",
77
"URL": "https:\/\/some-testing-url.testing.blog",
88
"jetpack": true,
9+
"jetpack_connection": true,
910
"options": {
1011
"timezone": "",
1112
"gmt_offset": 3.5,
@@ -144,6 +145,7 @@
144145
"description": "Your Favorite Blog",
145146
"URL": "https:\/\/thoughts.testing.blog",
146147
"jetpack": false,
148+
"jetpack_connection": true,
147149
"options": {
148150
"timezone": "",
149151
"gmt_offset": -4,

Yosemite/Yosemite/Model/Mocks/Graphs/ScreenshotsObjectGraph.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ struct ScreenshotObjectGraph: MockObjectGraph {
3636
description: "",
3737
url: i18n.DefaultSite.url,
3838
plan: "",
39+
isJetpackThePluginInstalled: true,
40+
isJetpackConnected: true,
3941
isWooCommerceActive: true,
4042
isWordPressStore: true,
4143
timezone: "UTC",

Yosemite/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ extension Storage.Site: ReadOnlyConvertible {
1414
tagline = site.description
1515
url = site.url
1616
// plan = site.plan // We're not assigning the plan here because it's not sent on the intial API request.
17+
// TODO: 5364 - update `isJetpackThePluginInstalled`
18+
// TODO: 5364 - update `isJetpackConnected`
1719
isWooCommerceActive = NSNumber(booleanLiteral: site.isWooCommerceActive)
1820
isWordPressStore = NSNumber(booleanLiteral: site.isWordPressStore)
1921
timezone = site.timezone
@@ -28,6 +30,8 @@ extension Storage.Site: ReadOnlyConvertible {
2830
description: tagline ?? "",
2931
url: url ?? "",
3032
plan: plan ?? "",
33+
isJetpackThePluginInstalled: true, // TODO: 5364 - persist in storage
34+
isJetpackConnected: true, // TODO: 5364 - persist in storage
3135
isWooCommerceActive: isWooCommerceActive?.boolValue ?? false,
3236
isWordPressStore: isWordPressStore?.boolValue ?? false,
3337
timezone: timezone ?? "",

Yosemite/YosemiteTests/Stores/AccountStoreTests.swift

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,20 @@ final class AccountStoreTests: XCTestCase {
351351
let accountStore = AccountStore(dispatcher: dispatcher, storageManager: storageManager, network: network)
352352
XCTAssertEqual(viewStorage.countObjects(ofType: Storage.Site.self), 0)
353353

354+
let siteID = Int64(999)
355+
// TODO: 5364 - remove `isJetpackThePluginInstalled` and `isJetpackConnected` once they are updated in `Site+ReadOnlyConvertible`
356+
let sampleSite = sampleSitePristine().copy(siteID: siteID, isJetpackThePluginInstalled: true, isJetpackConnected: true)
354357
let group = DispatchGroup()
355358
group.enter()
356-
accountStore.upsertStoredSitesInBackground(readOnlySites: [sampleSitePristine()]) {
359+
accountStore.upsertStoredSitesInBackground(readOnlySites: [sampleSite]) {
357360
XCTAssertEqual(self.viewStorage.countObjects(ofType: Storage.Site.self), 1)
358361
group.leave()
359362
}
360363

361364
// When
362365
let result: Result<Yosemite.Site, Error> = waitFor { promise in
363366
group.notify(queue: .main) {
364-
let action = AccountAction.loadAndSynchronizeSiteIfNeeded(siteID: 999) { result in
367+
let action = AccountAction.loadAndSynchronizeSiteIfNeeded(siteID: siteID) { result in
365368
XCTAssertTrue(Thread.isMainThread)
366369
promise(result)
367370
}
@@ -371,7 +374,7 @@ final class AccountStoreTests: XCTestCase {
371374

372375
// Then
373376
let site = try XCTUnwrap(result.get())
374-
XCTAssertEqual(site, sampleSitePristine())
377+
XCTAssertEqual(site, sampleSite)
375378
XCTAssertEqual(network.requestsForResponseData.count, 0)
376379
}
377380

@@ -485,14 +488,6 @@ private extension AccountStoreTests {
485488
/// Sample Site
486489
///
487490
func sampleSitePristine() -> Networking.Site {
488-
return Site(siteID: 999,
489-
name: "Awesome Test Site",
490-
description: "Best description ever!",
491-
url: "automattic.com",
492-
plan: String(),
493-
isWooCommerceActive: true,
494-
isWordPressStore: false,
495-
timezone: "Asia/Taipei",
496-
gmtOffset: 0)
491+
return Site.fake()
497492
}
498493
}

0 commit comments

Comments
 (0)