-
Notifications
You must be signed in to change notification settings - Fork 120
REST API: Migrate leaderboards endpoint #8546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e6db16b
Update LeaderboardListMapper to parse content without data envelope
itsmeichigo 574db02
Add tests for LeaderboardListMapper
itsmeichigo fc0583a
Enable REST request for leaderboard fetch
itsmeichigo 64ba491
Update mock data for LeaderboardListMapperTests
itsmeichigo 393fe06
Fix line limit violation
itsmeichigo c76f163
Support REST request on old leaderboard endpoint
itsmeichigo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Networking/NetworkingTests/Mapper/LeaderboardListMapperTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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-year") | ||
| } | ||
|
|
||
| /// Returns the LeaderboardListMapper output from `leaderboards-products-without-data.json` | ||
| /// | ||
| func mapLeaderboardListResponseWithoutDataEnvelope() throws -> [Leaderboard] { | ||
| return try mapLeaderboardList(from: "leaderboards-year-without-data") | ||
| } | ||
|
|
||
| struct FileNotFoundError: Error {} | ||
| } |
47 changes: 47 additions & 0 deletions
47
Networking/NetworkingTests/Responses/leaderboards-year-without-data.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| [ | ||
| { | ||
| "id": "products", | ||
| "label": "Top Products - Items Sold", | ||
| "headers": [ | ||
| { | ||
| "label": "Product" | ||
| }, | ||
| { | ||
| "label": "Items Sold" | ||
| }, | ||
| { | ||
| "label": "Net Sales" | ||
| } | ||
| ], | ||
| "rows": [ | ||
| [ | ||
| { | ||
| "display": "<a href='https:\/\/test.com\/wp-admin\/admin.php?page=wc-admin&path=\/analytics\/products&filter=single_product&products=9'>Aljafor<\/a>", | ||
| "value": "Aljafor" | ||
| }, | ||
| { | ||
| "display": "4", | ||
| "value": 4 | ||
| }, | ||
| { | ||
| "display": "<span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">$<\/span>20,000.00<\/span>", | ||
| "value": 20000 | ||
| } | ||
| ], | ||
| [ | ||
| { | ||
| "display": "<a href='https:\/\/test.com\/wp-admin\/admin.php?page=wc-admin&path=\/analytics\/products&filter=single_product&products=29'>Album<\/a>", | ||
| "value": "Album" | ||
| }, | ||
| { | ||
| "display": "1", | ||
| "value": 1 | ||
| }, | ||
| { | ||
| "display": "<span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">$<\/span>15.00<\/span>", | ||
| "value": 15.99 | ||
| } | ||
| ] | ||
| ] | ||
| } | ||
| ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reasons we don't allow
availableAsRESTRequest: truefor the deprecated leaderboards requestloadLeaderboardsDeprecatedbelow for sites with WC version under 6.7? is it because application passwords are supported for higher WC version?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching - I missed this 😅 Application password only has requirement for WordPress 5.6 minimum, so we should support WC under 6.7 I believe. Updated in c76f163.