Skip to content

Commit

Permalink
Assignments: Fix started_at Regression (#310)
Browse files Browse the repository at this point in the history
* Assignments: Fix `started_at` Regression

Signed-off-by: Collin Bachman <3395010+bachmacintosh@users.noreply.github.com>

* Keep started_at optional

Signed-off-by: Collin Bachman <3395010+bachmacintosh@users.noreply.github.com>

* Fix validatePayload

Signed-off-by: Collin Bachman <3395010+bachmacintosh@users.noreply.github.com>

* Update example

Signed-off-by: Collin Bachman <3395010+bachmacintosh@users.noreply.github.com>

* Update tests

Signed-off-by: Collin Bachman <3395010+bachmacintosh@users.noreply.github.com>

* Bump version

Signed-off-by: Collin Bachman <3395010+bachmacintosh@users.noreply.github.com>

---------

Signed-off-by: Collin Bachman <3395010+bachmacintosh@users.noreply.github.com>
  • Loading branch information
bachmacintosh authored Oct 27, 2024
1 parent 65f108e commit d435f71
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ async function startAssignment(id: number, started_at?: WKDatableString | Date):
let payload: WKAssignmentPayload = {};
if (typeof started_at !== "undefined" && (isWKDatableString(started_at) || started_at instanceof Date)) {
payload = {
started_at,
assignment: {
started_at,
},
};
}
const request = new WKRequestFactory({ apiToken: WANIKANI_API_TOKEN, revision: WK_API_REVISION }).assignments.start(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bachmacintosh/wanikani-api-types",
"version": "1.6.0",
"version": "1.6.1",
"description": "Regularly updated type definitions for the WaniKani API",
"keywords": [
"wanikani",
Expand Down
11 changes: 8 additions & 3 deletions src/assignments/v20170710.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ export interface WKAssignmentParameters extends WKCollectionParameters {
*/
export interface WKAssignmentPayload {
/**
* When the assignment was started. Must be greater than or equal to the assignment's `unlocked_at` date.
*/
started_at?: Date | WKDatableString;
* Specify properties of the Assignment; currently only `started_at` is supported.
*/
assignment: {
/**
* When the assignment was started. Must be greater than or equal to the assignment's `unlocked_at` date.
*/
started_at?: Date | WKDatableString;
};
}
4 changes: 3 additions & 1 deletion src/base/v20170710.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,9 @@ export function validatePayload<T extends keyof WKPayloadMap>(type: T, payload:

/* Create required dummy parameters */
const assignmentStartPayload: Required<WKAssignmentPayload> = {
started_at: new Date(),
assignment: {
started_at: new Date(),
},
};
const reviewCreatePayloadAssignment: Required<WKReviewPayload> = {
review: {
Expand Down
4 changes: 3 additions & 1 deletion tests/base/validatePayload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import type { WKReviewPayload } from "../../src/reviews/v20170710";
import { validatePayload } from "../../src/base/v20170710";

const assignmentStartPayload: Required<WKAssignmentPayload> = {
started_at: new Date(),
assignment: {
started_at: new Date(),
},
};
const reviewCreatePayloadAssignment: Required<WKReviewPayload> = {
review: {
Expand Down
6 changes: 4 additions & 2 deletions tests/requests/WKRequestFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ it("Returns PUT request for starting an Assignment", () => {
"Content-Type": "application/json",
"X-Forwarded-For": "192.168.1.1",
};
const expectedBody = `{"started_at":"2023-02-04T15:30:00.000Z"}`;
const expectedBody = `{"assignment":{"started_at":"2023-02-04T15:30:00.000Z"}}`;

const payload: WKAssignmentPayload = {
started_at: new Date("2023-02-04T15:30:00.000Z"),
assignment: {
started_at: new Date("2023-02-04T15:30:00.000Z"),
},
};

const request = wanikani.assignments.start(123, payload, putPostOptions);
Expand Down

0 comments on commit d435f71

Please sign in to comment.