Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ _None._
### Breaking Changes

- Add a new `unacceptableStatusCode` error case to `WordPressAPIError`. [#668]
- The `deviceId` parameter in `DashboardServiceRemote` is now non-optional. [#678]

### New Features

Expand Down
11 changes: 3 additions & 8 deletions WordPressKit/DashboardServiceRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open class DashboardServiceRemote: ServiceRemoteWordPressComREST {
open func fetch(
cards: [String],
forBlogID blogID: Int,
deviceId: String? = nil,
deviceId: String,
success: @escaping (NSDictionary) -> Void,
failure: @escaping (Error) -> Void
) {
Expand Down Expand Up @@ -32,16 +32,11 @@ open class DashboardServiceRemote: ServiceRemoteWordPressComREST {
})
}

private func makeQueryParams(cards: [String], deviceId: String?) throws -> [String: AnyObject] {
private func makeQueryParams(cards: [String], deviceId: String) throws -> [String: AnyObject] {
let cardsParams: [String: AnyObject] = [
"cards": cards.joined(separator: ",") as NSString
]
let featureFlagParams: [String: AnyObject]? = try {
guard let deviceId else {
return nil
}
return try SessionDetails(deviceId: deviceId).dictionaryRepresentation()
}()
let featureFlagParams: [String: AnyObject]? = try SessionDetails(deviceId: deviceId).dictionaryRepresentation()
return cardsParams.merging(featureFlagParams ?? [:]) { first, second in
return first
}
Expand Down
30 changes: 0 additions & 30 deletions WordPressKitTests/DashboardServiceRemoteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,6 @@ class DashboardServiceRemoteTests: RemoteTestCase, RESTTestable {
waitForExpectations(timeout: timeout, handler: nil)
}

// Validates the request's path and query items when the `deviceId` param is `nil`.
//
func testRequestCardsParamWithoutDeviceId() {
let expect = expectation(description: "Dashboard endpoint should contain query params")
let expectedPath = "/wpcom/v2/sites/165243437/dashboard/cards-data"
let expectedQueryParams: Set<String> = ["cards", "locale"]

stubRemoteResponse({ req in
let url = req.url?.absoluteString ?? ""
let containsQueryParams = self.queryParams(expectedQueryParams, containedInRequest: req)
let matchesPath = isPath(expectedPath)(req)
XCTAssertTrue(matchesPath, "The URL '\(url)' doesn't match the expected path.")
XCTAssertTrue(containsQueryParams, "The URL '\(url)' doesn't contain the expected query params.")
return containsQueryParams && matchesPath
}, filename: "dashboard-200-with-drafts-and-scheduled-posts.json", contentType: .ApplicationJSON)

dashboardServiceRemote.fetch(
cards: ["posts", "todays_stats"],
forBlogID: 165243437,
deviceId: nil
) { _ in
expect.fulfill()
} failure: { error in
XCTFail("Dashboard cards request failed: \(error.localizedDescription)")
expect.fulfill()
}

waitForExpectations(timeout: timeout, handler: nil)
}

// Return the cards when the request succeeds
//
func testRequestCards() {
Expand Down