-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new getUserWantToPlayList() function
- Loading branch information
1 parent
3f3a29e
commit 43b4eb4
Showing
10 changed files
with
196 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,75 @@ | ||
/* eslint-disable sonarjs/no-duplicate-string */ | ||
|
||
import { http, HttpResponse } from "msw"; | ||
import { setupServer } from "msw/node"; | ||
|
||
import { apiBaseUrl } from "../utils/internal"; | ||
import { buildAuthorization } from "../utils/public"; | ||
import { getUserWantToPlayList } from "./getUserWantToPlayList"; | ||
import type { GetUserWantToPlayListResponse } from "./models"; | ||
|
||
const server = setupServer(); | ||
|
||
describe("Function: getUserWantToPlayList", () => { | ||
// MSW Setup | ||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
it("is defined #sanity", () => { | ||
// ASSERT | ||
expect(getUserWantToPlayList).toBeDefined(); | ||
}); | ||
|
||
it('given a username, retrieves that users "Want To Play Games"', async () => { | ||
// ARRANGE | ||
const authorization = buildAuthorization({ | ||
username: "mockUserName", | ||
webApiKey: "mockWebApiKey", | ||
}); | ||
|
||
const mockResponse: GetUserWantToPlayListResponse = { | ||
Count: 100, | ||
Total: 1287, | ||
Results: [ | ||
{ | ||
ID: 20_246, | ||
Title: "~Hack~ Knuckles the Echidna in Sonic the Hedgehog", | ||
ImageIcon: "/Images/074560.png", | ||
ConsoleID: 1, | ||
ConsoleName: "Genesis/Mega Drive", | ||
PointsTotal: 1500, | ||
AchievementsPublished: 50, | ||
}, | ||
], | ||
}; | ||
|
||
server.use( | ||
http.get(`${apiBaseUrl}/API_GetUserWantToPlayList.php`, () => | ||
HttpResponse.json(mockResponse) | ||
) | ||
); | ||
|
||
// ACT | ||
const response = await getUserWantToPlayList(authorization, { | ||
username: "xelnia", | ||
}); | ||
|
||
// ASSERT | ||
expect(response).toEqual({ | ||
count: 100, | ||
total: 1287, | ||
results: [ | ||
{ | ||
id: 20_246, | ||
title: "~Hack~ Knuckles the Echidna in Sonic the Hedgehog", | ||
imageIcon: "/Images/074560.png", | ||
consoleId: 1, | ||
consoleName: "Genesis/Mega Drive", | ||
pointsTotal: 1500, | ||
achievementsPublished: 50, | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
This file contains 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,76 @@ | ||
import { | ||
apiBaseUrl, | ||
buildRequestUrl, | ||
call, | ||
serializeProperties, | ||
} from "../utils/internal"; | ||
import type { AuthObject } from "../utils/public"; | ||
import type { | ||
GetUserWantToPlayListResponse, | ||
UserWantToPlayList, | ||
} from "./models"; | ||
|
||
/** | ||
* A call to this function will retrieve a user's "Want to Play Games" list. | ||
* | ||
* @param authorization An object containing your username and webApiKey. | ||
* This can be constructed with `buildAuthorization()`. | ||
* | ||
* @param payload.username The user for which to retrieve the | ||
* want to play games list for. | ||
* | ||
* @param payload.offset Defaults to 0. The number of entries to skip. | ||
* | ||
* @param payload.count Defaults to 100, has a max of 500. | ||
* | ||
* @example | ||
* ``` | ||
* const wantToPlayList = await getUserWantToPlayList( | ||
* authorization, | ||
* { username: "wv_pinball" } | ||
* ); | ||
* ``` | ||
* | ||
* @returns An object containing a user's list of "Want to Play Games". | ||
* ```json | ||
* { | ||
* "count": 100, | ||
* "total": 1287, | ||
* "results": [ | ||
* { | ||
* "id": 20246, | ||
* "title": "~Hack~ Knuckles the Echidna in Sonic the Hedgehog", | ||
* "imageIcon": "/Images/074560.png", | ||
* "consoleID": 1, | ||
* "consoleName": "Genesis/Mega Drive", | ||
* "pointsTotal": 1500, | ||
* "achievementsPublished": 50 | ||
* } | ||
* ] | ||
* } | ||
* ``` | ||
*/ | ||
export const getUserWantToPlayList = async ( | ||
authorization: AuthObject, | ||
payload: { username: string; offset?: number; count?: number } | ||
): Promise<UserWantToPlayList> => { | ||
const queryParams: Record<string, any> = {}; | ||
queryParams.u = payload.username; | ||
if (payload?.offset) { | ||
queryParams.o = payload.offset; | ||
} | ||
if (payload?.count) { | ||
queryParams.c = payload.count; | ||
} | ||
|
||
const url = buildRequestUrl( | ||
apiBaseUrl, | ||
"/API_GetUserWantToPlayList.php", | ||
authorization, | ||
queryParams | ||
); | ||
|
||
const rawResponse = await call<GetUserWantToPlayListResponse>({ url }); | ||
|
||
return serializeProperties(rawResponse); | ||
}; |
This file contains 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
13 changes: 13 additions & 0 deletions
13
src/user/models/get-user-want-to-play-list-response.model.ts
This file contains 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,13 @@ | ||
export interface GetUserWantToPlayListResponse { | ||
Count: number; | ||
Total: number; | ||
Results: Array<{ | ||
ID: number; | ||
Title: string; | ||
ImageIcon: string; | ||
ConsoleID: number; | ||
ConsoleName: string; | ||
PointsTotal: number; | ||
AchievementsPublished: number; | ||
}>; | ||
} |
This file contains 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 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,13 @@ | ||
export interface UserWantToPlayList { | ||
count: number; | ||
total: number; | ||
results: Array<{ | ||
id: number; | ||
title: string; | ||
imageIcon: string; | ||
consoleId: number; | ||
consoleName: string; | ||
pointsTotal: number; | ||
achievementsPublished: number; | ||
}>; | ||
} |