revert fb8e77bb68
Local Build and Deploy / deploy (push) Successful in 1m11s
Local Build and Deploy / deploy (push) Successful in 1m11s
revert style: clean up code with prettier and eslint
This commit is contained in:
1 parent
27de078f54
commit
e85e4d74ea
378 files changed
+20710
-22428
No files matched your search
@@ -1,66 +1,67 @@
|
||||
// @vitest-environment node
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
vi.mock("@/lib/services/import/core/download", () => ({
|
||||
vi.mock('@/lib/services/import/core/download', () => ({
|
||||
downloadFile: vi.fn(async () => ({ ok: true, size: 100 })),
|
||||
}));
|
||||
vi.mock("@/lib/services/figure-source", () => ({
|
||||
}))
|
||||
vi.mock('@/lib/services/figure-source', () => ({
|
||||
resolveFigureSwfUrl: vi.fn(async (lib: string) => `https://x/${lib}.swf`),
|
||||
}));
|
||||
vi.mock("@/lib/services/figuremap", () => ({
|
||||
}))
|
||||
vi.mock('@/lib/services/figuremap', () => ({
|
||||
listFigureLibraries: vi.fn(async () => [
|
||||
{ id: "Hair_F_Bob", revision: 1 },
|
||||
{ id: "shirt_M_x", revision: 2 },
|
||||
{ id: "Hat_U_y", revision: 3 },
|
||||
{ id: 'Hair_F_Bob', revision: 1 },
|
||||
{ id: 'shirt_M_x', revision: 2 },
|
||||
{ id: 'Hat_U_y', revision: 3 },
|
||||
]),
|
||||
}));
|
||||
const convertSwfToNitro = vi.fn(() => ({ bundle: Buffer.from("nitro"), warnings: [] }));
|
||||
vi.mock("@/lib/services/swf-to-nitro", () => ({
|
||||
convertSwfToNitro: (...a: unknown[]) => convertSwfToNitro(...(a as Parameters<typeof convertSwfToNitro>)),
|
||||
}));
|
||||
vi.mock("node:fs", async (orig) => {
|
||||
const real = (await orig()) as typeof import("node:fs");
|
||||
}))
|
||||
const convertSwfToNitro = vi.fn(() => ({ bundle: Buffer.from('nitro'), warnings: [] }))
|
||||
vi.mock('@/lib/services/swf-to-nitro', () => ({
|
||||
convertSwfToNitro: (...a: unknown[]) =>
|
||||
convertSwfToNitro(...(a as Parameters<typeof convertSwfToNitro>)),
|
||||
}))
|
||||
vi.mock('node:fs', async (orig) => {
|
||||
const real = (await orig()) as typeof import('node:fs')
|
||||
return {
|
||||
...real,
|
||||
existsSync: vi.fn(() => false),
|
||||
promises: {
|
||||
...real.promises,
|
||||
readFile: vi.fn(async () => Buffer.from("CWS")),
|
||||
readFile: vi.fn(async () => Buffer.from('CWS')),
|
||||
writeFile: vi.fn(async () => {}),
|
||||
mkdir: vi.fn(async () => {}),
|
||||
unlink: vi.fn(async () => {}),
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
import { getFigureList, importSingleFigure } from "./figure-import";
|
||||
import { getFigureList, importSingleFigure } from './figure-import'
|
||||
|
||||
describe("figure-import", () => {
|
||||
it("paginates the library list with present flags", async () => {
|
||||
const { items, meta } = await getFigureList({ search: "", page: 1, perPage: 2 });
|
||||
expect(items).toHaveLength(2);
|
||||
expect(meta).toMatchObject({ page: 1, perPage: 2, total: 3 });
|
||||
expect(items[0]).toMatchObject({ lib: "Hair_F_Bob", nitroExists: false });
|
||||
});
|
||||
describe('figure-import', () => {
|
||||
it('paginates the library list with present flags', async () => {
|
||||
const { items, meta } = await getFigureList({ search: '', page: 1, perPage: 2 })
|
||||
expect(items).toHaveLength(2)
|
||||
expect(meta).toMatchObject({ page: 1, perPage: 2, total: 3 })
|
||||
expect(items[0]).toMatchObject({ lib: 'Hair_F_Bob', nitroExists: false })
|
||||
})
|
||||
|
||||
it("filters by search", async () => {
|
||||
const { items, meta } = await getFigureList({ search: "shirt", page: 1, perPage: 50 });
|
||||
expect(meta.total).toBe(1);
|
||||
expect(items[0].lib).toBe("shirt_M_x");
|
||||
});
|
||||
it('filters by search', async () => {
|
||||
const { items, meta } = await getFigureList({ search: 'shirt', page: 1, perPage: 50 })
|
||||
expect(meta.total).toBe(1)
|
||||
expect(items[0].lib).toBe('shirt_M_x')
|
||||
})
|
||||
|
||||
it("importSingleFigure downloads + converts + writes", async () => {
|
||||
const r = await importSingleFigure({ lib: "Hair_F_Bob" });
|
||||
expect(r.ok).toBe(true);
|
||||
expect(convertSwfToNitro).toHaveBeenCalled();
|
||||
});
|
||||
it('importSingleFigure downloads + converts + writes', async () => {
|
||||
const r = await importSingleFigure({ lib: 'Hair_F_Bob' })
|
||||
expect(r.ok).toBe(true)
|
||||
expect(convertSwfToNitro).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("fails cleanly when conversion throws", async () => {
|
||||
it('fails cleanly when conversion throws', async () => {
|
||||
convertSwfToNitro.mockImplementationOnce(() => {
|
||||
throw new Error("bad swf");
|
||||
});
|
||||
const r = await importSingleFigure({ lib: "shirt_M_x" });
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.error).toContain("conversion");
|
||||
});
|
||||
});
|
||||
throw new Error('bad swf')
|
||||
})
|
||||
const r = await importSingleFigure({ lib: 'shirt_M_x' })
|
||||
expect(r.ok).toBe(false)
|
||||
expect(r.error).toContain('conversion')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user