Skip to content

Commit eef43c8

Browse files
authored
feat: add new getUserWantToPlayList() function (#116)
1 parent 3f3a29e commit eef43c8

10 files changed

+196
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Click the function names to open their complete docs on the docs site.
9090
- [`getUserRecentlyPlayedGames()`](https://api-docs.retroachievements.org/v1/get-user-recently-played-games.html) - Get a list of games a user has recently played.
9191
- [`getUserSummary()`](https://api-docs.retroachievements.org/v1/get-user-summary.html) - Get a user's profile metadata.
9292
- [`getUserCompletedGames()`](https://api-docs.retroachievements.org/v1/get-user-completed-games.html) - Deprecated function. Get hardcore and softcore completion metadata about games a user has played.
93+
- [`getUserWantToPlayList()`](https://api-docs.retroachievements.org/v1/get-user-want-to-play-list.html) - Get a user's "Want to Play Games" list.
9394

9495
### Game
9596

src/game/getGameExtended.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ describe("Function: getGameExtended", () => {
7575
);
7676

7777
// ACT
78-
const response = await getGameExtended(authorization, { gameId: 14_402 });
78+
const response = await getGameExtended(authorization, {
79+
gameId: 14_402,
80+
isRequestingUnofficialAchievements: true,
81+
});
7982

8083
// ASSERT
8184
expect(response).toEqual({

src/game/getGameHashes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { GetGameHashesResponse } from "./models";
1010

1111
const server = setupServer();
1212

13-
describe("Function: getGameExtended", () => {
13+
describe("Function: getGameHashes", () => {
1414
// MSW Setup
1515
beforeAll(() => server.listen());
1616
afterEach(() => server.resetHandlers());
@@ -21,7 +21,7 @@ describe("Function: getGameExtended", () => {
2121
expect(getGameHashes).toBeDefined();
2222
});
2323

24-
it("given a game ID, retrieves extended metadata about the game", async () => {
24+
it("given a game ID, retrieves a list of linked hashes", async () => {
2525
// ARRANGE
2626
const authorization = buildAuthorization({
2727
username: "mockUserName",

src/game/getGameHashes.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ import type { GameHashes, GetGameHashesResponse } from "./models";
3030
* @returns An object containing a list of game hashes.
3131
* ```json
3232
* {
33-
* "Results": [
33+
* "results": [
3434
* {
35-
* "MD5": "1b1d9ac862c387367e904036114c4825",
36-
* "Name": "Sonic The Hedgehog (USA, Europe) (Ru) (NewGame).md",
37-
* "Labels": ["nointro", "rapatches"],
38-
* "PatchUrl": "https://github.com/RetroAchievements/RAPatches/raw/main/MD/Translation/Russian/1-Sonic1-Russian.zip"
35+
* "md5": "1b1d9ac862c387367e904036114c4825",
36+
* "name": "Sonic The Hedgehog (USA, Europe) (Ru) (NewGame).md",
37+
* "labels": ["nointro", "rapatches"],
38+
* "patchUrl": "https://github.com/RetroAchievements/RAPatches/raw/main/MD/Translation/Russian/1-Sonic1-Russian.zip"
3939
* },
4040
* {
41-
* "MD5": "1bc674be034e43c96b86487ac69d9293",
42-
* "Name": "Sonic The Hedgehog (USA, Europe).md",
43-
* "Labels": ["nointro"],
44-
* "PatchUrl": null
41+
* "md5": "1bc674be034e43c96b86487ac69d9293",
42+
* "name": "Sonic The Hedgehog (USA, Europe).md",
43+
* "labels": ["nointro"],
44+
* "patchUrl": null
4545
* }
4646
* ]
4747
* }
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* eslint-disable sonarjs/no-duplicate-string */
2+
3+
import { http, HttpResponse } from "msw";
4+
import { setupServer } from "msw/node";
5+
6+
import { apiBaseUrl } from "../utils/internal";
7+
import { buildAuthorization } from "../utils/public";
8+
import { getUserWantToPlayList } from "./getUserWantToPlayList";
9+
import type { GetUserWantToPlayListResponse } from "./models";
10+
11+
const server = setupServer();
12+
13+
describe("Function: getUserWantToPlayList", () => {
14+
// MSW Setup
15+
beforeAll(() => server.listen());
16+
afterEach(() => server.resetHandlers());
17+
afterAll(() => server.close());
18+
19+
it("is defined #sanity", () => {
20+
// ASSERT
21+
expect(getUserWantToPlayList).toBeDefined();
22+
});
23+
24+
it('given a username, retrieves that users "Want To Play Games"', async () => {
25+
// ARRANGE
26+
const authorization = buildAuthorization({
27+
username: "mockUserName",
28+
webApiKey: "mockWebApiKey",
29+
});
30+
31+
const mockResponse: GetUserWantToPlayListResponse = {
32+
Count: 100,
33+
Total: 1287,
34+
Results: [
35+
{
36+
ID: 20_246,
37+
Title: "~Hack~ Knuckles the Echidna in Sonic the Hedgehog",
38+
ImageIcon: "/Images/074560.png",
39+
ConsoleID: 1,
40+
ConsoleName: "Genesis/Mega Drive",
41+
PointsTotal: 1500,
42+
AchievementsPublished: 50,
43+
},
44+
],
45+
};
46+
47+
server.use(
48+
http.get(`${apiBaseUrl}/API_GetUserWantToPlayList.php`, () =>
49+
HttpResponse.json(mockResponse)
50+
)
51+
);
52+
53+
// ACT
54+
const response = await getUserWantToPlayList(authorization, {
55+
username: "xelnia",
56+
});
57+
58+
// ASSERT
59+
expect(response).toEqual({
60+
count: 100,
61+
total: 1287,
62+
results: [
63+
{
64+
id: 20_246,
65+
title: "~Hack~ Knuckles the Echidna in Sonic the Hedgehog",
66+
imageIcon: "/Images/074560.png",
67+
consoleId: 1,
68+
consoleName: "Genesis/Mega Drive",
69+
pointsTotal: 1500,
70+
achievementsPublished: 50,
71+
},
72+
],
73+
});
74+
});
75+
});

src/user/getUserWantToPlayList.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import {
2+
apiBaseUrl,
3+
buildRequestUrl,
4+
call,
5+
serializeProperties,
6+
} from "../utils/internal";
7+
import type { AuthObject } from "../utils/public";
8+
import type {
9+
GetUserWantToPlayListResponse,
10+
UserWantToPlayList,
11+
} from "./models";
12+
13+
/**
14+
* A call to this function will retrieve a user's "Want to Play Games" list.
15+
*
16+
* @param authorization An object containing your username and webApiKey.
17+
* This can be constructed with `buildAuthorization()`.
18+
*
19+
* @param payload.username The user for which to retrieve the
20+
* want to play games list for.
21+
*
22+
* @param payload.offset Defaults to 0. The number of entries to skip.
23+
*
24+
* @param payload.count Defaults to 100, has a max of 500.
25+
*
26+
* @example
27+
* ```
28+
* const wantToPlayList = await getUserWantToPlayList(
29+
* authorization,
30+
* { username: "wv_pinball" }
31+
* );
32+
* ```
33+
*
34+
* @returns An object containing a user's list of "Want to Play Games".
35+
* ```json
36+
* {
37+
* "count": 100,
38+
* "total": 1287,
39+
* "results": [
40+
* {
41+
* "id": 20246,
42+
* "title": "~Hack~ Knuckles the Echidna in Sonic the Hedgehog",
43+
* "imageIcon": "/Images/074560.png",
44+
* "consoleID": 1,
45+
* "consoleName": "Genesis/Mega Drive",
46+
* "pointsTotal": 1500,
47+
* "achievementsPublished": 50
48+
* }
49+
* ]
50+
* }
51+
* ```
52+
*/
53+
export const getUserWantToPlayList = async (
54+
authorization: AuthObject,
55+
payload: { username: string; offset?: number; count?: number }
56+
): Promise<UserWantToPlayList> => {
57+
const queryParams: Record<string, any> = {};
58+
queryParams.u = payload.username;
59+
if (payload?.offset) {
60+
queryParams.o = payload.offset;
61+
}
62+
if (payload?.count) {
63+
queryParams.c = payload.count;
64+
}
65+
66+
const url = buildRequestUrl(
67+
apiBaseUrl,
68+
"/API_GetUserWantToPlayList.php",
69+
authorization,
70+
queryParams
71+
);
72+
73+
const rawResponse = await call<GetUserWantToPlayListResponse>({ url });
74+
75+
return serializeProperties(rawResponse);
76+
};

src/user/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export * from "./getUserProgress";
1212
export * from "./getUserRecentAchievements";
1313
export * from "./getUserRecentlyPlayedGames";
1414
export * from "./getUserSummary";
15+
export * from "./getUserWantToPlayList";
1516
export * from "./models";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface GetUserWantToPlayListResponse {
2+
Count: number;
3+
Total: number;
4+
Results: Array<{
5+
ID: number;
6+
Title: string;
7+
ImageIcon: string;
8+
ConsoleID: number;
9+
ConsoleName: string;
10+
PointsTotal: number;
11+
AchievementsPublished: number;
12+
}>;
13+
}

src/user/models/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export * from "./get-user-progress-response.model";
1313
export * from "./get-user-recent-achievements-response.model";
1414
export * from "./get-user-recently-played-games-response.model";
1515
export * from "./get-user-summary-response.model";
16+
export * from "./get-user-want-to-play-list-response.model";
1617
export * from "./user-awards.model";
1718
export * from "./user-claims.model";
1819
export * from "./user-claims-response.model";
@@ -26,3 +27,4 @@ export * from "./user-progress.model";
2627
export * from "./user-recent-achievement.model";
2728
export * from "./user-recently-played-games.model";
2829
export * from "./user-summary.model";
30+
export * from "./user-want-to-play-list.model";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface UserWantToPlayList {
2+
count: number;
3+
total: number;
4+
results: Array<{
5+
id: number;
6+
title: string;
7+
imageIcon: string;
8+
consoleId: number;
9+
consoleName: string;
10+
pointsTotal: number;
11+
achievementsPublished: number;
12+
}>;
13+
}

0 commit comments

Comments
 (0)