Files
romm/frontend/src/utils/romFiles.test.ts
Georges-Antoine Assi 2469839b66 fix(jsdos): play a .jsdos bundle that sits inside a game folder (#5672)
* fix(jsdos): play a .jsdos bundle that sits inside a game folder

The play check read the ROM's own extension, which is empty for a folder,
so a bundle moved into a folder (for example beside its manual) lost its
Play button. The backend now exposes has_jsdos_bundle, true when the ROM
is a bundle or has one at its folder's top level, and the js-dos player
asks the content endpoint for that file instead of a zip of the folder.

Fixes #5615

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(jsdos): assert the player downloads only the bundle file

Addresses Greptile's review on #5672: covers the bundle file id in the player URL and drops a comment that restated the constant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* pr-ready: code-review

Pin has_jsdos_bundle's value for a plain single file and for a bundle
missing from disk, on both the SQL and the with_files path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011waFLKWoBw9KCu31UJJ7Te

* pr-ready: code-review

Expose missing_from_fs on RomFileSchema so the js-dos player skips a
bundle gone from disk, the same rule has_jsdos_bundle applies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011waFLKWoBw9KCu31UJJ7Te

* pr-ready: simplify

Share the top-level file predicate and the present-file exists subquery
between is_easyrpg_game and has_jsdos_bundle, compute the top-level files
once in apply_file_stats, and fold the two marker flag tests into one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011waFLKWoBw9KCu31UJJ7Te

* pr-ready: review-polish

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011waFLKWoBw9KCu31UJJ7Te

* pr-ready: prose

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011waFLKWoBw9KCu31UJJ7Te

* refactor(jsdos): rename isJsDosBundle to hasJsDosBundle

It also matches a folder that holds a bundle, so the name now says what
the backend flag it reads says.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011waFLKWoBw9KCu31UJJ7Te

* fix(scan): derive a scanned rom's file flags from the files it read

A scan emits scan:scanning_rom before it writes the rom's file rows, so a
new rom reached clients with every file flag false (has_simple_single_file,
has_multiple_files, has_jsdos_bundle and the rest) until a reload. The
emits now derive those flags from the files the scan just read whenever it
rebuilt them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011waFLKWoBw9KCu31UJJ7Te

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 19:28:36 -05:00

61 lines
1.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { RomFileSchema } from "@/__generated__";
import { FRONTEND_RESOURCES_PATH } from "@/utils";
import {
romFileUrl,
versionedResourceUrl,
versionedRomFileUrl,
} from "./romFiles";
const file: RomFileSchema = {
id: 7,
rom_id: 1,
file_name: "title screen #1.png",
file_path: "platform/roms/game/screenshots",
file_size_bytes: 10,
full_path: "platform/roms/game/screenshots/title screen #1.png",
is_top_level: false,
missing_from_fs: false,
created_at: "2024-01-01T00:00:00Z",
updated_at: "2024-02-03T04:05:06+00:00",
last_modified: "2024-01-01T00:00:00Z",
crc_hash: null,
md5_hash: null,
sha1_hash: null,
ra_hash: null,
chd_sha1_hash: null,
archive_members: null,
category: "screenshot",
};
describe("romFileUrl", () => {
it("encodes the file name into the content endpoint", () => {
expect(romFileUrl(7, "title screen #1.png")).toBe(
"/api/roms/7/files/content/title%20screen%20%231.png",
);
});
});
describe("versionedRomFileUrl", () => {
it("versions the URL with the file's own timestamp", () => {
expect(versionedRomFileUrl(file)).toBe(
"/api/roms/7/files/content/title%20screen%20%231.png?v=2024-02-03T04%3A05%3A06%2B00%3A00",
);
});
it("changes when the file row is updated", () => {
const replaced = { ...file, updated_at: "2024-03-01T00:00:00+00:00" };
expect(versionedRomFileUrl(replaced)).not.toBe(versionedRomFileUrl(file));
});
});
describe("versionedResourceUrl", () => {
it("serves the path from the resources root, versioned by the ROM timestamp", () => {
expect(
versionedResourceUrl("roms/1/2/logo/logo.png", "2024-02-03T04:05:06"),
).toBe(
`${FRONTEND_RESOURCES_PATH}/roms/1/2/logo/logo.png?v=2024-02-03T04%3A05%3A06`,
);
});
});