Skip to content

Commit d297392

Browse files
committed
Have SystemStatusMapper return active and inactive plugins combined
1 parent 757cfa2 commit d297392

File tree

6 files changed

+51
-19
lines changed

6 files changed

+51
-19
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
31104E142630DDA700587C1E /* wcpay-account-wrong-json.json in Resources */ = {isa = PBXBuildFile; fileRef = 31104E132630DDA700587C1E /* wcpay-account-wrong-json.json */; };
143143
311976E02602BD4B006AC56C /* SitePluginsMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 311976DF2602BD4B006AC56C /* SitePluginsMapperTests.swift */; };
144144
314703082670222500EF253A /* PaymentGatewayAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 314703072670222500EF253A /* PaymentGatewayAccount.swift */; };
145+
3148977027232982007A86BD /* SystemStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3148976F27232982007A86BD /* SystemStatus.swift */; };
145146
3158FE6026129ADD00E566B9 /* wcpay-account-none.json in Resources */ = {isa = PBXBuildFile; fileRef = 3158FE5F26129ADD00E566B9 /* wcpay-account-none.json */; };
146147
3158FE6426129B1300E566B9 /* wcpay-account-complete.json in Resources */ = {isa = PBXBuildFile; fileRef = 3158FE6326129B1300E566B9 /* wcpay-account-complete.json */; };
147148
3158FE6826129CE200E566B9 /* wcpay-account-rejected-fraud.json in Resources */ = {isa = PBXBuildFile; fileRef = 3158FE6726129CE200E566B9 /* wcpay-account-rejected-fraud.json */; };
@@ -704,6 +705,7 @@
704705
31104E132630DDA700587C1E /* wcpay-account-wrong-json.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wcpay-account-wrong-json.json"; sourceTree = "<group>"; };
705706
311976DF2602BD4B006AC56C /* SitePluginsMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SitePluginsMapperTests.swift; sourceTree = "<group>"; };
706707
314703072670222500EF253A /* PaymentGatewayAccount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentGatewayAccount.swift; sourceTree = "<group>"; };
708+
3148976F27232982007A86BD /* SystemStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemStatus.swift; sourceTree = "<group>"; };
707709
3158FE5F26129ADD00E566B9 /* wcpay-account-none.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wcpay-account-none.json"; sourceTree = "<group>"; };
708710
3158FE6326129B1300E566B9 /* wcpay-account-complete.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wcpay-account-complete.json"; sourceTree = "<group>"; };
709711
3158FE6726129CE200E566B9 /* wcpay-account-rejected-fraud.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wcpay-account-rejected-fraud.json"; sourceTree = "<group>"; };
@@ -1545,6 +1547,8 @@
15451547
74046E1C217A6989007DD7BF /* SiteSetting.swift */,
15461548
74159624224D4045003C21CF /* SiteSettingGroup.swift */,
15471549
CE50345F21B5799F007573C6 /* SitePlan.swift */,
1550+
077F39C7269F2C7E00ABEADC /* SystemPlugin.swift */,
1551+
3148976F27232982007A86BD /* SystemStatus.swift */,
15481552
450106842399A7CB00E24722 /* TaxClass.swift */,
15491553
3192F21F260D33BB0067FEF9 /* WCPayAccount.swift */,
15501554
3192F223260D34C40067FEF9 /* WCPayAccountStatusEnum.swift */,
@@ -1553,7 +1557,6 @@
15531557
31054705262E278100C5C02B /* WCPayPaymentIntent.swift */,
15541558
3105470B262E27F000C5C02B /* WCPayPaymentIntentStatusEnum.swift */,
15551559
FE28F6E126840DED004465C7 /* User.swift */,
1556-
077F39C7269F2C7E00ABEADC /* SystemPlugin.swift */,
15571560
);
15581561
path = Model;
15591562
sourceTree = "<group>";
@@ -2478,6 +2481,7 @@
24782481
CE430676234BA7920073CBFF /* RefundListMapper.swift in Sources */,
24792482
45551F122523E7F1007EF104 /* UserAgent.swift in Sources */,
24802483
45CDAFAB2434CA9300F83C22 /* ProductCatalogVisibility.swift in Sources */,
2484+
3148977027232982007A86BD /* SystemStatus.swift in Sources */,
24812485
B557DA1820979D51005962F4 /* Credentials.swift in Sources */,
24822486
CE583A0E2109154500D73C1C /* OrderNoteMapper.swift in Sources */,
24832487
318E8FD526C31F9500F519D7 /* WCPayCustomer.swift in Sources */,

