Skip to content

Commit

Permalink
Update unit tests with a test case on invalid type in an environment …
Browse files Browse the repository at this point in the history
…non required field.
  • Loading branch information
jaclync committed Jan 2, 2025
1 parent e7d8e45 commit bde4e5b
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 135 deletions.
8 changes: 8 additions & 0 deletions Networking/Networking.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
028FA474257E110700F88A48 /* shipping-label-refund-success.json in Resources */ = {isa = PBXBuildFile; fileRef = 028FA472257E110700F88A48 /* shipping-label-refund-success.json */; };
0291496E2D2634F800F7B3B3 /* SystemStatusReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0291496D2D2634F800F7B3B3 /* SystemStatusReport.swift */; };
029149702D263AE700F7B3B3 /* SystemStatusReportMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0291496F2D263AE700F7B3B3 /* SystemStatusReportMapper.swift */; };
029149722D2641DD00F7B3B3 /* SystemStatusReportMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 029149712D2641DD00F7B3B3 /* SystemStatusReportMapperTests.swift */; };
029149742D26430E00F7B3B3 /* systemStatus-inconsistent-environment-max-upload-size-data-type.json in Resources */ = {isa = PBXBuildFile; fileRef = 029149732D26430E00F7B3B3 /* systemStatus-inconsistent-environment-max-upload-size-data-type.json */; };
02935AEE29DFFA74001B793E /* site-enable-trial-success.json in Resources */ = {isa = PBXBuildFile; fileRef = 02935AEC29DFFA74001B793E /* site-enable-trial-success.json */; };
02935AEF29DFFA74001B793E /* site-enable-trial-error-already-upgraded.json in Resources */ = {isa = PBXBuildFile; fileRef = 02935AED29DFFA74001B793E /* site-enable-trial-error-already-upgraded.json */; };
029B86902A6FBBE000E944D1 /* wcpay-account-null-isLive.json in Resources */ = {isa = PBXBuildFile; fileRef = 029B868F2A6FBBE000E944D1 /* wcpay-account-null-isLive.json */; };
Expand Down Expand Up @@ -1370,6 +1372,8 @@
028FA472257E110700F88A48 /* shipping-label-refund-success.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-refund-success.json"; sourceTree = "<group>"; };
0291496D2D2634F800F7B3B3 /* SystemStatusReport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemStatusReport.swift; sourceTree = "<group>"; };
0291496F2D263AE700F7B3B3 /* SystemStatusReportMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemStatusReportMapper.swift; sourceTree = "<group>"; };
029149712D2641DD00F7B3B3 /* SystemStatusReportMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemStatusReportMapperTests.swift; sourceTree = "<group>"; };
029149732D26430E00F7B3B3 /* systemStatus-inconsistent-environment-max-upload-size-data-type.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "systemStatus-inconsistent-environment-max-upload-size-data-type.json"; sourceTree = "<group>"; };
02935AEC29DFFA74001B793E /* site-enable-trial-success.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "site-enable-trial-success.json"; sourceTree = "<group>"; };
02935AED29DFFA74001B793E /* site-enable-trial-error-already-upgraded.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "site-enable-trial-error-already-upgraded.json"; sourceTree = "<group>"; };
029B868F2A6FBBE000E944D1 /* wcpay-account-null-isLive.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "wcpay-account-null-isLive.json"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3102,6 +3106,7 @@
DE8BEF0C2D151396008B3A3F /* notification-settings.json */,
EED25B1C2CF74B9800503657 /* media-upload.json */,
EE6C6B6F2C6A190500632BDA /* systemStatus-inconsistent-page-id-data-type.json */,
029149732D26430E00F7B3B3 /* systemStatus-inconsistent-environment-max-upload-size-data-type.json */,
DEB3878E2C2D71A10025256E /* gla-campaign-list-with-data-envelope.json */,
DEB3878D2C2D71A10025256E /* gla-campaign-list-without-data-envelope.json */,
DEB387772C2A9ADC0025256E /* gla-connection-with-data-envelope.json */,
Expand Down Expand Up @@ -3775,6 +3780,7 @@
9387A6EF226E3F15001B53D7 /* AccountSettingsMapperTests.swift */,
077F39DB26A58F4800ABEADC /* SystemPluginMapperTests.swift */,
DEC51AFA2769C66B009F3DF4 /* SystemStatusMapperTests.swift */,
029149712D2641DD00F7B3B3 /* SystemStatusReportMapperTests.swift */,
2685C0D9263B551300D9EE97 /* AddOnGroupMapperTests.swift */,
74AB0AC921948CE4008220CD /* CommentResultMapperTests.swift */,
03DCB7432624AD9A00C8953D /* CouponListMapperTests.swift */,
Expand Down Expand Up @@ -4572,6 +4578,7 @@
EE1CB9162B4BCFA800AD24D5 /* blaze-ai-suggestions.json in Resources */,
DE66C5672977CEB800DAA978 /* shipping-label-status-success-without-data.json in Resources */,
D8FBFF2922D52AFB006E3336 /* order-stats-v4-year.json in Resources */,
029149742D26430E00F7B3B3 /* systemStatus-inconsistent-environment-max-upload-size-data-type.json in Resources */,
D865CE65278CA202002C8520 /* stripe-payment-intent-canceled.json in Resources */,
DE20046A2BF74B1E00660A72 /* product-stock-string-quantity.json in Resources */,
DE42F9672967F61D00D514C2 /* refunds-all-without-data.json in Resources */,
Expand Down Expand Up @@ -5514,6 +5521,7 @@
DE2E8EAB2954170D002E4B14 /* WordPressSiteMapperTests.swift in Sources */,
D88D5A4F230BD276007B6E01 /* ProductReviewListMapperTests.swift in Sources */,
B567AF3120A0FB8F00AB6C62 /* JetpackRequestTests.swift in Sources */,
029149722D2641DD00F7B3B3 /* SystemStatusReportMapperTests.swift in Sources */,
7412A8F221B6E47A005D182A /* ReportRemoteTests.swift in Sources */,
DE78DE4C2B2AED4C002E58DE /* WordPressPageMapperTests.swift in Sources */,
4513382627A96DB700AE5E78 /* InboxNoteMapperTests.swift in Sources */,
Expand Down
167 changes: 35 additions & 132 deletions Networking/NetworkingTests/Mapper/SystemStatusMapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,152 +11,49 @@ final class SystemStatusMapperTests: XCTestCase {

func test_system_status_fields_are_properly_parsed() throws {
// When
let report = try mapLoadSystemStatusResponse()
let status = try mapLoadSystemStatusResponse()

// Then
XCTAssertEqual(report.environment?.homeURL, "https://additional-beetle.jurassic.ninja")
XCTAssertEqual(report.environment?.siteURL, "https://additional-beetle.jurassic.ninja")
XCTAssertEqual(report.environment?.version, "5.9.0")
XCTAssertEqual(report.environment?.wpVersion, "5.8.2")
XCTAssertEqual(report.environment?.phpVersion, "7.4.26")
XCTAssertEqual(report.environment?.curlVersion, "7.47.0, OpenSSL/1.0.2g")
XCTAssertEqual(report.environment?.mysqlVersion, "5.7.33-0ubuntu0.16.04.1-log")

XCTAssertEqual(report.database?.wcDatabaseVersion, "5.9.0")
XCTAssertEqual(report.database?.databasePrefix, "wp_")
XCTAssertEqual(report.database?.databaseTables.woocommerce.count, 14)
XCTAssertEqual(report.database?.databaseTables.other.count, 29)

XCTAssertEqual(report.activePlugins.count, 4)
XCTAssertEqual(report.activePlugins[0].siteID, dummySiteID)
XCTAssertEqual(report.inactivePlugins.count, 2)
XCTAssertEqual(report.inactivePlugins[1].siteID, dummySiteID)
XCTAssertEqual(report.dropinPlugins.count, 2)
XCTAssertEqual(report.dropinPlugins[0].name, "advanced-cache.php")
XCTAssertEqual(report.mustUsePlugins.count, 1)
XCTAssertEqual(report.mustUsePlugins[0].name, "WP.com Site Helper")

XCTAssertEqual(report.theme?.name, "Twenty Twenty-One")
XCTAssertEqual(report.theme?.version, "1.4")
XCTAssertEqual(report.theme?.authorURL, "https://wordpress.org/")
XCTAssertEqual(report.theme?.hasWoocommerceSupport, true)
XCTAssertEqual(report.theme?.overrides.count, 0)

XCTAssertEqual(report.settings?.apiEnabled, false)
XCTAssertEqual(report.settings?.currency, "USD")
XCTAssertEqual(report.settings?.currencySymbol, "&#36;")
XCTAssertEqual(report.settings?.currencyPosition, "left")
XCTAssertEqual(report.settings?.numberOfDecimals, 2)
XCTAssertEqual(report.settings?.thousandSeparator, ",")
XCTAssertEqual(report.settings?.decimalSeparator, ".")
XCTAssertEqual(report.settings?.taxonomies["external"], "external")
XCTAssertEqual(report.settings?.productVisibilityTerms["exclude-from-catalog"], "exclude-from-catalog")

XCTAssertEqual(report.security?.secureConnection, true)
XCTAssertEqual(report.security?.hideErrors, false)

XCTAssertEqual(report.pages.count, 5)
XCTAssertEqual(report.postTypeCounts.count, 3)
XCTAssertEqual(status.environment?.storeID, "sample-store-uuid")
XCTAssertEqual(status.activePlugins.count, 4)
XCTAssertEqual(status.activePlugins[0].siteID, dummySiteID)
XCTAssertEqual(status.inactivePlugins.count, 2)
XCTAssertEqual(status.inactivePlugins[1].siteID, dummySiteID)
}

func test_system_status_fields_are_properly_parsed_when_response_has_no_data_envelope() throws {
// When
let report = try mapLoadSystemStatusResponseWithoutDataEnvelope()
let status = try mapLoadSystemStatusResponseWithoutDataEnvelope()

// Then
XCTAssertEqual(report.environment?.homeURL, "https://additional-beetle.jurassic.ninja")
XCTAssertEqual(report.environment?.siteURL, "https://additional-beetle.jurassic.ninja")
XCTAssertEqual(report.environment?.version, "5.9.0")
XCTAssertEqual(report.environment?.wpVersion, "5.8.2")
XCTAssertEqual(report.environment?.phpVersion, "7.4.26")
XCTAssertEqual(report.environment?.curlVersion, "7.47.0, OpenSSL/1.0.2g")
XCTAssertEqual(report.environment?.mysqlVersion, "5.7.33-0ubuntu0.16.04.1-log")

XCTAssertEqual(report.database?.wcDatabaseVersion, "5.9.0")
XCTAssertEqual(report.database?.databasePrefix, "wp_")
XCTAssertEqual(report.database?.databaseTables.woocommerce.count, 14)
XCTAssertEqual(report.database?.databaseTables.other.count, 29)

XCTAssertEqual(report.activePlugins.count, 4)
XCTAssertEqual(report.activePlugins[0].siteID, dummySiteID)
XCTAssertEqual(report.inactivePlugins.count, 2)
XCTAssertEqual(report.inactivePlugins[1].siteID, dummySiteID)
XCTAssertEqual(report.dropinPlugins.count, 2)
XCTAssertEqual(report.dropinPlugins[0].name, "advanced-cache.php")
XCTAssertEqual(report.mustUsePlugins.count, 1)
XCTAssertEqual(report.mustUsePlugins[0].name, "WP.com Site Helper")

XCTAssertEqual(report.theme?.name, "Twenty Twenty-One")
XCTAssertEqual(report.theme?.version, "1.4")
XCTAssertEqual(report.theme?.authorURL, "https://wordpress.org/")
XCTAssertEqual(report.theme?.hasWoocommerceSupport, true)
XCTAssertEqual(report.theme?.overrides.count, 0)

XCTAssertEqual(report.settings?.apiEnabled, false)
XCTAssertEqual(report.settings?.currency, "USD")
XCTAssertEqual(report.settings?.currencySymbol, "&#36;")
XCTAssertEqual(report.settings?.currencyPosition, "left")
XCTAssertEqual(report.settings?.numberOfDecimals, 2)
XCTAssertEqual(report.settings?.thousandSeparator, ",")
XCTAssertEqual(report.settings?.decimalSeparator, ".")
XCTAssertEqual(report.settings?.taxonomies["external"], "external")
XCTAssertEqual(report.settings?.productVisibilityTerms["exclude-from-catalog"], "exclude-from-catalog")

XCTAssertEqual(report.security?.secureConnection, true)
XCTAssertEqual(report.security?.hideErrors, false)

XCTAssertEqual(report.pages.count, 5)
XCTAssertEqual(report.postTypeCounts.count, 3)
XCTAssertEqual(status.activePlugins.count, 4)
XCTAssertEqual(status.activePlugins[0].siteID, dummySiteID)
XCTAssertEqual(status.inactivePlugins.count, 2)
XCTAssertEqual(status.inactivePlugins[1].siteID, dummySiteID)
}

func test_system_status_fields_are_properly_parsed_when_response_has_inconsistent_data_type_for_page_id() throws {
// When
let report = try mapLoadSystemStatusResponseWithInconsistentPageIdDataType()
let status = try mapLoadSystemStatusResponseWithInconsistentPageIdDataType()

// Then
XCTAssertEqual(report.environment?.homeURL, "https://additional-beetle.jurassic.ninja")
XCTAssertEqual(report.environment?.siteURL, "https://additional-beetle.jurassic.ninja")
XCTAssertEqual(report.environment?.version, "5.9.0")
XCTAssertEqual(report.environment?.wpVersion, "5.8.2")
XCTAssertEqual(report.environment?.phpVersion, "7.4.26")
XCTAssertEqual(report.environment?.curlVersion, "7.47.0, OpenSSL/1.0.2g")
XCTAssertEqual(report.environment?.mysqlVersion, "5.7.33-0ubuntu0.16.04.1-log")

XCTAssertEqual(report.database?.wcDatabaseVersion, "5.9.0")
XCTAssertEqual(report.database?.databasePrefix, "wp_")
XCTAssertEqual(report.database?.databaseTables.woocommerce.count, 14)
XCTAssertEqual(report.database?.databaseTables.other.count, 29)

XCTAssertEqual(report.activePlugins.count, 4)
XCTAssertEqual(report.activePlugins[0].siteID, dummySiteID)
XCTAssertEqual(report.inactivePlugins.count, 2)
XCTAssertEqual(report.inactivePlugins[1].siteID, dummySiteID)
XCTAssertEqual(report.dropinPlugins.count, 2)
XCTAssertEqual(report.dropinPlugins[0].name, "advanced-cache.php")
XCTAssertEqual(report.mustUsePlugins.count, 1)
XCTAssertEqual(report.mustUsePlugins[0].name, "WP.com Site Helper")

XCTAssertEqual(report.theme?.name, "Twenty Twenty-One")
XCTAssertEqual(report.theme?.version, "1.4")
XCTAssertEqual(report.theme?.authorURL, "https://wordpress.org/")
XCTAssertEqual(report.theme?.hasWoocommerceSupport, true)
XCTAssertEqual(report.theme?.overrides.count, 0)

XCTAssertEqual(report.settings?.apiEnabled, false)
XCTAssertEqual(report.settings?.currency, "USD")
XCTAssertEqual(report.settings?.currencySymbol, "&#36;")
XCTAssertEqual(report.settings?.currencyPosition, "left")
XCTAssertEqual(report.settings?.numberOfDecimals, 2)
XCTAssertEqual(report.settings?.thousandSeparator, ",")
XCTAssertEqual(report.settings?.decimalSeparator, ".")
XCTAssertEqual(report.settings?.taxonomies["external"], "external")
XCTAssertEqual(report.settings?.productVisibilityTerms["exclude-from-catalog"], "exclude-from-catalog")

XCTAssertEqual(report.security?.secureConnection, true)
XCTAssertEqual(report.security?.hideErrors, false)

XCTAssertEqual(report.pages.count, 5)
XCTAssertEqual(report.postTypeCounts.count, 3)
XCTAssertEqual(status.environment?.storeID, "sample-store-uuid")
XCTAssertEqual(status.activePlugins.count, 4)
XCTAssertEqual(status.activePlugins[0].siteID, dummySiteID)
XCTAssertEqual(status.inactivePlugins.count, 2)
XCTAssertEqual(status.inactivePlugins[1].siteID, dummySiteID)
}

func test_system_status_fields_are_properly_parsed_when_response_has_inconsistent_data_type_for_unused_environment_properties() throws {
// When
let status = try mapLoadSystemStatusResponseWithInconsistentEnvironmentMaxUploadSizeType()

// Then
XCTAssertEqual(status.environment?.storeID, "sample-store-uuid")
XCTAssertEqual(status.activePlugins.count, 4)
XCTAssertEqual(status.activePlugins[0].siteID, dummySiteID)
XCTAssertEqual(status.inactivePlugins.count, 2)
XCTAssertEqual(status.inactivePlugins[1].siteID, dummySiteID)
}
}

Expand Down Expand Up @@ -189,4 +86,10 @@ private extension SystemStatusMapperTests {
func mapLoadSystemStatusResponseWithInconsistentPageIdDataType() throws -> SystemStatus {
return try mapReport(from: "systemStatus-inconsistent-page-id-data-type")
}

/// Returns the SystemStatus output upon receiving `systemStatus-inconsistent-environment-max-upload-size-data-type.json`
///
func mapLoadSystemStatusResponseWithInconsistentEnvironmentMaxUploadSizeType() throws -> SystemStatus {
return try mapReport(from: "systemStatus-inconsistent-environment-max-upload-size-data-type")
}
}
Loading

0 comments on commit bde4e5b

Please sign in to comment.