fix: District settings read per field, so DISTRICT_* always wins

A leftover v1 MOVIE_CODE used to switch the whole District block to the old names,
silently discarding DISTRICT_CONTENT_ID even when it was set deliberately. The
monitor then watched the wrong film and still reported 'closed', which is the
failure mode this project exists to avoid.

Each field now prefers the DISTRICT_* value and falls back to its v1 name, an
explicitly emptied value is respected, and any v1 name still in use is warned
about at startup. District is enabled by DISTRICT_CONTENT_ID rather than the
movie code, which is optional: District answers without it, and a film with no
showtimes yet has none.
This commit is contained in:
Aculix Technologies committed 2026-09-08 15:14:51 +05:30
1 parent 6607a469a2
commit ef23f25ee5
4 files changed
+89 -34

No files matched your search

+31
View File
@@ -132,3 +132,34 @@ test("district: 400 code 32 is a waiting state, other 400s are failures", async
globalThis.fetch = realFetch;
}
});
// A leftover v1 name silently overriding a DISTRICT_* value that was set on purpose is
// the worst kind of config bug: the monitor watches the wrong film and still says "closed".
test("config: DISTRICT_* wins per field over leftover v1 names", async () => {
const { loadConfig, legacyNamesInUse } = await import("../src/config.js");
const saved = { ...process.env };
try {
Object.assign(process.env, {
TARGET_DATE: "2026-09-25", NTFY_TOPIC: "t",
MOVIE_CODE: "OLDCODE", CONTENT_ID: "187151", CITY_KEY: "ahmedabad",
LAT: "23.03", LNG: "72.57", CINEMA_ID: "1032362",
DISTRICT_CONTENT_ID: "227928", DISTRICT_CINEMA_ID: "",
BMS_EVENT_CODE: "ET1", BMS_REGION_CODE: "AHD",
});
const d = loadConfig().providers.find((p) => p.key === "district");
assert.equal(d.contentId, "227928", "the explicitly set new name must win");
assert.equal(d.venueId, "", "an explicitly emptied new name must not fall back to the old one");
assert.equal(d.movieCode, "OLDCODE", "fields with no new value still inherit");
assert.ok(legacyNamesInUse().includes("MOVIE_CODE"), "and the leftovers are reported");
delete process.env.DISTRICT_CONTENT_ID;
delete process.env.CONTENT_ID;
const only = loadConfig().providers;
assert.equal(only.find((p) => p.key === "district"), undefined,
"no content id means District is simply not watched");
assert.equal(only.length, 1, "and the other site carries on alone");
} finally {
for (const k of Object.keys(process.env)) if (!(k in saved)) delete process.env[k];
Object.assign(process.env, saved);
}
});