Skip to content

Commit

Permalink
achievements-app#126 - change naming for purchased games functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
alekpentchev committed Mar 28, 2023
1 parent 1bf9c5d commit 5b7ca8a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface GamesLibraryForUserResponse {
import { TitlePlatform } from "./title-platform.model";

export interface GetUserPurchasedGamesResponse {
data: {
purchasedTitlesRetrieve: {
/**
Expand All @@ -13,12 +15,12 @@ export interface GamesLibraryForUserResponse {
/**
* The list of games in the library.
*/
games: Array<GameLibraryTitle>;
games: Array<PurchasedGame>;
};
};
}

export interface GameLibraryTitle {
export interface PurchasedGame {
/**
* The type of resource retrieved.
*
Expand All @@ -43,7 +45,7 @@ export interface GameLibraryTitle {
* "entitlementId": "UP4433-CUSA18779_00-DUNGEONSPS400000"
* ```
*/
entitlementId: string;
entitlementId: string | null;

/**
* The image of the game.
Expand All @@ -56,12 +58,12 @@ export interface GameLibraryTitle {
* }
* ```
*/
image: GameLibraryImage;
image: GameImage;

/**
* Whether the game is active or not.
*/
isActive: boolean;
isActive: boolean | null;

/**
* Whether the game is downloadable or not.
Expand Down Expand Up @@ -91,7 +93,7 @@ export interface GameLibraryTitle {
* platform: "PS4"
* ```
*/
platform: string;
platform: TitlePlatform | "UNKNOWN";

/**
* The ID of the product.
Expand All @@ -101,7 +103,7 @@ export interface GameLibraryTitle {
* productId: "UP4433-CUSA18779_00"
* ```
*/
productId: string;
productId: string | null;

/**
* The subscription service associated with the game.
Expand All @@ -111,7 +113,7 @@ export interface GameLibraryTitle {
* subscriptionService: "PS_PLUS"
* ```
*/
subscriptionService: string;
subscriptionService: "NONE" | string;

/**
* The ID of the title.
Expand All @@ -124,7 +126,7 @@ export interface GameLibraryTitle {
titleId: string;
}

export interface GameLibraryImage {
export interface GameImage {
__typename: string;
url: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import { rest } from "msw";
import { setupServer } from "msw/node";

import { AuthorizationPayload } from "../models";
import { GamesLibraryForUserResponse } from "../models/games-library-for-user.model";
import { getUserGamesLibrary } from "./getUserGamesLibrary";
import { GetUserPurchasedGamesResponse } from "../models/user-purchased-games-response.model";
import { getUserPurchasedGames } from "./getUserPurchasedGames";
import { USER_GAMES_BASE_URL } from "./USER_GAMES_BASE_URL";

const server = setupServer();

describe("Function: getUserGamesLibrary", () => {
describe("Function: getUserPurchasedGames", () => {
// MSW Setup
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

it("is defined #sanity", () => {
// ASSERT
expect(getUserGamesLibrary).toBeDefined();
expect(getUserPurchasedGames).toBeDefined();
});

it("retrieve the games library for a given user", async () => {
Expand All @@ -25,13 +25,13 @@ describe("Function: getUserGamesLibrary", () => {
accessToken: "mockAccessToken"
};

const mockResponse: GamesLibraryForUserResponse = {
const mockResponse: GetUserPurchasedGamesResponse = {
data: {
purchasedTitlesRetrieve: {
__typename: "GameList",
games: [
{
__typename: "GameLibraryTitle",
__typename: "PurchasedGame",
conceptId: null,
entitlementId: "UP4433-CUSA18779_00-DUNGEONSPS400000",
image: {
Expand All @@ -48,7 +48,7 @@ describe("Function: getUserGamesLibrary", () => {
titleId: "CUSA18779_00"
},
{
__typename: "GameLibraryTitle",
__typename: "PurchasedGame",
conceptId: null,
entitlementId: "UP0006-CUSA23249_00-KINGSTONGAME0000",
image: {
Expand Down Expand Up @@ -76,7 +76,7 @@ describe("Function: getUserGamesLibrary", () => {
);

// ACT
const response = await getUserGamesLibrary(mockAuthorization);
const response = await getUserPurchasedGames(mockAuthorization);
// ASSERT
expect(response).toEqual(mockResponse);
});
Expand All @@ -102,6 +102,6 @@ describe("Function: getUserGamesLibrary", () => {
);

// ASSERT
await expect(getUserGamesLibrary(mockAuthorization)).rejects.toThrow();
await expect(getUserPurchasedGames(mockAuthorization)).rejects.toThrow();
});
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// import { AuthorizationPayload, ProfileFromUserNameResponse } from "../models";

import { AuthorizationPayload } from "../models";
import { GamesLibraryForUserResponse } from "../models/games-library-for-user.model";
import { GetUserPurchasedGamesResponse } from "../models/user-purchased-games-response.model";
import { call } from "../utils/call";
import { USER_GAMES_BASE_URL } from "./USER_GAMES_BASE_URL";

export type GetUserGamesLibraryOptions = {
export type GetUserPurchasedGamesOptions = {
platform?: Array<"ps4" | "ps5">;
size?: number;
start?: number;
Expand All @@ -15,7 +15,7 @@ export type GetUserGamesLibraryOptions = {
subscriptionService?: string;
};

const defaultOptions: GetUserGamesLibraryOptions = {
const defaultOptions: GetUserPurchasedGamesOptions = {
platform: ["ps4", "ps5"],
size: 500,
start: 0,
Expand All @@ -39,9 +39,9 @@ const defaultOptions: GetUserGamesLibraryOptions = {
* @param options.isActive Whether to return active games only. Defaults to `true`.
* @param options.subscriptionService The subscription service to filter by. Defaults to `"NONE"`.
*/
export const getUserGamesLibrary = async (
export const getUserPurchasedGames = async (
authorization: AuthorizationPayload,
options: Partial<GetUserGamesLibraryOptions> = defaultOptions
options: Partial<GetUserPurchasedGamesOptions> = defaultOptions
): Promise<any> => {
const operationName = "getPurchasedGameList";
const variables = encodeURIComponent(JSON.stringify(options));
Expand All @@ -50,7 +50,7 @@ export const getUserGamesLibrary = async (
);
const url = `${USER_GAMES_BASE_URL}?operationName=${operationName}&variables=${variables}&extensions=${extensions}`;

const response = await call<GamesLibraryForUserResponse>(
const response = await call<GetUserPurchasedGamesResponse>(
{ url },
authorization
);
Expand Down

0 comments on commit 5b7ca8a

Please sign in to comment.