mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-11 16:58:25 +03:00
basic parser tests
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import t from "tap";
|
||||
import { CloseAllConnections } from "../../../../../test-utils/close-connections";
|
||||
import { agta } from "../../../../../test-utils/misc";
|
||||
import { MockJSONFetch } from "../../../../../test-utils/mock-fetch";
|
||||
import ResetDBState from "../../../../../test-utils/reset-db-state";
|
||||
import CreateLogCtx from "../../../../logger/logger";
|
||||
import { ParseArcDDR } from "./parser";
|
||||
|
||||
const logger = CreateLogCtx(__filename);
|
||||
|
||||
t.test("#ParseArcDDR", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("Should iterate over the API.", async (t) => {
|
||||
const mockArcAPI = MockJSONFetch({
|
||||
"https://arc.example.com/api/v1/ddr/16/player_bests?profile_id=profile": {
|
||||
_links: {
|
||||
_next:
|
||||
"https://arc.example.com/api/v1/ddr/16/player_bests?profile_id=profile&page=2",
|
||||
},
|
||||
_items: [1, 2, 3],
|
||||
},
|
||||
"https://arc.example.com/api/v1/ddr/16/player_bests?profile_id=profile&page=2": {
|
||||
_links: {
|
||||
_next: null,
|
||||
},
|
||||
_items: [4, 5, 6],
|
||||
},
|
||||
});
|
||||
|
||||
const res = ParseArcDDR("profile", logger, mockArcAPI);
|
||||
|
||||
t.equal(res.game, "ddr");
|
||||
t.strictSame(res.context, {});
|
||||
t.equal(res.classHandler, null);
|
||||
|
||||
const iter = await agta(res.iterable);
|
||||
|
||||
t.strictSame(iter, [1, 2, 3, 4, 5, 6]);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
@@ -0,0 +1,47 @@
|
||||
import t from "tap";
|
||||
import { CloseAllConnections } from "../../../../../test-utils/close-connections";
|
||||
import { agta } from "../../../../../test-utils/misc";
|
||||
import { MockJSONFetch } from "../../../../../test-utils/mock-fetch";
|
||||
import ResetDBState from "../../../../../test-utils/reset-db-state";
|
||||
import CreateLogCtx from "../../../../logger/logger";
|
||||
import { ParseArcIIDX } from "./parser";
|
||||
|
||||
const logger = CreateLogCtx(__filename);
|
||||
|
||||
t.test("#ParseArcIIDX", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("Should iterate over the API.", async (t) => {
|
||||
const mockArcAPI = MockJSONFetch({
|
||||
"https://arc.example.com/api/v1/iidx/27/player_bests?profile_id=profile": {
|
||||
_links: {
|
||||
_next:
|
||||
"https://arc.example.com/api/v1/iidx/27/player_bests?profile_id=profile&page=2",
|
||||
},
|
||||
_items: [1, 2, 3],
|
||||
},
|
||||
"https://arc.example.com/api/v1/iidx/27/player_bests?profile_id=profile&page=2": {
|
||||
_links: {
|
||||
_next: null,
|
||||
},
|
||||
_items: [4, 5, 6],
|
||||
},
|
||||
});
|
||||
|
||||
const res = ParseArcIIDX("profile", logger, mockArcAPI);
|
||||
|
||||
t.equal(res.game, "iidx");
|
||||
t.strictSame(res.context, {});
|
||||
t.equal(res.classHandler, null);
|
||||
|
||||
const iter = await agta(res.iterable);
|
||||
|
||||
t.strictSame(iter, [1, 2, 3, 4, 5, 6]);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
@@ -0,0 +1,47 @@
|
||||
import t from "tap";
|
||||
import { CloseAllConnections } from "../../../../../test-utils/close-connections";
|
||||
import { agta } from "../../../../../test-utils/misc";
|
||||
import { MockJSONFetch } from "../../../../../test-utils/mock-fetch";
|
||||
import ResetDBState from "../../../../../test-utils/reset-db-state";
|
||||
import CreateLogCtx from "../../../../logger/logger";
|
||||
import { ParseArcJubeat } from "./parser";
|
||||
|
||||
const logger = CreateLogCtx(__filename);
|
||||
|
||||
t.test("#ParseArcJubeat", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("Should iterate over the API.", async (t) => {
|
||||
const mockArcAPI = MockJSONFetch({
|
||||
"https://arc.example.com/api/v1/jb/8/player_bests?profile_id=profile": {
|
||||
_links: {
|
||||
_next:
|
||||
"https://arc.example.com/api/v1/jb/8/player_bests?profile_id=profile&page=2",
|
||||
},
|
||||
_items: [1, 2, 3],
|
||||
},
|
||||
"https://arc.example.com/api/v1/jb/8/player_bests?profile_id=profile&page=2": {
|
||||
_links: {
|
||||
_next: null,
|
||||
},
|
||||
_items: [4, 5, 6],
|
||||
},
|
||||
});
|
||||
|
||||
const res = ParseArcJubeat("profile", logger, mockArcAPI);
|
||||
|
||||
t.equal(res.game, "jubeat");
|
||||
t.strictSame(res.context, {});
|
||||
t.equal(res.classHandler, null);
|
||||
|
||||
const iter = await agta(res.iterable);
|
||||
|
||||
t.strictSame(iter, [1, 2, 3, 4, 5, 6]);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
@@ -0,0 +1,47 @@
|
||||
import t from "tap";
|
||||
import { CloseAllConnections } from "../../../../../test-utils/close-connections";
|
||||
import { agta } from "../../../../../test-utils/misc";
|
||||
import { MockJSONFetch } from "../../../../../test-utils/mock-fetch";
|
||||
import ResetDBState from "../../../../../test-utils/reset-db-state";
|
||||
import CreateLogCtx from "../../../../logger/logger";
|
||||
import { ParseArcSDVX } from "./parser";
|
||||
|
||||
const logger = CreateLogCtx(__filename);
|
||||
|
||||
t.test("#ParseArcSDVX", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("Should iterate over the API.", async (t) => {
|
||||
const mockArcAPI = MockJSONFetch({
|
||||
"https://arc.example.com/api/v1/sdvx/5/player_bests?profile_id=profile": {
|
||||
_links: {
|
||||
_next:
|
||||
"https://arc.example.com/api/v1/sdvx/5/player_bests?profile_id=profile&page=2",
|
||||
},
|
||||
_items: [1, 2, 3],
|
||||
},
|
||||
"https://arc.example.com/api/v1/sdvx/5/player_bests?profile_id=profile&page=2": {
|
||||
_links: {
|
||||
_next: null,
|
||||
},
|
||||
_items: [4, 5, 6],
|
||||
},
|
||||
});
|
||||
|
||||
const res = ParseArcSDVX("profile", logger, mockArcAPI);
|
||||
|
||||
t.equal(res.game, "sdvx");
|
||||
t.strictSame(res.context, {});
|
||||
t.equal(res.classHandler, null);
|
||||
|
||||
const iter = await agta(res.iterable);
|
||||
|
||||
t.strictSame(iter, [1, 2, 3, 4, 5, 6]);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
@@ -1,5 +1,6 @@
|
||||
import t from "tap";
|
||||
import { CloseAllConnections } from "../../../../../test-utils/close-connections";
|
||||
import { agta } from "../../../../../test-utils/misc";
|
||||
import { MockJSONFetch } from "../../../../../test-utils/mock-fetch";
|
||||
import ResetDBState from "../../../../../test-utils/reset-db-state";
|
||||
import CreateLogCtx from "../../../../logger/logger";
|
||||
@@ -10,18 +11,6 @@ const logger = CreateLogCtx(__filename);
|
||||
|
||||
const fakeAuth = "bar";
|
||||
|
||||
/**
|
||||
* Async Generator To Array
|
||||
*/
|
||||
async function agta(ag: AsyncGenerator<unknown>) {
|
||||
const a = [];
|
||||
for await (const el of ag) {
|
||||
a.push(el);
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
t.test("#TraverseKaiAPI", (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Async Generator To Array
|
||||
*/
|
||||
export async function agta(ag: AsyncIterable<unknown>) {
|
||||
const a = [];
|
||||
for await (const el of ag) {
|
||||
a.push(el);
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
Reference in New Issue
Block a user