From e6db16b94d9b8b43f52f57a149c8158845f8614b Mon Sep 17 00:00:00 2001 From: Huong Do Date: Wed, 4 Jan 2023 15:54:35 +0800 Subject: [PATCH 1/6] Update LeaderboardListMapper to parse content without data envelope --- Networking/Networking/Mapper/LeaderboardListMapper.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Networking/Networking/Mapper/LeaderboardListMapper.swift b/Networking/Networking/Mapper/LeaderboardListMapper.swift index 0c91d133d44..f9cdac6ee64 100644 --- a/Networking/Networking/Mapper/LeaderboardListMapper.swift +++ b/Networking/Networking/Mapper/LeaderboardListMapper.swift @@ -8,7 +8,11 @@ struct LeaderboardListMapper: Mapper { /// func map(response: Data) throws -> [Leaderboard] { let decoder = JSONDecoder() - return try decoder.decode(LeaderboardsEnvelope.self, from: response).data + do { + return try decoder.decode(LeaderboardsEnvelope.self, from: response).data + } catch { + return try decoder.decode([Leaderboard].self, from: response) + } } } From 574db02f03e4e845532ebeb51bd77d22ca2825ff Mon Sep 17 00:00:00 2001 From: Huong Do Date: Wed, 4 Jan 2023 16:10:14 +0800 Subject: [PATCH 2/6] Add tests for LeaderboardListMapper --- .../Networking.xcodeproj/project.pbxproj | 8 + .../Mapper/LeaderboardListMapperTests.swift | 54 +++ .../leaderboards-products-without-data.json | 391 ++++++++++++++++++ 3 files changed, 453 insertions(+) create mode 100644 Networking/NetworkingTests/Mapper/LeaderboardListMapperTests.swift create mode 100644 Networking/NetworkingTests/Responses/leaderboards-products-without-data.json diff --git a/Networking/Networking.xcodeproj/project.pbxproj b/Networking/Networking.xcodeproj/project.pbxproj index 2103da20d02..d398865d83b 100644 --- a/Networking/Networking.xcodeproj/project.pbxproj +++ b/Networking/Networking.xcodeproj/project.pbxproj @@ -722,6 +722,8 @@ DEC51AFB2769C66B009F3DF4 /* SystemStatusMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC51AFA2769C66B009F3DF4 /* SystemStatusMapperTests.swift */; }; DEC51B02276AFB35009F3DF4 /* SystemStatus+DropinMustUsePlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC51B01276AFB34009F3DF4 /* SystemStatus+DropinMustUsePlugin.swift */; }; DEF13C5029629EEA0024A02B /* user-complete-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DEF13C4F29629EEA0024A02B /* user-complete-without-data.json */; }; + DEF13C562965689F0024A02B /* LeaderboardListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEF13C552965689F0024A02B /* LeaderboardListMapperTests.swift */; }; + DEF13C5829656A610024A02B /* leaderboards-products-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DEF13C5729656A600024A02B /* leaderboards-products-without-data.json */; }; DEFBA74E29485A7600C35BA9 /* RESTRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFBA74D29485A7600C35BA9 /* RESTRequest.swift */; }; DEFBA7542949CE6600C35BA9 /* RequestProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFBA7532949CE6600C35BA9 /* RequestProcessor.swift */; }; DEFBA7562949D17400C35BA9 /* DefaultRequestAuthenticatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFBA7552949D17300C35BA9 /* DefaultRequestAuthenticatorTests.swift */; }; @@ -1515,6 +1517,8 @@ DEC51AFA2769C66B009F3DF4 /* SystemStatusMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemStatusMapperTests.swift; sourceTree = ""; }; DEC51B01276AFB34009F3DF4 /* SystemStatus+DropinMustUsePlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SystemStatus+DropinMustUsePlugin.swift"; sourceTree = ""; }; DEF13C4F29629EEA0024A02B /* user-complete-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "user-complete-without-data.json"; sourceTree = ""; }; + DEF13C552965689F0024A02B /* LeaderboardListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeaderboardListMapperTests.swift; sourceTree = ""; }; + DEF13C5729656A600024A02B /* leaderboards-products-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "leaderboards-products-without-data.json"; sourceTree = ""; }; DEFBA74D29485A7600C35BA9 /* RESTRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RESTRequest.swift; sourceTree = ""; }; DEFBA7532949CE6600C35BA9 /* RequestProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestProcessor.swift; sourceTree = ""; }; DEFBA7552949D17300C35BA9 /* DefaultRequestAuthenticatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultRequestAuthenticatorTests.swift; sourceTree = ""; }; @@ -2162,6 +2166,7 @@ B524194621AC643900D6FC0A /* device-settings.json */, 24F98C612502EFF600F49B68 /* feature-flags-load-all.json */, 268B68FA24C87384007EBF1D /* leaderboards-products.json */, + DEF13C5729656A600024A02B /* leaderboards-products-without-data.json */, E18152C128F85E0A0011A0EC /* iap-products.json */, E16C59B628F92782007D55BB /* iap-sample-receipt.json */, E16C59B828F927CA007D55BB /* iap-order-create.json */, @@ -2521,6 +2526,7 @@ isa = PBXGroup; children = ( B505F6D220BEE3A500BB1B69 /* AccountMapperTests.swift */, + DEF13C552965689F0024A02B /* LeaderboardListMapperTests.swift */, DE2E8EAA2954170D002E4B14 /* WordPressSiteMapperTests.swift */, 9387A6EF226E3F15001B53D7 /* AccountSettingsMapperTests.swift */, 077F39DB26A58F4800ABEADC /* SystemPluginMapperTests.swift */, @@ -3011,6 +3017,7 @@ 31054718262E2F5E00C5C02B /* wcpay-payment-intent-requires-confirmation.json in Resources */, D8FBFF2922D52AFB006E3336 /* order-stats-v4-year.json in Resources */, D865CE65278CA202002C8520 /* stripe-payment-intent-canceled.json in Resources */, + DEF13C5829656A610024A02B /* leaderboards-products-without-data.json in Resources */, AED8AEBA272A97B400663FCC /* null-data.json in Resources */, 02BA23CA22EEF62C009539E7 /* order-stats-v4-wcadmin-activated.json in Resources */, 31A451D627863A2E00FE81AA /* stripe-account-unknown-status.json in Resources */, @@ -3525,6 +3532,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + DEF13C562965689F0024A02B /* LeaderboardListMapperTests.swift in Sources */, 45551F142523E7FF007EF104 /* UserAgentTests.swift in Sources */, 03EB998A2906AB0C00F06A39 /* JustInTimeMessagesRemoteTests.swift in Sources */, DE34051D28BDF1C900CF0D97 /* JetpackConnectionURLMapperTests.swift in Sources */, diff --git a/Networking/NetworkingTests/Mapper/LeaderboardListMapperTests.swift b/Networking/NetworkingTests/Mapper/LeaderboardListMapperTests.swift new file mode 100644 index 00000000000..3055ec4fe09 --- /dev/null +++ b/Networking/NetworkingTests/Mapper/LeaderboardListMapperTests.swift @@ -0,0 +1,54 @@ +import XCTest +@testable import Networking + +final class LeaderboardListMapperTests: XCTestCase { + + /// Verifies that leaderboard list is parsed. + /// + func test_mapper_parses_leaderboard_list_in_response_with_data_envelope() throws { + // Given + let list = try mapLeaderboardListResponse() + + // Then + XCTAssertFalse(list.isEmpty) + } + + /// Verifies that the leaderboard list is parsed when the response has no data envelope. + /// + func test_mapper_parses_leaderboard_list_in_response_without_data_envelope() throws { + // Given + let list = try mapLeaderboardListResponseWithoutDataEnvelope() + + // Then + XCTAssertFalse(list.isEmpty) + } +} + +// MARK: - Test Helpers +/// +private extension LeaderboardListMapperTests { + + /// Returns the LeaderboardListMapper output upon receiving `filename` (Data Encoded) + /// + func mapLeaderboardList(from filename: String) throws -> [Leaderboard] { + guard let response = Loader.contentsOf(filename) else { + throw FileNotFoundError() + } + + return try LeaderboardListMapper().map(response: response) + } + + /// Returns the LeaderboardListMapper output from `products.json` + /// + func mapLeaderboardListResponse() throws -> [Leaderboard] { + return try mapLeaderboardList(from: "leaderboards-products") + } + + /// Returns the LeaderboardListMapper output from `leaderboards-products-without-data.json` + /// + func mapLeaderboardListResponseWithoutDataEnvelope() throws -> [Leaderboard] { + return try mapLeaderboardList(from: "leaderboards-products-without-data") + } + + struct FileNotFoundError: Error {} +} diff --git a/Networking/NetworkingTests/Responses/leaderboards-products-without-data.json b/Networking/NetworkingTests/Responses/leaderboards-products-without-data.json new file mode 100644 index 00000000000..f326dba91b9 --- /dev/null +++ b/Networking/NetworkingTests/Responses/leaderboards-products-without-data.json @@ -0,0 +1,391 @@ +[ + { + "related_ids" : [ + 30 + ], + "shipping_required" : false, + "categories" : [ + { + "id" : 21, + "name" : "Music", + "slug" : "music" + } + ], + "parent_id" : 0, + "variations" : [ + + ], + "id" : 29, + "regular_price" : "15", + "weight" : "", + "total_sales" : 1, + "sku" : "woo-album", + "rating_count" : 3, + "grouped_products" : [ + + ], + "backordered" : false, + "on_sale" : false, + "status" : "publish", + "download_limit" : 1, + "permalink" : "https://dulces.mystagingwebsite.com/product/album/", + "date_created" : "2020-06-18T18:03:17", + "description" : "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sagittis orci ac odio dictum tincidunt. Donec ut metus leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed luctus, dui eu sagittis sodales, nulla nibh sagittis augue, vel porttitor diam enim non metus. Vestibulum aliquam augue neque. Phasellus tincidunt odio eget ullamcorper efficitur. Cras placerat ut turpis pellentesque vulputate. Nam sed consequat tortor. Curabitur finibus sapien dolor. Ut eleifend tellus nec erat pulvinar dignissim. Nam non arcu purus. Vivamus et massa massa.

\n", + "reviews_allowed" : true, + "sale_price" : "", + "slug" : "album", + "type" : "simple", + "catalog_visibility" : "visible", + "download_expiry" : 1, + "meta_data" : [ + { + "id" : 604, + "key" : "_wpcom_is_markdown", + "value" : "1" + } + ], + "dimensions" : { + "width" : "", + "height" : "", + "length" : "" + }, + "cross_sell_ids" : [ + + ], + "price" : "15", + "date_on_sale_to" : null, + "name" : "Album", + "purchasable" : true, + "shipping_class" : "", + "attributes" : [ + + ], + "menu_order" : 0, + "virtual" : true, + "stock_status" : "instock", + "downloadable" : true, + "date_modified_gmt" : "2020-07-01T12:44:22", + "date_created_gmt" : "2020-06-18T18:03:17", + "default_attributes" : [ + + ], + "upsell_ids" : [ + + ], + "tags" : [ + + ], + "tax_class" : "", + "price_html" : "$15.00", + "sold_individually" : false, + "short_description" : "

This is a simple, virtual product.

\n", + "downloads" : [ + { + "id" : "262be1e5-9d26-40e1-804e-992e2fc71371", + "name" : "Single 1", + "file" : "https://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2017/08/single.jpg" + }, + { + "id" : "f5d20309-c189-45cf-8bf8-e43f4f4416ae", + "name" : "Single 2", + "file" : "https://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2017/08/album.jpg" + } + ], + "backorders" : "no", + "tax_status" : "taxable", + "date_on_sale_from_gmt" : null, + "shipping_taxable" : false, + "average_rating" : "4.67", + "_links" : { + "collection" : [ + { + "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products" + } + ], + "self" : [ + { + "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products/29" + } + ] + }, + "date_on_sale_from" : null, + "button_text" : "", + "purchase_note" : "", + "shipping_class_id" : 0, + "date_modified" : "2020-07-01T12:44:22", + "external_url" : "", + "date_on_sale_to_gmt" : null, + "backorders_allowed" : false, + "images" : [ + { + "id" : 58, + "src" : "https://dulces.mystagingwebsite.com/wp-content/uploads/2020/06/album-1.jpg", + "alt" : "", + "date_created" : "2020-06-18T18:03:22", + "date_modified" : "2020-06-18T18:03:22", + "date_created_gmt" : "2020-06-18T18:03:22", + "date_modified_gmt" : "2020-06-18T18:03:22", + "name" : "album-1.jpg" + } + ], + "stock_quantity" : null, + "featured" : false, + "manage_stock" : false + }, + { + "related_ids" : [ + 27, + 37, + 20, + 17 + ], + "shipping_required" : true, + "categories" : [ + { + "id" : 18, + "name" : "Tshirts", + "slug" : "tshirts" + } + ], + "parent_id" : 0, + "variations" : [ + + ], + "id" : 28, + "regular_price" : "20.99", + "weight" : "", + "total_sales" : 2, + "sku" : "woo-polo", + "rating_count" : 0, + "grouped_products" : [ + + ], + "backordered" : false, + "on_sale" : false, + "status" : "publish", + "download_limit" : 0, + "permalink" : "https://dulces.mystagingwebsite.com/product/polo/", + "date_created" : "2020-06-18T18:03:17", + "description" : "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", + "reviews_allowed" : true, + "sale_price" : "", + "slug" : "polo", + "type" : "simple", + "catalog_visibility" : "visible", + "download_expiry" : 0, + "meta_data" : [ + { + "id" : 595, + "key" : "_wpcom_is_markdown", + "value" : "1" + } + ], + "dimensions" : { + "width" : "", + "height" : "", + "length" : "" + }, + "cross_sell_ids" : [ + + ], + "price" : "20.99", + "date_on_sale_to" : null, + "name" : "Polo", + "purchasable" : true, + "shipping_class" : "", + "attributes" : [ + { + "id" : 1, + "variation" : false, + "options" : [ + "Blue" + ], + "name" : "Color", + "position" : 0, + "visible" : true + } + ], + "menu_order" : 0, + "virtual" : false, + "stock_status" : "instock", + "downloadable" : false, + "date_modified_gmt" : "2020-07-21T21:30:55", + "date_created_gmt" : "2020-06-18T18:03:17", + "default_attributes" : [ + + ], + "upsell_ids" : [ + + ], + "tags" : [ + + ], + "tax_class" : "", + "price_html" : "$20.99", + "sold_individually" : false, + "short_description" : "

This is a simple product.

\n", + "downloads" : [ + + ], + "backorders" : "no", + "tax_status" : "taxable", + "date_on_sale_from_gmt" : null, + "shipping_taxable" : true, + "average_rating" : "0.00", + "_links" : { + "collection" : [ + { + "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products" + } + ], + "self" : [ + { + "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products/28" + } + ] + }, + "date_on_sale_from" : null, + "button_text" : "", + "purchase_note" : "", + "shipping_class_id" : 0, + "date_modified" : "2020-07-21T21:30:55", + "external_url" : "", + "date_on_sale_to_gmt" : null, + "backorders_allowed" : false, + "images" : [ + { + "id" : 57, + "src" : "https://dulces.mystagingwebsite.com/wp-content/uploads/2020/06/polo-2.jpg", + "alt" : "", + "date_created" : "2020-06-18T18:03:22", + "date_modified" : "2020-06-18T18:03:22", + "date_created_gmt" : "2020-06-18T18:03:22", + "date_modified_gmt" : "2020-06-18T18:03:22", + "name" : "polo-2.jpg" + } + ], + "stock_quantity" : null, + "featured" : false, + "manage_stock" : false + }, + { + "related_ids" : [ + + ], + "shipping_required" : true, + "categories" : [ + { + "id" : 15, + "name" : "Uncategorized", + "slug" : "uncategorized" + } + ], + "parent_id" : 0, + "variations" : [ + + ], + "id" : 9, + "regular_price" : "4000", + "weight" : "1", + "total_sales" : 4, + "sku" : "", + "rating_count" : 4, + "grouped_products" : [ + + ], + "backordered" : false, + "on_sale" : false, + "status" : "publish", + "download_limit" : -1, + "permalink" : "https://dulces.mystagingwebsite.com/product/aljafor/", + "date_created" : "2020-06-02T21:27:19", + "description" : "

Rico alfajor con arequipe

\n", + "reviews_allowed" : true, + "sale_price" : "", + "slug" : "aljafor", + "type" : "simple", + "catalog_visibility" : "visible", + "download_expiry" : -1, + "meta_data" : [ + + ], + "dimensions" : { + "width" : "20", + "height" : "20", + "length" : "20" + }, + "cross_sell_ids" : [ + + ], + "price" : "4000", + "date_on_sale_to" : null, + "name" : "Aljafor", + "purchasable" : true, + "shipping_class" : "", + "attributes" : [ + + ], + "menu_order" : 0, + "virtual" : false, + "stock_status" : "instock", + "downloadable" : false, + "date_modified_gmt" : "2020-07-01T13:24:13", + "date_created_gmt" : "2020-06-02T21:27:19", + "default_attributes" : [ + + ], + "upsell_ids" : [ + + ], + "tags" : [ + + ], + "tax_class" : "zero-rate", + "price_html" : "$4,000.00", + "sold_individually" : false, + "short_description" : "", + "downloads" : [ + + ], + "backorders" : "no", + "tax_status" : "none", + "date_on_sale_from_gmt" : null, + "shipping_taxable" : false, + "average_rating" : "4.75", + "_links" : { + "collection" : [ + { + "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products" + } + ], + "self" : [ + { + "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products/9" + } + ] + }, + "date_on_sale_from" : null, + "button_text" : "", + "purchase_note" : "", + "shipping_class_id" : 0, + "date_modified" : "2020-07-01T13:24:13", + "external_url" : "", + "date_on_sale_to_gmt" : null, + "backorders_allowed" : false, + "images" : [ + { + "id" : 67, + "src" : "https://dulces.mystagingwebsite.com/wp-content/uploads/2020/07/img_7472-scaled.jpeg", + "alt" : "", + "date_created" : "2020-07-01T13:23:24", + "date_modified" : "2020-07-01T13:24:13", + "date_created_gmt" : "2020-07-01T13:23:24", + "date_modified_gmt" : "2020-07-01T13:24:13", + "name" : "img_7472" + } + ], + "stock_quantity" : null, + "featured" : false, + "manage_stock" : false + } +] From fc0583a5a169cdc7e507b5b1df3da32b973de101 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Wed, 4 Jan 2023 16:10:46 +0800 Subject: [PATCH 3/6] Enable REST request for leaderboard fetch --- Networking/Networking/Remote/LeaderboardsRemote.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Networking/Networking/Remote/LeaderboardsRemote.swift b/Networking/Networking/Remote/LeaderboardsRemote.swift index 4a08dd2dc51..0df8def2fd8 100644 --- a/Networking/Networking/Remote/LeaderboardsRemote.swift +++ b/Networking/Networking/Remote/LeaderboardsRemote.swift @@ -30,7 +30,7 @@ public class LeaderboardsRemote: Remote { ParameterKeys.forceRefresh: forceRefresh ] - let request = JetpackRequest(wooApiVersion: .wcAnalytics, method: .get, siteID: siteID, path: Constants.path, parameters: parameters) + let request = JetpackRequest(wooApiVersion: .wcAnalytics, method: .get, siteID: siteID, path: Constants.path, parameters: parameters, availableAsRESTRequest: true) let mapper = LeaderboardListMapper() enqueue(request, mapper: mapper, completion: completion) } From 64ba491ad9aebcbeb3b6e1e34b3cfaf95b8fee0b Mon Sep 17 00:00:00 2001 From: Huong Do Date: Wed, 4 Jan 2023 16:34:10 +0800 Subject: [PATCH 4/6] Update mock data for LeaderboardListMapperTests --- .../Networking.xcodeproj/project.pbxproj | 8 +- .../Mapper/LeaderboardListMapperTests.swift | 4 +- .../leaderboards-products-without-data.json | 391 ------------------ .../leaderboards-year-without-data.json | 47 +++ 4 files changed, 53 insertions(+), 397 deletions(-) delete mode 100644 Networking/NetworkingTests/Responses/leaderboards-products-without-data.json create mode 100644 Networking/NetworkingTests/Responses/leaderboards-year-without-data.json diff --git a/Networking/Networking.xcodeproj/project.pbxproj b/Networking/Networking.xcodeproj/project.pbxproj index d398865d83b..9ca45e24fcb 100644 --- a/Networking/Networking.xcodeproj/project.pbxproj +++ b/Networking/Networking.xcodeproj/project.pbxproj @@ -723,7 +723,7 @@ DEC51B02276AFB35009F3DF4 /* SystemStatus+DropinMustUsePlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC51B01276AFB34009F3DF4 /* SystemStatus+DropinMustUsePlugin.swift */; }; DEF13C5029629EEA0024A02B /* user-complete-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DEF13C4F29629EEA0024A02B /* user-complete-without-data.json */; }; DEF13C562965689F0024A02B /* LeaderboardListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEF13C552965689F0024A02B /* LeaderboardListMapperTests.swift */; }; - DEF13C5829656A610024A02B /* leaderboards-products-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DEF13C5729656A600024A02B /* leaderboards-products-without-data.json */; }; + DEF13C5A296571150024A02B /* leaderboards-year-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DEF13C59296571150024A02B /* leaderboards-year-without-data.json */; }; DEFBA74E29485A7600C35BA9 /* RESTRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFBA74D29485A7600C35BA9 /* RESTRequest.swift */; }; DEFBA7542949CE6600C35BA9 /* RequestProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFBA7532949CE6600C35BA9 /* RequestProcessor.swift */; }; DEFBA7562949D17400C35BA9 /* DefaultRequestAuthenticatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFBA7552949D17300C35BA9 /* DefaultRequestAuthenticatorTests.swift */; }; @@ -1518,7 +1518,7 @@ DEC51B01276AFB34009F3DF4 /* SystemStatus+DropinMustUsePlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SystemStatus+DropinMustUsePlugin.swift"; sourceTree = ""; }; DEF13C4F29629EEA0024A02B /* user-complete-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "user-complete-without-data.json"; sourceTree = ""; }; DEF13C552965689F0024A02B /* LeaderboardListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeaderboardListMapperTests.swift; sourceTree = ""; }; - DEF13C5729656A600024A02B /* leaderboards-products-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "leaderboards-products-without-data.json"; sourceTree = ""; }; + DEF13C59296571150024A02B /* leaderboards-year-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "leaderboards-year-without-data.json"; sourceTree = ""; }; DEFBA74D29485A7600C35BA9 /* RESTRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RESTRequest.swift; sourceTree = ""; }; DEFBA7532949CE6600C35BA9 /* RequestProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestProcessor.swift; sourceTree = ""; }; DEFBA7552949D17300C35BA9 /* DefaultRequestAuthenticatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultRequestAuthenticatorTests.swift; sourceTree = ""; }; @@ -2166,12 +2166,12 @@ B524194621AC643900D6FC0A /* device-settings.json */, 24F98C612502EFF600F49B68 /* feature-flags-load-all.json */, 268B68FA24C87384007EBF1D /* leaderboards-products.json */, - DEF13C5729656A600024A02B /* leaderboards-products-without-data.json */, E18152C128F85E0A0011A0EC /* iap-products.json */, E16C59B628F92782007D55BB /* iap-sample-receipt.json */, E16C59B828F927CA007D55BB /* iap-order-create.json */, 26B2F74624C55A6E0065CCC8 /* leaderboards-year.json */, 268B68FC24C87E37007EBF1D /* leaderboards-year-alt.json */, + DEF13C59296571150024A02B /* leaderboards-year-without-data.json */, 02EF1671292F0D1900D90AD6 /* load-plan-success.json */, B505F6D420BEE4E600BB1B69 /* me.json */, 93D8BBFE226BC1DA00AD2EB3 /* me-settings.json */, @@ -2944,6 +2944,7 @@ 265BCA02243056E3004E53EE /* categories-all.json in Resources */, D8FBFF2422D52815006E3336 /* order-stats-v4-daily.json in Resources */, CEC4BF91234E40B5008D9195 /* refund-single.json in Resources */, + DEF13C5A296571150024A02B /* leaderboards-year-without-data.json in Resources */, 2683D70E24456DB8002A1589 /* categories-empty.json in Resources */, D865CE67278CA225002C8520 /* stripe-payment-intent-succeeded.json in Resources */, DE74F2A027E3137F0002FE59 /* setting-analytics.json in Resources */, @@ -3017,7 +3018,6 @@ 31054718262E2F5E00C5C02B /* wcpay-payment-intent-requires-confirmation.json in Resources */, D8FBFF2922D52AFB006E3336 /* order-stats-v4-year.json in Resources */, D865CE65278CA202002C8520 /* stripe-payment-intent-canceled.json in Resources */, - DEF13C5829656A610024A02B /* leaderboards-products-without-data.json in Resources */, AED8AEBA272A97B400663FCC /* null-data.json in Resources */, 02BA23CA22EEF62C009539E7 /* order-stats-v4-wcadmin-activated.json in Resources */, 31A451D627863A2E00FE81AA /* stripe-account-unknown-status.json in Resources */, diff --git a/Networking/NetworkingTests/Mapper/LeaderboardListMapperTests.swift b/Networking/NetworkingTests/Mapper/LeaderboardListMapperTests.swift index 3055ec4fe09..e970c010954 100644 --- a/Networking/NetworkingTests/Mapper/LeaderboardListMapperTests.swift +++ b/Networking/NetworkingTests/Mapper/LeaderboardListMapperTests.swift @@ -41,13 +41,13 @@ private extension LeaderboardListMapperTests { /// Returns the LeaderboardListMapper output from `products.json` /// func mapLeaderboardListResponse() throws -> [Leaderboard] { - return try mapLeaderboardList(from: "leaderboards-products") + return try mapLeaderboardList(from: "leaderboards-year") } /// Returns the LeaderboardListMapper output from `leaderboards-products-without-data.json` /// func mapLeaderboardListResponseWithoutDataEnvelope() throws -> [Leaderboard] { - return try mapLeaderboardList(from: "leaderboards-products-without-data") + return try mapLeaderboardList(from: "leaderboards-year-without-data") } struct FileNotFoundError: Error {} diff --git a/Networking/NetworkingTests/Responses/leaderboards-products-without-data.json b/Networking/NetworkingTests/Responses/leaderboards-products-without-data.json deleted file mode 100644 index f326dba91b9..00000000000 --- a/Networking/NetworkingTests/Responses/leaderboards-products-without-data.json +++ /dev/null @@ -1,391 +0,0 @@ -[ - { - "related_ids" : [ - 30 - ], - "shipping_required" : false, - "categories" : [ - { - "id" : 21, - "name" : "Music", - "slug" : "music" - } - ], - "parent_id" : 0, - "variations" : [ - - ], - "id" : 29, - "regular_price" : "15", - "weight" : "", - "total_sales" : 1, - "sku" : "woo-album", - "rating_count" : 3, - "grouped_products" : [ - - ], - "backordered" : false, - "on_sale" : false, - "status" : "publish", - "download_limit" : 1, - "permalink" : "https://dulces.mystagingwebsite.com/product/album/", - "date_created" : "2020-06-18T18:03:17", - "description" : "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sagittis orci ac odio dictum tincidunt. Donec ut metus leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed luctus, dui eu sagittis sodales, nulla nibh sagittis augue, vel porttitor diam enim non metus. Vestibulum aliquam augue neque. Phasellus tincidunt odio eget ullamcorper efficitur. Cras placerat ut turpis pellentesque vulputate. Nam sed consequat tortor. Curabitur finibus sapien dolor. Ut eleifend tellus nec erat pulvinar dignissim. Nam non arcu purus. Vivamus et massa massa.

\n", - "reviews_allowed" : true, - "sale_price" : "", - "slug" : "album", - "type" : "simple", - "catalog_visibility" : "visible", - "download_expiry" : 1, - "meta_data" : [ - { - "id" : 604, - "key" : "_wpcom_is_markdown", - "value" : "1" - } - ], - "dimensions" : { - "width" : "", - "height" : "", - "length" : "" - }, - "cross_sell_ids" : [ - - ], - "price" : "15", - "date_on_sale_to" : null, - "name" : "Album", - "purchasable" : true, - "shipping_class" : "", - "attributes" : [ - - ], - "menu_order" : 0, - "virtual" : true, - "stock_status" : "instock", - "downloadable" : true, - "date_modified_gmt" : "2020-07-01T12:44:22", - "date_created_gmt" : "2020-06-18T18:03:17", - "default_attributes" : [ - - ], - "upsell_ids" : [ - - ], - "tags" : [ - - ], - "tax_class" : "", - "price_html" : "$15.00", - "sold_individually" : false, - "short_description" : "

This is a simple, virtual product.

\n", - "downloads" : [ - { - "id" : "262be1e5-9d26-40e1-804e-992e2fc71371", - "name" : "Single 1", - "file" : "https://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2017/08/single.jpg" - }, - { - "id" : "f5d20309-c189-45cf-8bf8-e43f4f4416ae", - "name" : "Single 2", - "file" : "https://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2017/08/album.jpg" - } - ], - "backorders" : "no", - "tax_status" : "taxable", - "date_on_sale_from_gmt" : null, - "shipping_taxable" : false, - "average_rating" : "4.67", - "_links" : { - "collection" : [ - { - "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products" - } - ], - "self" : [ - { - "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products/29" - } - ] - }, - "date_on_sale_from" : null, - "button_text" : "", - "purchase_note" : "", - "shipping_class_id" : 0, - "date_modified" : "2020-07-01T12:44:22", - "external_url" : "", - "date_on_sale_to_gmt" : null, - "backorders_allowed" : false, - "images" : [ - { - "id" : 58, - "src" : "https://dulces.mystagingwebsite.com/wp-content/uploads/2020/06/album-1.jpg", - "alt" : "", - "date_created" : "2020-06-18T18:03:22", - "date_modified" : "2020-06-18T18:03:22", - "date_created_gmt" : "2020-06-18T18:03:22", - "date_modified_gmt" : "2020-06-18T18:03:22", - "name" : "album-1.jpg" - } - ], - "stock_quantity" : null, - "featured" : false, - "manage_stock" : false - }, - { - "related_ids" : [ - 27, - 37, - 20, - 17 - ], - "shipping_required" : true, - "categories" : [ - { - "id" : 18, - "name" : "Tshirts", - "slug" : "tshirts" - } - ], - "parent_id" : 0, - "variations" : [ - - ], - "id" : 28, - "regular_price" : "20.99", - "weight" : "", - "total_sales" : 2, - "sku" : "woo-polo", - "rating_count" : 0, - "grouped_products" : [ - - ], - "backordered" : false, - "on_sale" : false, - "status" : "publish", - "download_limit" : 0, - "permalink" : "https://dulces.mystagingwebsite.com/product/polo/", - "date_created" : "2020-06-18T18:03:17", - "description" : "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", - "reviews_allowed" : true, - "sale_price" : "", - "slug" : "polo", - "type" : "simple", - "catalog_visibility" : "visible", - "download_expiry" : 0, - "meta_data" : [ - { - "id" : 595, - "key" : "_wpcom_is_markdown", - "value" : "1" - } - ], - "dimensions" : { - "width" : "", - "height" : "", - "length" : "" - }, - "cross_sell_ids" : [ - - ], - "price" : "20.99", - "date_on_sale_to" : null, - "name" : "Polo", - "purchasable" : true, - "shipping_class" : "", - "attributes" : [ - { - "id" : 1, - "variation" : false, - "options" : [ - "Blue" - ], - "name" : "Color", - "position" : 0, - "visible" : true - } - ], - "menu_order" : 0, - "virtual" : false, - "stock_status" : "instock", - "downloadable" : false, - "date_modified_gmt" : "2020-07-21T21:30:55", - "date_created_gmt" : "2020-06-18T18:03:17", - "default_attributes" : [ - - ], - "upsell_ids" : [ - - ], - "tags" : [ - - ], - "tax_class" : "", - "price_html" : "$20.99", - "sold_individually" : false, - "short_description" : "

This is a simple product.

\n", - "downloads" : [ - - ], - "backorders" : "no", - "tax_status" : "taxable", - "date_on_sale_from_gmt" : null, - "shipping_taxable" : true, - "average_rating" : "0.00", - "_links" : { - "collection" : [ - { - "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products" - } - ], - "self" : [ - { - "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products/28" - } - ] - }, - "date_on_sale_from" : null, - "button_text" : "", - "purchase_note" : "", - "shipping_class_id" : 0, - "date_modified" : "2020-07-21T21:30:55", - "external_url" : "", - "date_on_sale_to_gmt" : null, - "backorders_allowed" : false, - "images" : [ - { - "id" : 57, - "src" : "https://dulces.mystagingwebsite.com/wp-content/uploads/2020/06/polo-2.jpg", - "alt" : "", - "date_created" : "2020-06-18T18:03:22", - "date_modified" : "2020-06-18T18:03:22", - "date_created_gmt" : "2020-06-18T18:03:22", - "date_modified_gmt" : "2020-06-18T18:03:22", - "name" : "polo-2.jpg" - } - ], - "stock_quantity" : null, - "featured" : false, - "manage_stock" : false - }, - { - "related_ids" : [ - - ], - "shipping_required" : true, - "categories" : [ - { - "id" : 15, - "name" : "Uncategorized", - "slug" : "uncategorized" - } - ], - "parent_id" : 0, - "variations" : [ - - ], - "id" : 9, - "regular_price" : "4000", - "weight" : "1", - "total_sales" : 4, - "sku" : "", - "rating_count" : 4, - "grouped_products" : [ - - ], - "backordered" : false, - "on_sale" : false, - "status" : "publish", - "download_limit" : -1, - "permalink" : "https://dulces.mystagingwebsite.com/product/aljafor/", - "date_created" : "2020-06-02T21:27:19", - "description" : "

Rico alfajor con arequipe

\n", - "reviews_allowed" : true, - "sale_price" : "", - "slug" : "aljafor", - "type" : "simple", - "catalog_visibility" : "visible", - "download_expiry" : -1, - "meta_data" : [ - - ], - "dimensions" : { - "width" : "20", - "height" : "20", - "length" : "20" - }, - "cross_sell_ids" : [ - - ], - "price" : "4000", - "date_on_sale_to" : null, - "name" : "Aljafor", - "purchasable" : true, - "shipping_class" : "", - "attributes" : [ - - ], - "menu_order" : 0, - "virtual" : false, - "stock_status" : "instock", - "downloadable" : false, - "date_modified_gmt" : "2020-07-01T13:24:13", - "date_created_gmt" : "2020-06-02T21:27:19", - "default_attributes" : [ - - ], - "upsell_ids" : [ - - ], - "tags" : [ - - ], - "tax_class" : "zero-rate", - "price_html" : "$4,000.00", - "sold_individually" : false, - "short_description" : "", - "downloads" : [ - - ], - "backorders" : "no", - "tax_status" : "none", - "date_on_sale_from_gmt" : null, - "shipping_taxable" : false, - "average_rating" : "4.75", - "_links" : { - "collection" : [ - { - "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products" - } - ], - "self" : [ - { - "href" : "https://dulces.mystagingwebsite.com/wp-json/wc/v3/products/9" - } - ] - }, - "date_on_sale_from" : null, - "button_text" : "", - "purchase_note" : "", - "shipping_class_id" : 0, - "date_modified" : "2020-07-01T13:24:13", - "external_url" : "", - "date_on_sale_to_gmt" : null, - "backorders_allowed" : false, - "images" : [ - { - "id" : 67, - "src" : "https://dulces.mystagingwebsite.com/wp-content/uploads/2020/07/img_7472-scaled.jpeg", - "alt" : "", - "date_created" : "2020-07-01T13:23:24", - "date_modified" : "2020-07-01T13:24:13", - "date_created_gmt" : "2020-07-01T13:23:24", - "date_modified_gmt" : "2020-07-01T13:24:13", - "name" : "img_7472" - } - ], - "stock_quantity" : null, - "featured" : false, - "manage_stock" : false - } -] diff --git a/Networking/NetworkingTests/Responses/leaderboards-year-without-data.json b/Networking/NetworkingTests/Responses/leaderboards-year-without-data.json new file mode 100644 index 00000000000..802ad26b625 --- /dev/null +++ b/Networking/NetworkingTests/Responses/leaderboards-year-without-data.json @@ -0,0 +1,47 @@ +[ + { + "id": "products", + "label": "Top Products - Items Sold", + "headers": [ + { + "label": "Product" + }, + { + "label": "Items Sold" + }, + { + "label": "Net Sales" + } + ], + "rows": [ + [ + { + "display": "Aljafor<\/a>", + "value": "Aljafor" + }, + { + "display": "4", + "value": 4 + }, + { + "display": "$<\/span>20,000.00<\/span>", + "value": 20000 + } + ], + [ + { + "display": "Album<\/a>", + "value": "Album" + }, + { + "display": "1", + "value": 1 + }, + { + "display": "$<\/span>15.00<\/span>", + "value": 15.99 + } + ] + ] + } +] From 393fe067a5b4c34b0a4479338bdf6904c6870652 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Wed, 4 Jan 2023 17:49:51 +0800 Subject: [PATCH 5/6] Fix line limit violation --- Networking/Networking/Remote/LeaderboardsRemote.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Networking/Networking/Remote/LeaderboardsRemote.swift b/Networking/Networking/Remote/LeaderboardsRemote.swift index 0df8def2fd8..fb37ec08fc9 100644 --- a/Networking/Networking/Remote/LeaderboardsRemote.swift +++ b/Networking/Networking/Remote/LeaderboardsRemote.swift @@ -30,7 +30,12 @@ public class LeaderboardsRemote: Remote { ParameterKeys.forceRefresh: forceRefresh ] - let request = JetpackRequest(wooApiVersion: .wcAnalytics, method: .get, siteID: siteID, path: Constants.path, parameters: parameters, availableAsRESTRequest: true) + let request = JetpackRequest(wooApiVersion: .wcAnalytics, + method: .get, + siteID: siteID, + path: Constants.path, + parameters: parameters, + availableAsRESTRequest: true) let mapper = LeaderboardListMapper() enqueue(request, mapper: mapper, completion: completion) } From c76f163ef2bb0232680eec87ed2a5ab1c5bda752 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Thu, 5 Jan 2023 10:10:05 +0800 Subject: [PATCH 6/6] Support REST request on old leaderboard endpoint --- Networking/Networking/Remote/LeaderboardsRemote.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Networking/Networking/Remote/LeaderboardsRemote.swift b/Networking/Networking/Remote/LeaderboardsRemote.swift index fb37ec08fc9..579081f2219 100644 --- a/Networking/Networking/Remote/LeaderboardsRemote.swift +++ b/Networking/Networking/Remote/LeaderboardsRemote.swift @@ -67,7 +67,12 @@ public class LeaderboardsRemote: Remote { ParameterKeys.forceRefresh: forceRefresh ] - let request = JetpackRequest(wooApiVersion: .wcAnalytics, method: .get, siteID: siteID, path: Constants.pathDeprecated, parameters: parameters) + let request = JetpackRequest(wooApiVersion: .wcAnalytics, + method: .get, + siteID: siteID, + path: Constants.pathDeprecated, + parameters: parameters, + availableAsRESTRequest: true) let mapper = LeaderboardListMapper() enqueue(request, mapper: mapper, completion: completion) }