mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-02-16 17:27:41 +00:00
extend test-coverage for admin-api
This commit is contained in:
parent
eea9a8852b
commit
0de91ca3af
@ -114,13 +114,12 @@ export class PokerogueAdminApi extends ApiBase {
|
||||
/**
|
||||
* Search an account.
|
||||
* @param params The {@linkcode SearchAccountRequest} to send
|
||||
* @returns TODO: add this comment
|
||||
* @returns an array of {@linkcode SearchAccountResponse} and error. Both can be `undefined`
|
||||
*/
|
||||
public async searchAccount(params: SearchAccountRequest): Promise<[data?: SearchAccountResponse, error?: string]> {
|
||||
try {
|
||||
const urlSearchParams = this.toUrlSearchParams(params);
|
||||
const response = await this.doGet(`/admin/account/adminSearch?${urlSearchParams}`);
|
||||
console.log("response", response);
|
||||
|
||||
if (response.ok) {
|
||||
const resData: SearchAccountResponse = await response.json();
|
||||
|
@ -1,4 +1,11 @@
|
||||
import type { LinkAccountToDiscordIdRequest } from "#app/@types/PokerogueAdminApi";
|
||||
import type {
|
||||
LinkAccountToDiscordIdRequest,
|
||||
LinkAccountToGoogledIdRequest,
|
||||
SearchAccountRequest,
|
||||
SearchAccountResponse,
|
||||
UnlinkAccountFromDiscordIdRequest,
|
||||
UnlinkAccountFromGoogledIdRequest,
|
||||
} from "#app/@types/PokerogueAdminApi";
|
||||
import { PokerogueAdminApi } from "#app/plugins/api/pokerogue-admin-api";
|
||||
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
||||
import { http, HttpResponse } from "msw";
|
||||
@ -17,33 +24,209 @@ describe("Pokerogue Admin API", () => {
|
||||
vi.spyOn(console, "warn");
|
||||
});
|
||||
|
||||
describe("Link Account to Discord Title Stats", () => {
|
||||
describe("Link Account to Discord", () => {
|
||||
const params: LinkAccountToDiscordIdRequest = { username: "test", discordId: "test-12575756" };
|
||||
|
||||
it("should return true on SUCCESS", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/discord-link`, () => HttpResponse.json(true)));
|
||||
it("should return null on SUCCESS", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/discordLink`, () => HttpResponse.json(true)));
|
||||
|
||||
const success = await adminApi.linkAccountToDiscord(params);
|
||||
|
||||
expect(success).toBe(true);
|
||||
expect(success).toBeNull();
|
||||
});
|
||||
|
||||
it("should return false and report a warning on FAILURE", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/discord-link`, () => new HttpResponse("", { status: 400 })));
|
||||
it("should return a ERR_GENERIC and report a warning on FAILURE", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/discordLink`, () => new HttpResponse("", { status: 400 })));
|
||||
|
||||
const success = await adminApi.linkAccountToDiscord(params);
|
||||
|
||||
expect(success).toBe(false);
|
||||
expect(success).toBe(adminApi.ERR_GENERIC);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not link account with discord!", 400, "Bad Request");
|
||||
});
|
||||
|
||||
it("should return false and report a warning on ERROR", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/discord-link`, () => HttpResponse.error()));
|
||||
it("should return a ERR_USERNAME_NOT_FOUND and report a warning on 404", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/discordLink`, () => new HttpResponse("", { status: 404 })));
|
||||
|
||||
const success = await adminApi.linkAccountToDiscord(params);
|
||||
|
||||
expect(success).toBe(false);
|
||||
expect(success).toBe(adminApi.ERR_USERNAME_NOT_FOUND);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not link account with discord!", 404, "Not Found");
|
||||
});
|
||||
|
||||
it("should return a ERR_GENERIC and report a warning on ERROR", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/discordLink`, () => HttpResponse.error()));
|
||||
|
||||
const success = await adminApi.linkAccountToDiscord(params);
|
||||
|
||||
expect(success).toBe(adminApi.ERR_GENERIC);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not link account with discord!", expect.any(Error));
|
||||
});
|
||||
});
|
||||
|
||||
describe("Unlink Account from Discord", () => {
|
||||
const params: UnlinkAccountFromDiscordIdRequest = { username: "test", discordId: "test-12575756" };
|
||||
|
||||
it("should return null on SUCCESS", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/discordUnlink`, () => HttpResponse.json(true)));
|
||||
|
||||
const success = await adminApi.unlinkAccountFromDiscord(params);
|
||||
|
||||
expect(success).toBeNull();
|
||||
});
|
||||
|
||||
it("should return a ERR_GENERIC and report a warning on FAILURE", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/discordUnlink`, () => new HttpResponse("", { status: 400 })));
|
||||
|
||||
const success = await adminApi.unlinkAccountFromDiscord(params);
|
||||
|
||||
expect(success).toBe(adminApi.ERR_GENERIC);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not unlink account from discord!", 400, "Bad Request");
|
||||
});
|
||||
|
||||
it("should return a ERR_USERNAME_NOT_FOUND and report a warning on 404", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/discordUnlink`, () => new HttpResponse("", { status: 404 })));
|
||||
|
||||
const success = await adminApi.unlinkAccountFromDiscord(params);
|
||||
|
||||
expect(success).toBe(adminApi.ERR_USERNAME_NOT_FOUND);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not unlink account from discord!", 404, "Not Found");
|
||||
});
|
||||
|
||||
it("should return a ERR_GENERIC and report a warning on ERROR", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/discordUnlink`, () => HttpResponse.error()));
|
||||
|
||||
const success = await adminApi.unlinkAccountFromDiscord(params);
|
||||
|
||||
expect(success).toBe(adminApi.ERR_GENERIC);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not unlink account from discord!", expect.any(Error));
|
||||
});
|
||||
});
|
||||
|
||||
describe("Link Account to Google", () => {
|
||||
const params: LinkAccountToGoogledIdRequest = { username: "test", googleId: "test-12575756" };
|
||||
|
||||
it("should return null on SUCCESS", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/googleLink`, () => HttpResponse.json(true)));
|
||||
|
||||
const success = await adminApi.linkAccountToGoogleId(params);
|
||||
|
||||
expect(success).toBeNull();
|
||||
});
|
||||
|
||||
it("should return a ERR_GENERIC and report a warning on FAILURE", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/googleLink`, () => new HttpResponse("", { status: 400 })));
|
||||
|
||||
const success = await adminApi.linkAccountToGoogleId(params);
|
||||
|
||||
expect(success).toBe(adminApi.ERR_GENERIC);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not link account with google!", 400, "Bad Request");
|
||||
});
|
||||
|
||||
it("should return a ERR_USERNAME_NOT_FOUND and report a warning on 404", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/googleLink`, () => new HttpResponse("", { status: 404 })));
|
||||
|
||||
const success = await adminApi.linkAccountToGoogleId(params);
|
||||
|
||||
expect(success).toBe(adminApi.ERR_USERNAME_NOT_FOUND);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not link account with google!", 404, "Not Found");
|
||||
});
|
||||
|
||||
it("should return a ERR_GENERIC and report a warning on ERROR", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/googleLink`, () => HttpResponse.error()));
|
||||
|
||||
const success = await adminApi.linkAccountToGoogleId(params);
|
||||
|
||||
expect(success).toBe(adminApi.ERR_GENERIC);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not link account with google!", expect.any(Error));
|
||||
});
|
||||
});
|
||||
|
||||
describe("Unlink Account from Google", () => {
|
||||
const params: UnlinkAccountFromGoogledIdRequest = { username: "test", googleId: "test-12575756" };
|
||||
|
||||
it("should return null on SUCCESS", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/googleUnlink`, () => HttpResponse.json(true)));
|
||||
|
||||
const success = await adminApi.unlinkAccountFromGoogleId(params);
|
||||
|
||||
expect(success).toBeNull();
|
||||
});
|
||||
|
||||
it("should return a ERR_GENERIC and report a warning on FAILURE", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/googleUnlink`, () => new HttpResponse("", { status: 400 })));
|
||||
|
||||
const success = await adminApi.unlinkAccountFromGoogleId(params);
|
||||
|
||||
expect(success).toBe(adminApi.ERR_GENERIC);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not unlink account from google!", 400, "Bad Request");
|
||||
});
|
||||
|
||||
it("should return a ERR_USERNAME_NOT_FOUND and report a warning on 404", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/googleUnlink`, () => new HttpResponse("", { status: 404 })));
|
||||
|
||||
const success = await adminApi.unlinkAccountFromGoogleId(params);
|
||||
|
||||
expect(success).toBe(adminApi.ERR_USERNAME_NOT_FOUND);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not unlink account from google!", 404, "Not Found");
|
||||
});
|
||||
|
||||
it("should return a ERR_GENERIC and report a warning on ERROR", async () => {
|
||||
server.use(http.post(`${apiBase}/admin/account/googleUnlink`, () => HttpResponse.error()));
|
||||
|
||||
const success = await adminApi.unlinkAccountFromGoogleId(params);
|
||||
|
||||
expect(success).toBe(adminApi.ERR_GENERIC);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not unlink account from google!", expect.any(Error));
|
||||
});
|
||||
});
|
||||
|
||||
describe("Search Account", () => {
|
||||
const params: SearchAccountRequest = { username: "test" };
|
||||
|
||||
it("should return [data, undefined] on SUCCESS", async () => {
|
||||
const responseData: SearchAccountResponse = {
|
||||
username: "test",
|
||||
discordId: "discord-test-123",
|
||||
googleId: "google-test-123",
|
||||
lastLoggedIn: "2022-01-01",
|
||||
registered: "2022-01-01",
|
||||
};
|
||||
server.use(http.get(`${apiBase}/admin/account/adminSearch`, () => HttpResponse.json(responseData)));
|
||||
|
||||
const [ data, err ] = await adminApi.searchAccount(params);
|
||||
|
||||
expect(data).toStrictEqual(responseData);
|
||||
expect(err).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should return [undefined, ERR_GENERIC] and report a warning on on FAILURE", async () => {
|
||||
server.use(http.get(`${apiBase}/admin/account/adminSearch`, () => new HttpResponse("", { status: 400 })));
|
||||
|
||||
const [ data, err ] = await adminApi.searchAccount(params);
|
||||
|
||||
expect(data).toBeUndefined();
|
||||
expect(err).toBe(adminApi.ERR_GENERIC);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not find account!", 400, "Bad Request");
|
||||
});
|
||||
|
||||
it("should return [undefined, ERR_USERNAME_NOT_FOUND] and report a warning on on 404", async () => {
|
||||
server.use(http.get(`${apiBase}/admin/account/adminSearch`, () => new HttpResponse("", { status: 404 })));
|
||||
|
||||
const [ data, err ] = await adminApi.searchAccount(params);
|
||||
|
||||
expect(data).toBeUndefined();
|
||||
expect(err).toBe(adminApi.ERR_USERNAME_NOT_FOUND);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not find account!", 404, "Not Found");
|
||||
});
|
||||
|
||||
it("should return [undefined, ERR_GENERIC] and report a warning on on ERROR", async () => {
|
||||
server.use(http.get(`${apiBase}/admin/account/adminSearch`, () => HttpResponse.error()));
|
||||
|
||||
const [ data, err ] = await adminApi.searchAccount(params);
|
||||
|
||||
expect(data).toBeUndefined();
|
||||
expect(err).toBe(adminApi.ERR_GENERIC);
|
||||
expect(console.warn).toHaveBeenCalledWith("Could not find account!", expect.any(Error));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user