Files
artcraft/test/app/Classes/ApiManager/utils/testGetEndpoints.ts
T
wilandwil ef6685c2d1 API2.6 / that's all of the ApiManager v2 (#505)
commit 15fb01eccadc0b53c51624a17dd0f10e8bb85885
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Wed Jun 19 07:53:52 2024 -0400

    Final endpoints

commit 9085f5060ec955d7f85d181018ef020a4f3645a0
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Tue Jun 18 18:18:18 2024 -0400

    Start simplifying tests

commit a3d24422766f461a6ca16548de7f1b3437f0ef6a
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Tue Jun 18 11:00:46 2024 -0400

    unit tests for weights

commit e67b28c9f204d29d73345f4ab764a99e411f26fc
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Tue Jun 18 09:08:45 2024 -0400

    unit tests for weights

commit e3aaa1e0ed9401b005a51e849eefd4dd6ce88335
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Tue Jun 18 06:45:42 2024 -0400

    All weight enpoints, no unit tests

commit f44e996a593a55a5279551fd373b2cdd782006b8
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Tue Jun 18 06:40:20 2024 -0400

    Initial weights endpoints

commit eec57936558b8cbd820b76e7399a9d62e881d3c6
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Sun Jun 16 08:29:12 2024 -0400

    Add moderation endpoint

commit 9f3ce2c84c84a3c4a5a6c48006b3e5664900793d
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Sun Jun 16 07:52:28 2024 -0400

    Add to Jobs enpoints

commit 1b96d4394af97074ab2cf2fe36d6d83cc5c9cde8
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Sun Jun 16 07:39:15 2024 -0400

    Add featured items endpoints

commit 350afd53736d5dd16c44c4bf3951fe1cbf192593
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Sun Jun 16 07:19:16 2024 -0400

    Add conversion endpoint

commit fa183d912f1838432e0e9873df5a5620dfa3c614
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Sat Jun 15 21:32:26 2024 -0400

    add comments endpoints

commit 5195555233bd2f002e820cd892ab77bf6d7c908c
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Sat Jun 15 21:04:09 2024 -0400

    add beta keys endpoints

commit 0e87644c0a059bc1f7e5c5886ee2f8e9f4703511
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Sat Jun 15 19:49:01 2024 -0400

    Add analytics

commit 2bbf3017fbedc4bd4bbbabad5861158b29cff562
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Sat Jun 15 19:33:54 2024 -0400

    user rating

commit 41b7c9262f6f58dbff54205e78430ace1b1bd72c
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Sat Jun 15 07:49:11 2024 -0400

    user bookmarks - fixes and unit tests

commit 8b7d8517903055c633517e3ae85fcaf9b58a085a
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Fri Jun 14 14:22:31 2024 -0400

    add user bookmarks (no tests yet)

commit f74318c296c871bbeb263d093f53fe2f481e7a9c
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Fri Jun 14 10:25:17 2024 -0400

    Add many load functions

commit dbc6ae1bddea6aec9faf7c36d13e44b0dacdad06
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Fri Jun 14 07:57:21 2024 -0400

    add delete media file

commit 5d8a1505d4b656da3e14d6f57fde2f0badecb6b7
Author: Christopher Oliphant <christopheroliphant@christophersmbp.home>
Date:   Fri Jun 14 07:06:07 2024 -0400

    Add rename media file

Co-authored-by: wil <wil@storyteller.ai>
2024-06-19 11:41:18 -04:00

53 lines
1.3 KiB
TypeScript

import { ApiManager } from "~/Classes/ApiManager/ApiManager";
interface TestConfig {
name: string;
function: (...args: any[]) => any;
endpoint: string;
params: any;
}
export default function testGetEndpoints(
api: ApiManager,
testMethod: TestConfig,
mockData: any,
) {
describe(testMethod.name, () => {
afterEach(() => {
jest.clearAllMocks();
});
it("success", async () => {
jest.spyOn(api, "fetch").mockResolvedValue({
...mockData,
success: true,
});
const response = await testMethod.function(testMethod.params);
expect(api.fetch).toHaveBeenCalledWith(testMethod.endpoint, {
method: "GET",
body: undefined,
query: undefined,
});
expect(response).toEqual({
data: mockData,
success: true,
errorMessage: undefined,
});
});
it("exception", async () => {
jest.spyOn(api, "fetch").mockRejectedValue(new Error("server error"));
const response = await testMethod.function(testMethod.params);
expect(api.fetch).toHaveBeenCalledWith(testMethod.endpoint, {
method: "GET",
body: undefined,
query: undefined,
});
expect(response).toEqual({
success: false,
errorMessage: "server error",
});
});
});
}