Skip to content

Commit e67b78f

Browse files
authored
Merge pull request #5341 from woocommerce/issue/5269-systemplugin-active
[Mobile Payments] Use active (not networkActivated) to determine plugin activation state
2 parents 6fcc52d + 7bba37a commit e67b78f

File tree

9 files changed

+42
-42
lines changed

9 files changed

+42
-42
lines changed

Fakes/Fakes/Networking.generated.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,8 @@ extension SystemPlugin {
14571457
url: .fake(),
14581458
authorName: .fake(),
14591459
authorUrl: .fake(),
1460-
networkActivated: .fake()
1460+
networkActivated: .fake(),
1461+
active: .fake()
14611462
)
14621463
}
14631464
}

Networking/Networking/Mapper/SystemStatusMapper.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ struct SystemStatusMapper: Mapper {
1919

2020
let systemStatus = try decoder.decode(SystemStatusEnvelope.self, from: response).systemStatus
2121

22-
/// For now, we're going to override the networkActivated Bool in each plugin to convey active or inactive -- in order to
23-
/// avoid a core data change to add a Bool for activated
24-
/// This will be undone in #5269
22+
/// Active and in-active plugins share identical structure, but are stored in separate parts of the remote response
23+
/// (and without an active attribute in the response). So... we use the same decoder for active and in-active plugins
24+
/// and here we apply the correct value for active (or not)
25+
///
2526
let activePlugins = systemStatus.activePlugins.map {
26-
$0.overrideNetworkActivated(isNetworkActivated: true)
27+
$0.copy(active: true)
2728
}
29+
2830
let inactivePlugins = systemStatus.inactivePlugins.map {
29-
$0.overrideNetworkActivated(isNetworkActivated: false)
31+
$0.copy(active: false)
3032
}
3133

3234
return activePlugins + inactivePlugins

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,8 @@ extension SystemPlugin {
12621262
url: CopiableProp<String> = .copy,
12631263
authorName: CopiableProp<String> = .copy,
12641264
authorUrl: CopiableProp<String> = .copy,
1265-
networkActivated: CopiableProp<Bool> = .copy
1265+
networkActivated: CopiableProp<Bool> = .copy,
1266+
active: CopiableProp<Bool> = .copy
12661267
) -> SystemPlugin {
12671268
let siteID = siteID ?? self.siteID
12681269
let plugin = plugin ?? self.plugin
@@ -1273,6 +1274,7 @@ extension SystemPlugin {
12731274
let authorName = authorName ?? self.authorName
12741275
let authorUrl = authorUrl ?? self.authorUrl
12751276
let networkActivated = networkActivated ?? self.networkActivated
1277+
let active = active ?? self.active
12761278

12771279
return SystemPlugin(
12781280
siteID: siteID,
@@ -1283,7 +1285,8 @@ extension SystemPlugin {
12831285
url: url,
12841286
authorName: authorName,
12851287
authorUrl: authorUrl,
1286-
networkActivated: networkActivated
1288+
networkActivated: networkActivated,
1289+
active: active
12871290
)
12881291
}
12891292
}

Networking/Networking/Model/SystemPlugin.swift

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public struct SystemPlugin: Decodable, GeneratedFakeable, GeneratedCopiable {
3939
///
4040
public let networkActivated: Bool
4141

42+
/// Is the plugin active, i.e. false | true
43+
///
44+
public let active: Bool
45+
4246
/// Struct initializer.
4347
///
4448
public init(siteID: Int64,
@@ -49,7 +53,8 @@ public struct SystemPlugin: Decodable, GeneratedFakeable, GeneratedCopiable {
4953
url: String,
5054
authorName: String,
5155
authorUrl: String,
52-
networkActivated: Bool) {
56+
networkActivated: Bool,
57+
active: Bool) {
5358
self.siteID = siteID
5459
self.plugin = plugin
5560
self.name = name
@@ -59,6 +64,7 @@ public struct SystemPlugin: Decodable, GeneratedFakeable, GeneratedCopiable {
5964
self.authorName = authorName
6065
self.authorUrl = authorUrl
6166
self.networkActivated = networkActivated
67+
self.active = active
6268
}
6369
/// The public initializer for SystemPlugin.
6470
///
@@ -76,6 +82,12 @@ public struct SystemPlugin: Decodable, GeneratedFakeable, GeneratedCopiable {
7682
let authorUrl = try container.decode(String.self, forKey: .authorUrl)
7783
let networkActivated = try container.decode(Bool.self, forKey: .networkActivated)
7884

85+
/// Active and in-active plugins share identical structure, but are stored in separate parts of the remote response
86+
/// (and without an active attribute in the response). So... we use the same decoder for active and in-active plugins
87+
/// and in SystemStatusMapper we apply the correct value for active (which here is defaulted to true)
88+
///
89+
let active = true
90+
7991
self.init(siteID: siteID,
8092
plugin: plugin,
8193
name: name,
@@ -84,23 +96,8 @@ public struct SystemPlugin: Decodable, GeneratedFakeable, GeneratedCopiable {
8496
url: url,
8597
authorName: authorName,
8698
authorUrl: authorUrl,
87-
networkActivated: networkActivated)
88-
}
89-
}
90-
91-
extension SystemPlugin {
92-
func overrideNetworkActivated(isNetworkActivated: Bool) -> SystemPlugin {
93-
SystemPlugin(
94-
siteID: self.siteID,
95-
plugin: self.plugin,
96-
name: self.name,
97-
version: self.version,
98-
versionLatest: self.versionLatest,
99-
url: self.url,
100-
authorName: self.authorName,
101-
authorUrl: self.authorUrl,
102-
networkActivated: isNetworkActivated
103-
)
99+
networkActivated: networkActivated,
100+
active: active)
104101
}
105102
}
106103

Networking/NetworkingTests/Mapper/SystemStatusMapperTests.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ class SystemStatusMapperTests: XCTestCase {
2121
let expectedVersionLatest = "5.8.0"
2222
let expectedAuthorName = "Automattic"
2323
let expectedAuthorUrl = "https://woocommerce.com"
24-
/// TODO - The mapper is overriding networkActivated to be true for active plugins in general
25-
/// When we fix #5269 this test will need to be updated to properly test the
26-
/// new `activated` attribute that will be added to SystemPlugin instead
27-
let expectedNetworkActivated = true
24+
let expectedNetworkActivated = false
25+
let expectedActive = true
2826

2927
// When
3028
let systemPlugins = try mapLoadSystemStatusResponse()
@@ -43,6 +41,7 @@ class SystemStatusMapperTests: XCTestCase {
4341
XCTAssertEqual(systemPlugin.authorName, expectedAuthorName)
4442
XCTAssertEqual(systemPlugin.authorUrl, expectedAuthorUrl)
4543
XCTAssertEqual(systemPlugin.networkActivated, expectedNetworkActivated)
44+
XCTAssertEqual(systemPlugin.active, expectedActive)
4645
}
4746

4847
/// Verifies the SystemPlugin fields are parsed correctly for an inactive plugin
@@ -57,10 +56,8 @@ class SystemStatusMapperTests: XCTestCase {
5756
let expectedVersionLatest = "1.7.2"
5857
let expectedAuthorName = "Matt Mullenweg"
5958
let expectedAuthorUrl = "http://ma.tt/"
60-
/// TODO - The mapper is overriding networkActivated to be true for active plugins in general
61-
/// When we fix #5269 this test will need to be updated to properly test the
62-
/// new `activated` attribute that will be added to SystemPlugin instead
6359
let expectedNetworkActivated = false
60+
let expectedActive = false
6461

6562
// When
6663
let systemPlugins = try mapLoadSystemStatusResponse()
@@ -79,6 +76,7 @@ class SystemStatusMapperTests: XCTestCase {
7976
XCTAssertEqual(systemPlugin.authorName, expectedAuthorName)
8077
XCTAssertEqual(systemPlugin.authorUrl, expectedAuthorUrl)
8178
XCTAssertEqual(systemPlugin.networkActivated, expectedNetworkActivated)
79+
XCTAssertEqual(systemPlugin.active, expectedActive)
8280
}
8381
}
8482

WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/CardPresentPaymentsOnboardingUseCase.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ private extension CardPresentPaymentsOnboardingUseCase {
201201
}
202202

203203
func isWCPayActivated(plugin: SystemPlugin) -> Bool {
204-
// For now we are overriding networkActivated in SystemStatusMapper
205-
// to convey active / not active for a plugin.
206-
// TODO - replace with simply `activated` as part of #5269
207-
return plugin.networkActivated
204+
return plugin.active
208205
}
209206

210207
func getWCPayAccount() -> PaymentGatewayAccount? {

WooCommerce/WooCommerceTests/UnitTests.xctestplan

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"testTargets" : [
2828
{
2929
"skippedTests" : [
30-
"CardPresentPaymentsOnboardingUseCaseTests\/test_onboarding_returns_wcpay_not_activated_when_wcpay_installed_but_not_active()",
3130
"StripeCardReaderIntegrationTests"
3231
],
3332
"target" : {

WooCommerce/WooCommerceTests/ViewRelated/CardPresentPayments/CardPresentPaymentsOnboardingUseCaseTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class CardPresentPaymentsOnboardingUseCaseTests: XCTestCase {
6969

7070
}
7171

72-
// TODO: Unskip in #5269
7372
func test_onboarding_returns_wcpay_not_activated_when_wcpay_installed_but_not_active() {
7473
// Given
7574
setupCountry(country: .us)
@@ -359,15 +358,17 @@ private extension CardPresentPaymentsOnboardingUseCaseTests {
359358
// MARK: - Plugin helpers
360359
private extension CardPresentPaymentsOnboardingUseCaseTests {
361360
func setupPlugin(status: SitePluginStatusEnum, version: PluginVersion) {
361+
let active = status == .active || status == .networkActive
362+
let networkActivated = status == .networkActive
362363
let plugin = SystemPlugin
363364
.fake()
364365
.copy(
365366
siteID: sampleSiteID,
366367
plugin: "woocommerce-payments",
367-
// status: status, // TODO fix in #5269
368368
name: "WooCommerce Payments",
369369
version: version.rawValue,
370-
networkActivated: true // TODO remove in #5269
370+
networkActivated: networkActivated,
371+
active: active
371372
)
372373
storageManager.insertSampleSystemPlugin(readOnlySystemPlugin: plugin)
373374
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extension Storage.SystemPlugin: ReadOnlyConvertible {
1717
version = entity.version
1818
versionLatest = entity.versionLatest
1919
networkActivated = entity.networkActivated
20+
active = entity.active
2021
}
2122

2223
/// Returns a readonly version of the Storage.SystemPlugin
@@ -30,6 +31,7 @@ extension Storage.SystemPlugin: ReadOnlyConvertible {
3031
url: url,
3132
authorName: authorName,
3233
authorUrl: authorUrl,
33-
networkActivated: networkActivated)
34+
networkActivated: networkActivated,
35+
active: active)
3436
}
3537
}

0 commit comments

Comments
 (0)