Networking/Networking/Mapper/SystemStatusMapper.swift

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,19 @@ struct SystemStatusMapper: Mapper {
1717
.siteID: siteID
1818
]
1919

20-
return try decoder.decode(SystemPluginsEnvelope.self, from: response).data.activePlugins
20+
let systemStatus = try decoder.decode(SystemStatusEnvelope.self, from: response).systemStatus
21+
22+
return systemStatus.activePlugins + systemStatus.inactivePlugins
2123
}
2224
}
2325

24-
/// SystemPluginsActivePluginsEnvelope Disposable Entity:
25-
/// The plugins endpoint returns the document within a `active_plugins` key. This entity
26-
/// allows us to do parse all the things with JSONDecoder.
26+
/// System Status endpoint returns the requested account in the `data` key. This entity
27+
/// allows us to parse it with JSONDecoder.
2728
///
28-
private struct SystemPluginsActivePluginsEnvelope: Decodable {
29-
30-
let activePlugins: [SystemPlugin]
29+
private struct SystemStatusEnvelope: Decodable {
30+
let systemStatus: SystemStatus
3131

3232
private enum CodingKeys: String, CodingKey {
33-
case activePlugins = "active_plugins"
33+
case systemStatus = "data"
3434
}
3535
}
36-
37-
/// SystemPluginsEnvelope Disposable Entity:
38-
/// The plugins endpoint returns the document within a `data` key. This entity
39-
/// allows us to do parse the object `SystemPluginsActivePluginsEnvelope`.
40-
///
41-
private struct SystemPluginsEnvelope: Decodable {
42-
let data: SystemPluginsActivePluginsEnvelope
43-
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/// Represent a System Status.
2+
/// Note: We are only decoding the active and inactive plugins portions at the moment.
3+
///
4+
public struct SystemStatus: Decodable {
5+
let activePlugins: [SystemPlugin]
6+
let inactivePlugins: [SystemPlugin]
7+
8+
public init(
9+
activePlugins: [SystemPlugin],
10+
inactivePlugins: [SystemPlugin]
11+
) {
12+
self.activePlugins = activePlugins
13+
self.inactivePlugins = inactivePlugins
14+
}
15+
16+
/// The public initializer for System Status.
17+
///
18+
public init(from decoder: Decoder) throws {
19+
let container = try decoder.container(keyedBy: CodingKeys.self)
20+
let activePlugins = try container.decode([SystemPlugin].self, forKey: .activePlugins)
21+
let inactivePlugins = try container.decode([SystemPlugin].self, forKey: .inactivePlugins)
22+
23+
self.init(
24+
activePlugins: activePlugins,
25+
inactivePlugins: inactivePlugins
26+
)
27+
}
28+
}
29+
30+
private extension SystemStatus {
31+
enum CodingKeys: String, CodingKey {
32+
case activePlugins = "active_plugins"
33+
case inactivePlugins = "inactive_plugins"
34+
}
35+
}

Networking/NetworkingTests/Mapper/SystemStatusMapperTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SystemStatusMapperTests: XCTestCase {
2727
let systemPlugins = try mapLoadSystemStatusResponse()
2828

2929
// Then
30-
XCTAssertEqual(systemPlugins.count, 4)
30+
XCTAssertEqual(systemPlugins.count, 6)
3131

3232
let systemPlugin = systemPlugins[0]
3333
XCTAssertNotNil(systemPlugin)

Networking/NetworkingTests/Remote/SystemStatusRemoteTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SystemStatusRemoteTests: XCTestCase {
3939
// Then
4040
switch result {
4141
case .success(let plugins):
42-
XCTAssertEqual(plugins.count, 3)
42+
XCTAssertEqual(plugins.count, 6)
4343
case .failure(let error):
4444
XCTAssertNil(error)
4545
}

Yosemite/Yosemite/Model/Model.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public typealias SiteVisitStats = Networking.SiteVisitStats
114114
public typealias SiteVisitStatsItem = Networking.SiteVisitStatsItem
115115
public typealias StateOfACountry = Networking.StateOfACountry
116116
public typealias SystemPlugin = Networking.SystemPlugin
117+
public typealias SystemStatus = Networking.SystemStatus
117118
public typealias TaxClass = Networking.TaxClass
118119
public typealias TopEarnerStats = Networking.TopEarnerStats
119120
public typealias TopEarnerStatsItem = Networking.TopEarnerStatsItem

0 commit comments

Comments
 (0)