Skip to content

Commit 7cb62da

Browse files
committed
Have the mapper return plugins with networkActivated as a proxy for activation
1 parent d297392 commit 7cb62da

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

Networking/Networking/Mapper/SystemStatusMapper.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@ struct SystemStatusMapper: Mapper {
1919

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

22-
return systemStatus.activePlugins + systemStatus.inactivePlugins
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 #xxxx
25+
let activePlugins = systemStatus.activePlugins.map {
26+
$0.overrideNetworkActivated(isNetworkActivated: true)
27+
}
28+
let inactivePlugins = systemStatus.inactivePlugins.map {
29+
$0.overrideNetworkActivated(isNetworkActivated: false)
30+
}
31+
32+
return activePlugins + inactivePlugins
2333
}
2434
}
2535

Networking/Networking/Model/SystemPlugin.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ public struct SystemPlugin: Decodable, GeneratedFakeable, GeneratedCopiable {
8888
}
8989
}
9090

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+
)
104+
}
105+
}
106+
91107
/// Defines all of the SystemPlugin CodingKeys.
92108
///
93109
private extension SystemPlugin {

Networking/NetworkingTests/Mapper/SystemStatusMapperTests.swift

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class SystemStatusMapperTests: XCTestCase {
99
///
1010
private let dummySiteID: Int64 = 999999
1111

12-
/// Verifies the SystemPlugin fields are parsed correctly.
12+
/// Verifies the SystemPlugin fields are parsed correctly for an active plugin
1313
///
14-
func test_SystemPlugin_fields_are_properly_parsed() throws {
14+
func test_active_plugin_fields_are_properly_parsed() throws {
1515
// Given
1616
let expectedSiteId: Int64 = 999999
1717
let expectedPlugin = "woocommerce/woocommerce.php"
@@ -21,7 +21,10 @@ class SystemStatusMapperTests: XCTestCase {
2121
let expectedVersionLatest = "5.8.0"
2222
let expectedAuthorName = "Automattic"
2323
let expectedAuthorUrl = "https://woocommerce.com"
24-
let expectedNetworkActivated = false
24+
/// TODO - The mapper is overriding networkActivated to be true for active plugins in general
25+
/// When we fix #xxxx 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
2528

2629
// When
2730
let systemPlugins = try mapLoadSystemStatusResponse()
@@ -41,6 +44,42 @@ class SystemStatusMapperTests: XCTestCase {
4144
XCTAssertEqual(systemPlugin.authorUrl, expectedAuthorUrl)
4245
XCTAssertEqual(systemPlugin.networkActivated, expectedNetworkActivated)
4346
}
47+
48+
/// Verifies the SystemPlugin fields are parsed correctly for an inactive plugin
49+
///
50+
func test_inactive_plugin_fields_are_properly_parsed() throws {
51+
// Given
52+
let expectedSiteId: Int64 = 999999
53+
let expectedPlugin = "hello.php"
54+
let expectedName = "Hello Dolly"
55+
let expectedUrl = "http://wordpress.org/plugins/hello-dolly/"
56+
let expectedVersion = "1.7.2"
57+
let expectedVersionLatest = "1.7.2"
58+
let expectedAuthorName = "Matt Mullenweg"
59+
let expectedAuthorUrl = "http://ma.tt/"
60+
/// TODO - The mapper is overriding networkActivated to be true for active plugins in general
61+
/// When we fix #xxxx this test will need to be updated to properly test the
62+
/// new `activated` attribute that will be added to SystemPlugin instead
63+
let expectedNetworkActivated = false
64+
65+
// When
66+
let systemPlugins = try mapLoadSystemStatusResponse()
67+
68+
// Then
69+
XCTAssertEqual(systemPlugins.count, 6)
70+
71+
let systemPlugin = systemPlugins[5]
72+
XCTAssertNotNil(systemPlugin)
73+
XCTAssertEqual(systemPlugin.siteID, expectedSiteId)
74+
XCTAssertEqual(systemPlugin.plugin, expectedPlugin)
75+
XCTAssertEqual(systemPlugin.name, expectedName)
76+
XCTAssertEqual(systemPlugin.url, expectedUrl)
77+
XCTAssertEqual(systemPlugin.version, expectedVersion)
78+
XCTAssertEqual(systemPlugin.versionLatest, expectedVersionLatest)
79+
XCTAssertEqual(systemPlugin.authorName, expectedAuthorName)
80+
XCTAssertEqual(systemPlugin.authorUrl, expectedAuthorUrl)
81+
XCTAssertEqual(systemPlugin.networkActivated, expectedNetworkActivated)
82+
}
4483
}
4584

4685
/// Private Methods.

0 commit comments

Comments
 (0)