Skip to content

Commit 632d597

Browse files
committed
Update test for SitePluginsMapper
1 parent a27d7dd commit 632d597

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@
728728
DE66C5632977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */; };
729729
DE66C5652977CC4300DAA978 /* shipping-label-purchase-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */; };
730730
DE66C5672977CEB800DAA978 /* shipping-label-status-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */; };
731+
DE66C5692977D62700DAA978 /* plugins-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5682977D62700DAA978 /* plugins-without-data.json */; };
731732
DE6F308727966FEF004E1C9A /* CouponReportListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */; };
732733
DE74F29A27E08F5A0002FE59 /* SiteSettingMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */; };
733734
DE74F29C27E0A1D00002FE59 /* setting-coupon.json in Resources */ = {isa = PBXBuildFile; fileRef = DE74F29B27E0A1D00002FE59 /* setting-coupon.json */; };
@@ -1569,6 +1570,7 @@
15691570
DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-eligibility-failure-without-data.json"; sourceTree = "<group>"; };
15701571
DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-purchase-success-without-data.json"; sourceTree = "<group>"; };
15711572
DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-status-success-without-data.json"; sourceTree = "<group>"; };
1573+
DE66C5682977D62700DAA978 /* plugins-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "plugins-without-data.json"; sourceTree = "<group>"; };
15721574
DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponReportListMapperTests.swift; sourceTree = "<group>"; };
15731575
DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteSettingMapper.swift; sourceTree = "<group>"; };
15741576
DE74F29B27E0A1D00002FE59 /* setting-coupon.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "setting-coupon.json"; sourceTree = "<group>"; };
@@ -2188,6 +2190,7 @@
21882190
B559EBA820A0B5B100836CD4 /* Responses */ = {
21892191
isa = PBXGroup;
21902192
children = (
2193+
DE66C5682977D62700DAA978 /* plugins-without-data.json */,
21912194
DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */,
21922195
DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */,
21932196
DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */,
@@ -3171,6 +3174,7 @@
31713174
03E8FEC427B40E3F00F5FC7D /* wcpay-charge-card-present-minimal.json in Resources */,
31723175
EE6FDCFC2966A70400E1CECF /* product-without-data.json in Resources */,
31733176
31054724262E2FC600C5C02B /* wcpay-payment-intent-requires-capture.json in Resources */,
3177+
DE66C5692977D62700DAA978 /* plugins-without-data.json in Resources */,
31743178
7492FAE3217FBDBC00ED2C69 /* settings-general-alt.json in Resources */,
31753179
93D8BBFF226BC1DA00AD2EB3 /* me-settings.json in Resources */,
31763180
74C947842193A6C70024CB60 /* comment-moderate-approved.json in Resources */,

Networking/NetworkingTests/Mapper/SitePluginsMapperTests.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,37 @@ class SitePluginsMapperTests: XCTestCase {
3939
XCTAssertEqual(wooCommerceSubscriptionsPlugin.version, "3.0.13")
4040
XCTAssertEqual(wooCommerceSubscriptionsPlugin.textDomain, "woocommerce-subscriptions")
4141
}
42+
43+
/// Verifies the SitePlugin fields are parsed correctly.
44+
///
45+
func test_SitePlugin_fields_are_properly_parsed_when_response_has_no_data_envelope() {
46+
let plugins = mapLoadSitePluginsResponseWithoutDataEnvelope()
47+
XCTAssertEqual(plugins.count, 3)
48+
49+
let helloDollyPlugin = plugins[0]
50+
XCTAssertNotNil(helloDollyPlugin)
51+
XCTAssertEqual(helloDollyPlugin.siteID, dummySiteID)
52+
XCTAssertEqual(helloDollyPlugin.status, .inactive)
53+
XCTAssertEqual(helloDollyPlugin.name, "Hello Dolly")
54+
XCTAssertEqual(helloDollyPlugin.pluginUri, "http://wordpress.org/plugins/hello-dolly/")
55+
XCTAssertEqual(helloDollyPlugin.authorUri, "http://ma.tt/")
56+
XCTAssertEqual(helloDollyPlugin.descriptionRaw, "This is not just a plugin, it...")
57+
XCTAssertEqual(helloDollyPlugin.descriptionRendered, "This is not just a plugin, it symbolizes...")
58+
XCTAssertEqual(helloDollyPlugin.version, "1.7.2")
59+
XCTAssertEqual(helloDollyPlugin.textDomain, "")
60+
61+
let wooCommerceSubscriptionsPlugin = plugins[4]
62+
XCTAssertNotNil(wooCommerceSubscriptionsPlugin)
63+
XCTAssertEqual(wooCommerceSubscriptionsPlugin.siteID, dummySiteID)
64+
XCTAssertEqual(wooCommerceSubscriptionsPlugin.status, .active)
65+
XCTAssertEqual(wooCommerceSubscriptionsPlugin.name, "WooCommerce Subscriptions")
66+
XCTAssertEqual(wooCommerceSubscriptionsPlugin.pluginUri, "https://www.woocommerce.com/products/woocommerce-subscriptions/")
67+
XCTAssertEqual(wooCommerceSubscriptionsPlugin.authorUri, "https://woocommerce.com/")
68+
XCTAssertEqual(wooCommerceSubscriptionsPlugin.descriptionRaw, "Sell products and services...")
69+
XCTAssertEqual(wooCommerceSubscriptionsPlugin.descriptionRendered, "Sell products and services with recurring payments...")
70+
XCTAssertEqual(wooCommerceSubscriptionsPlugin.version, "3.0.13")
71+
XCTAssertEqual(wooCommerceSubscriptionsPlugin.textDomain, "woocommerce-subscriptions")
72+
}
4273
}
4374

4475

@@ -61,4 +92,10 @@ private extension SitePluginsMapperTests {
6192
func mapLoadSitePluginsResponse() -> [SitePlugin] {
6293
return mapPlugins(from: "plugins")
6394
}
95+
96+
/// Returns the SitePluginsMapper output upon receiving `plugins-without-data`
97+
///
98+
func mapLoadSitePluginsResponseWithoutDataEnvelope() -> [SitePlugin] {
99+
return mapPlugins(from: "plugins-without-data")
100+
}
64101
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[
2+
{
3+
"plugin": "hello",
4+
"status": "inactive",
5+
"name": "Hello Dolly",
6+
"plugin_uri": "http://wordpress.org/plugins/hello-dolly/",
7+
"author": "Matt Mullenweg",
8+
"author_uri": "http://ma.tt/",
9+
"description": {
10+
"raw": "This is not just a plugin, it...",
11+
"rendered": "This is not just a plugin, it symbolizes..."
12+
},
13+
"version": "1.7.2",
14+
"network_only": false,
15+
"requires_wp": "",
16+
"requires_php": "",
17+
"textdomain": "",
18+
"_links": {
19+
"self": [
20+
{
21+
"href": "https://example.com/wp-json/wp/v2/plugins/hello"
22+
}
23+
]
24+
}
25+
},
26+
{
27+
"plugin": "jetpack/jetpack",
28+
"status": "active",
29+
"name": "Jetpack by WordPress.com",
30+
"plugin_uri": "https://jetpack.com",
31+
"author": "Automattic",
32+
"author_uri": "https://jetpack.com",
33+
"description": {
34+
"raw": "Bring the power of the WordPress.com cloud to your self-hosted WordPress. Jetpack enables you to connect your blog to a WordPress.com account to use the powerful features normally only available to WordPress.com users.",
35+
"rendered": "Bring the power of the WordPress.com cloud to your self-hosted WordPress. Jetpack enables you to connect your blog to a WordPress.com account to use the powerful features normally only available to WordPress.com users. <cite>By <a href=\"https://jetpack.com\">Automattic</a>.</cite>"
36+
},
37+
"version": "9.5",
38+
"network_only": false,
39+
"requires_wp": "5.6",
40+
"requires_php": "5.6",
41+
"textdomain": "jetpack",
42+
"_links": {
43+
"self": [
44+
{
45+
"href": "https://example.com/wp-json/wp/v2/plugins/jetpack/jetpack"
46+
}
47+
]
48+
}
49+
},
50+
{
51+
"plugin": "woocommerce/woocommerce",
52+
"status": "active",
53+
"name": "WooCommerce",
54+
"plugin_uri": "https://woocommerce.com/",
55+
"author": "Automattic",
56+
"author_uri": "https://woocommerce.com",
57+
"description": {
58+
"raw": "An eCommerce toolkit that helps you sell anything. Beautifully.",
59+
"rendered": "An eCommerce toolkit that helps you sell anything. Beautifully. <cite>By <a href=\"https://woocommerce.com\">Automattic</a>.</cite>"
60+
},
61+
"version": "5.1.0",
62+
"network_only": false,
63+
"requires_wp": "5.4",
64+
"requires_php": "7.0",
65+
"textdomain": "woocommerce",
66+
"_links": {
67+
"self": [
68+
{
69+
"href": "https://example.com//wp-json/wp/v2/plugins/woocommerce/woocommerce"
70+
}
71+
]
72+
}
73+
}
74+
]

0 commit comments

Comments
 (0)