-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into issue-template-config
- Loading branch information
Showing
20 changed files
with
418 additions
and
460 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
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,81 @@ | ||
import { http, HttpResponse } from "msw"; | ||
import { setupServer } from "msw/node"; | ||
|
||
import { apiBaseUrl } from "../utils/internal"; | ||
import { buildAuthorization } from "../utils/public"; | ||
import { getUserCompletionProgress } from "./getUserCompletionProgress"; | ||
import type { GetUserCompletionProgressResponse } from "./models"; | ||
|
||
const server = setupServer(); | ||
|
||
describe("Function: getUserCompletionProgress", () => { | ||
// MSW Setup | ||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
it("is defined #sanity", () => { | ||
// ASSERT | ||
expect(getUserCompletionProgress).toBeDefined(); | ||
}); | ||
|
||
it("retrieves completion progress by username", async () => { | ||
// ARRANGE | ||
const authorization = buildAuthorization({ | ||
userName: "mockUserName", | ||
webApiKey: "mockWebApiKey" | ||
}); | ||
|
||
const mockResponse: GetUserCompletionProgressResponse = { | ||
Count: 1, | ||
Total: 1, | ||
Results: [ | ||
{ | ||
GameID: 680, | ||
Title: "Game & Watch Gallery", | ||
ImageIcon: "/Images/042952.png", | ||
ConsoleID: 4, | ||
ConsoleName: "Game Boy", | ||
MaxPossible: 27, | ||
NumAwarded: 8, | ||
NumAwardedHardcore: 8, | ||
MostRecentAwardedDate: "2022-07-26T23:56:15+00:00", | ||
HighestAwardKind: null, | ||
HighestAwardDate: null | ||
} | ||
] | ||
}; | ||
|
||
server.use( | ||
http.get(`${apiBaseUrl}/API_GetUserCompletionProgress.php`, () => | ||
HttpResponse.json(mockResponse) | ||
) | ||
); | ||
|
||
// ACT | ||
const response = await getUserCompletionProgress(authorization, { | ||
userName: "xelnia" | ||
}); | ||
|
||
// ASSERT | ||
expect(response).toEqual({ | ||
count: 1, | ||
total: 1, | ||
results: [ | ||
{ | ||
gameId: 680, | ||
title: "Game & Watch Gallery", | ||
imageIcon: "/Images/042952.png", | ||
consoleId: 4, | ||
consoleName: "Game Boy", | ||
maxPossible: 27, | ||
numAwarded: 8, | ||
numAwardedHardcore: 8, | ||
mostRecentAwardedDate: "2022-07-26T23:56:15+00:00", | ||
highestAwardKind: null, | ||
highestAwardDate: null | ||
} | ||
] | ||
}); | ||
}); | ||
}); |
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,83 @@ | ||
import { | ||
apiBaseUrl, | ||
buildRequestUrl, | ||
call, | ||
serializeProperties | ||
} from "../utils/internal"; | ||
import type { AuthObject } from "../utils/public"; | ||
import type { | ||
GetUserCompletionProgressResponse, | ||
UserCompletionProgress | ||
} from "./models"; | ||
|
||
/** | ||
* A call to this function will retrieve a given user's completion | ||
* progress, targeted by their username. | ||
* | ||
* @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 progress 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 userCompletionProgress = await getUserCompletionProgress( | ||
* authorization, | ||
* { userName: "xelnia" } | ||
* ); | ||
* ``` | ||
* | ||
* @returns | ||
* ``` | ||
* { | ||
* "count": 100, | ||
* "total": 752, | ||
* "results": [ | ||
* { | ||
gameId: 11406, | ||
title: 'Mortal Kombat 4', | ||
imageIcon: '/Images/042133.png', | ||
consoleId: 12, | ||
consoleName: 'PlayStation', | ||
maxPossible: 131, | ||
numAwarded: 131, | ||
numAwardedHardcore: 131, | ||
mostRecentAwardedDate: '2022-08-07T18:24:44+00:00', | ||
highestAwardKind: 'mastered', | ||
highestAwardDate: '2022-08-07T18:24:44+00:00' | ||
* } | ||
* ] | ||
* } | ||
* ``` | ||
*/ | ||
export const getUserCompletionProgress = async ( | ||
authorization: AuthObject, | ||
payload: { userName: string; offset?: number; count?: number } | ||
): Promise<UserCompletionProgress> => { | ||
const { userName, offset, count } = payload; | ||
|
||
const params: Record<string, string | number> = { | ||
u: userName | ||
}; | ||
if (offset) { | ||
params["o"] = offset; | ||
} | ||
if (count) { | ||
params["c"] = count; | ||
} | ||
|
||
const url = buildRequestUrl( | ||
apiBaseUrl, | ||
"/API_GetUserCompletionProgress.php", | ||
authorization, | ||
params | ||
); | ||
|
||
const rawResponse = await call<GetUserCompletionProgressResponse>({ 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { http, HttpResponse } from "msw"; | ||
import { setupServer } from "msw/node"; | ||
|
||
import { apiBaseUrl } from "../utils/internal"; | ||
import { buildAuthorization } from "../utils/public"; | ||
import { getUserProfile } from "./getUserProfile"; | ||
import type { GetUserProfileResponse } from "./models"; | ||
|
||
const server = setupServer(); | ||
|
||
describe("Function: getUserProfile", () => { | ||
// MSW Setup | ||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
it("is defined #sanity", () => { | ||
// ASSERT | ||
expect(getUserProfile).toBeDefined(); | ||
}); | ||
|
||
it("given a username, retrieves minimal user profile information about the user", async () => { | ||
// ARRANGE | ||
const authorization = buildAuthorization({ | ||
userName: "mockUserName", | ||
webApiKey: "mockWebApiKey" | ||
}); | ||
|
||
const mockResponse: GetUserProfileResponse = { | ||
User: "MaxMilyin", | ||
UserPic: "/UserPic/MaxMilyin.png", | ||
MemberSince: "2016-01-02 00:43:04", | ||
RichPresenceMsg: | ||
"Playing ~Hack~ 11th Annual Vanilla Level Design Contest, The", | ||
LastGameID: 19_504, | ||
ContribCount: 0, | ||
ContribYield: 0, | ||
TotalPoints: 399_597, | ||
TotalSoftcorePoints: 0, | ||
TotalTruePoints: 1_599_212, | ||
Permissions: 1, | ||
Untracked: 0, | ||
ID: 16_446, | ||
UserWallActive: 1, | ||
Motto: "Join me on Twitch! GameSquadSquad for live RA" | ||
}; | ||
|
||
server.use( | ||
http.get(`${apiBaseUrl}/API_GetUserProfile.php`, () => | ||
HttpResponse.json(mockResponse) | ||
) | ||
); | ||
|
||
// ACT | ||
const response = await getUserProfile(authorization, { | ||
userName: "WCopeland" | ||
}); | ||
|
||
// ASSERT | ||
expect(response).toEqual({ | ||
user: "MaxMilyin", | ||
userPic: "/UserPic/MaxMilyin.png", | ||
memberSince: "2016-01-02 00:43:04", | ||
richPresenceMsg: | ||
"Playing ~Hack~ 11th Annual Vanilla Level Design Contest, The", | ||
lastGameId: 19_504, | ||
contribCount: 0, | ||
contribYield: 0, | ||
totalPoints: 399_597, | ||
totalSoftcorePoints: 0, | ||
totalTruePoints: 1_599_212, | ||
permissions: 1, | ||
untracked: false, | ||
id: 16_446, | ||
userWallActive: true, | ||
motto: "Join me on Twitch! GameSquadSquad for live RA" | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.