Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit d2a1d33

Browse files
committed
Make deviceId a required parameter
The parameter was [initially designed to be non-optional][PR-1]. Later it's later [changed to be optional][PR-2], under [this proposal][comment-1]. This commit simply reverts the parameter to be non-optional, to ship it along with other breaking changes. [PR-1]: #674 [PR-2]: #676 [comment-1]: wordpress-mobile/WordPress-iOS#22320 (comment)
1 parent 92a74b7 commit d2a1d33

File tree

2 files changed

+3
-38
lines changed

2 files changed

+3
-38
lines changed

WordPressKit/DashboardServiceRemote.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ open class DashboardServiceRemote: ServiceRemoteWordPressComREST {
44
open func fetch(
55
cards: [String],
66
forBlogID blogID: Int,
7-
deviceId: String? = nil,
7+
deviceId: String,
88
success: @escaping (NSDictionary) -> Void,
99
failure: @escaping (Error) -> Void
1010
) {
@@ -32,16 +32,11 @@ open class DashboardServiceRemote: ServiceRemoteWordPressComREST {
3232
})
3333
}
3434

35-
private func makeQueryParams(cards: [String], deviceId: String?) throws -> [String: AnyObject] {
35+
private func makeQueryParams(cards: [String], deviceId: String) throws -> [String: AnyObject] {
3636
let cardsParams: [String: AnyObject] = [
3737
"cards": cards.joined(separator: ",") as NSString
3838
]
39-
let featureFlagParams: [String: AnyObject]? = try {
40-
guard let deviceId else {
41-
return nil
42-
}
43-
return try SessionDetails(deviceId: deviceId).dictionaryRepresentation()
44-
}()
39+
let featureFlagParams: [String: AnyObject]? = try SessionDetails(deviceId: deviceId).dictionaryRepresentation()
4540
return cardsParams.merging(featureFlagParams ?? [:]) { first, second in
4641
return first
4742
}

WordPressKitTests/DashboardServiceRemoteTests.swift

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,36 +49,6 @@ class DashboardServiceRemoteTests: RemoteTestCase, RESTTestable {
4949
waitForExpectations(timeout: timeout, handler: nil)
5050
}
5151

52-
// Validates the request's path and query items when the `deviceId` param is `nil`.
53-
//
54-
func testRequestCardsParamWithoutDeviceId() {
55-
let expect = expectation(description: "Dashboard endpoint should contain query params")
56-
let expectedPath = "/wpcom/v2/sites/165243437/dashboard/cards-data"
57-
let expectedQueryParams: Set<String> = ["cards", "locale"]
58-
59-
stubRemoteResponse({ req in
60-
let url = req.url?.absoluteString ?? ""
61-
let containsQueryParams = self.queryParams(expectedQueryParams, containedInRequest: req)
62-
let matchesPath = isPath(expectedPath)(req)
63-
XCTAssertTrue(matchesPath, "The URL '\(url)' doesn't match the expected path.")
64-
XCTAssertTrue(containsQueryParams, "The URL '\(url)' doesn't contain the expected query params.")
65-
return containsQueryParams && matchesPath
66-
}, filename: "dashboard-200-with-drafts-and-scheduled-posts.json", contentType: .ApplicationJSON)
67-
68-
dashboardServiceRemote.fetch(
69-
cards: ["posts", "todays_stats"],
70-
forBlogID: 165243437,
71-
deviceId: nil
72-
) { _ in
73-
expect.fulfill()
74-
} failure: { error in
75-
XCTFail("Dashboard cards request failed: \(error.localizedDescription)")
76-
expect.fulfill()
77-
}
78-
79-
waitForExpectations(timeout: timeout, handler: nil)
80-
}
81-
8252
// Return the cards when the request succeeds
8353
//
8454
func testRequestCards() {

0 commit comments

Comments
 (0)