gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit0553b51f0553b51ftracker#19 (mission 066): franchises and timelines — tables, /franchises, /franchises/<slug>, /timelines/<slug> (Timeline | Release sort, series by last episode), the Prequel | Timeline | Sequel widget with the franchise above, the creator's editor, TMDB collection seed in the app (resumes, paced); gate tests/franchises.mjs 48/0 + browser.mjs 266/0, tests/realdata-066.mjs, docs/franchises.md, README + STATUSmre0553b51f/tests/faketmdb.mjs

9.4 KB

  1. // tests/faketmdb.mjs — A FAKE TMDB for the gate (tracker.worldapi.org#9): a tiny local HTTP server that answers
  2. // the three calls tmdbsync.hl makes, from fixed JSON — no real TMDB call ever happens in the gate. The app is
  3. // pointed at it with TMDB_BASE_URL=<base>/3 and TMDB_IMAGE_URL=<base>/t/p.
  4. //
  5. // GET /3/tv/<id> details (shows[id] minus the episodes)
  6. // GET /3/tv/<id>?append_to_response=season/1,… the same + "season/<n>" = { name, overview, air_date, episodes }
  7. // GET /t/p/w342/<file>.png a 1×1 png
  8. // …?append_to_response=…,external_ids + "external_ids" = shows[id].external_ids (tracker.worldapi.org#12)
  9. // GET /3/movie/<id>[?append_to_response=external_ids] movies[id]: { id, title, poster_path } (+ external_ids)
  10. // GET /3/search/multi?query=… tracker.worldapi.org#14: { results = search[query in lower case] }
  11. // — recorded in `fake.searchRequests`, NOT in `fake.requests`
  12. // GET /t/p/w92/<file>.png the search page's small posters → `fake.thumbRequests`
  13. // GET /3/person/<id>[?append_to_response=combined_credits] tracker.worldapi.org#16: persons[id] (+ its combined_credits)
  14. // GET /t/p/w185/<file>.png a person's photo (1×1 png) — both recorded in `fake.personRequests`
  15. // and A FAKE TVMAZE under /tvmaze (the app gets TVMAZE_BASE_URL=<base>/tvmaze):
  16. // GET /tvmaze/lookup/shows?imdb=tt…|thetvdb=<id> 301 → /tvmaze/shows/<id> (like the real one), 404 when unknown
  17. // GET /tvmaze/shows/<id> { id, name }
  18. // GET /tvmaze/shows/<id>/episodes tvmaze.episodes[id] (tracker.worldapi.org#15): [{ id, season, number, name, airdate }]
  19. //
  20. // GET /3/collection/<id> tracker.worldapi.org#19 (mission 066): collections[id] = { id, name, parts }; a
  21. // movie's details carry `belongs_to_collection` when its fixture has one
  22. // mission 054: every details / search answer carries TMDB's `adult` (false unless the fixture sets it).
  23. // `fake.shows` is mutable (the gate adds an episode before the in-app run), `fake.delayMs` slows every answer
  24. // down, `fake.requests` records every TMDB/image request (path, authorization) so the gate can prove what was asked;
  25. // TVmaze requests go to `fake.tvmazeRequests` (paths) instead.
  26. import http from 'node:http';
  27. export const PNG = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==', 'base64');
  28. export async function startFakeTmdb({ port, shows, movies = {}, tvmaze = { imdb: {}, thetvdb: {} }, search = {}, persons = {}, collections = {} }) {
  29. const fake = { shows, movies, tvmaze, search, persons, collections, delayMs: 0, personDelayMs: 0, requests: [], tvmazeRequests: [], searchRequests: [], thumbRequests: [], personRequests: [], base: `http://127.0.0.1:${port}` };
  30. const details = (s) => ({
  31. id: s.id, name: s.name, adult: s.adult ?? false, overview: s.overview, status: s.status, poster_path: s.poster_path,
  32. first_air_date: s.first_air_date, genres: s.genres, original_language: s.original_language,
  33. number_of_seasons: s.seasons.filter(x => x.season_number > 0).length,
  34. number_of_episodes: s.seasons.filter(x => x.season_number > 0).reduce((a, x) => a + x.episodes.length, 0),
  35. seasons: s.seasons.map(x => ({ id: x.id, season_number: x.season_number, name: x.name, overview: x.overview || '', air_date: x.air_date, episode_count: x.episodes.length })),
  36. });
  37. const server = http.createServer((req, res) => {
  38. const url = new URL(req.url, fake.base);
  39. if (url.pathname.startsWith('/tvmaze/')) {
  40. fake.tvmazeRequests.push(url.pathname + url.search);
  41. const json = (code, body, headers = {}) => { res.writeHead(code, { 'content-type': 'application/json', ...headers }); res.end(JSON.stringify(body)); };
  42. if (url.pathname === '/tvmaze/lookup/shows') {
  43. const [param, value] = [...url.searchParams.entries()][0] || [];
  44. const id = param && (fake.tvmaze[param] || {})[value];
  45. return id ? json(301, {}, { location: `${fake.base}/tvmaze/shows/${id}` }) : json(404, { name: 'Not Found', status: 404 });
  46. }
  47. const em = url.pathname.match(/^\/tvmaze\/shows\/(\d+)\/episodes$/);
  48. if (em) return (fake.tvmaze.episodes || {})[em[1]] ? json(200, fake.tvmaze.episodes[em[1]].map(e => ({ type: 'regular', summary: '<p>tvmaze</p>', ...e }))) : json(404, { name: 'Not Found', status: 404 });
  49. const sm = url.pathname.match(/^\/tvmaze\/shows\/(\d+)$/);
  50. return sm ? json(200, { id: Number(sm[1]), name: 'fake TVmaze show ' + sm[1] }) : json(404, { name: 'Not Found', status: 404 });
  51. }
  52. if (url.pathname === '/3/search/multi') {
  53. fake.searchRequests.push({ path: url.pathname + url.search, authorization: req.headers['authorization'] || null });
  54. // like the real one, every title result carries `adult` (false unless the fixture says otherwise, mission 054)
  55. const results = (fake.search[(url.searchParams.get('query') || '').toLowerCase()] || []).map(r => r.media_type === 'person' || 'adult' in r ? r : { ...r, adult: false });
  56. res.writeHead(200, { 'content-type': 'application/json' });
  57. return res.end(JSON.stringify({ page: 1, results, total_pages: 1, total_results: results.length }));
  58. }
  59. // the search page's small posters (w92, loaded by the BROWSER from TMDB's image host) — kept out of `requests` too
  60. if (/^\/t\/p\/w92\/[a-z0-9]+\.png$/.test(url.pathname)) { fake.thumbRequests.push(url.pathname); res.writeHead(200, { 'content-type': 'image/png' }); return res.end(PNG); }
  61. // tracker.worldapi.org#16: the person page's fetch (kept out of `requests`, like the search's) — `personDelayMs` slows it
  62. // down so the gate sees the page's "loading" state
  63. const pm = url.pathname.match(/^\/3\/person\/(\d+)$/);
  64. if (pm || /^\/t\/p\/w185\/[a-z0-9]+\.png$/.test(url.pathname)) {
  65. fake.personRequests.push({ path: url.pathname + url.search, authorization: req.headers['authorization'] || null });
  66. const answerPerson = () => {
  67. if (!pm) { res.writeHead(200, { 'content-type': 'image/png' }); return res.end(PNG); }
  68. const pr = fake.persons[pm[1]];
  69. if (!pr) { res.writeHead(404, { 'content-type': 'application/json' }); return res.end('{"status_code":34,"status_message":"The resource you requested could not be found."}'); }
  70. const { combined_credits, ...out } = pr;
  71. if ((url.searchParams.get('append_to_response') || '').split(',').includes('combined_credits')) out.combined_credits = combined_credits || { cast: [], crew: [] };
  72. res.writeHead(200, { 'content-type': 'application/json' });
  73. res.end(JSON.stringify(out));
  74. };
  75. if (pm && fake.personDelayMs > 0) return setTimeout(answerPerson, fake.personDelayMs);
  76. return answerPerson();
  77. }
  78. fake.requests.push({ path: url.pathname + url.search, authorization: req.headers['authorization'] || null, at: Date.now() });
  79. const answer = () => {
  80. const appended = (url.searchParams.get('append_to_response') || '').split(',').filter(Boolean);
  81. const mv = url.pathname.match(/^\/3\/movie\/(\d+)$/);
  82. if (mv && fake.movies[mv[1]]) {
  83. const m = fake.movies[mv[1]];
  84. const out = { id: m.id, title: m.title, adult: m.adult ?? false, poster_path: m.poster_path, release_date: m.release_date, overview: m.overview, genres: m.genres };
  85. if (appended.includes('external_ids')) out.external_ids = m.external_ids || {};
  86. if (m.belongs_to_collection !== undefined) out.belongs_to_collection = m.belongs_to_collection;
  87. res.writeHead(200, { 'content-type': 'application/json' });
  88. return res.end(JSON.stringify(out));
  89. }
  90. const cm = url.pathname.match(/^\/3\/collection\/(\d+)$/);
  91. if (cm && fake.collections[cm[1]]) {
  92. res.writeHead(200, { 'content-type': 'application/json' });
  93. return res.end(JSON.stringify(fake.collections[cm[1]]));
  94. }
  95. let m = url.pathname.match(/^\/3\/tv\/(\d+)$/);
  96. if (m && fake.shows[m[1]]) {
  97. const s = fake.shows[m[1]];
  98. const out = details(s);
  99. if (appended.includes('external_ids')) out.external_ids = s.external_ids || {};
  100. for (const part of appended) {
  101. const sm = part.match(/^season\/(\d+)$/);
  102. const season = sm && s.seasons.find(x => x.season_number === Number(sm[1]));
  103. if (season) out[part] = { id: season.id, season_number: season.season_number, name: season.name, overview: season.overview || '', air_date: season.air_date,
  104. episodes: season.episodes.map(e => ({ id: e.id, season_number: season.season_number, episode_number: e.episode_number, name: e.name, overview: e.overview || '', air_date: e.air_date })) };
  105. }
  106. res.writeHead(200, { 'content-type': 'application/json' });
  107. return res.end(JSON.stringify(out));
  108. }
  109. if (/^\/t\/p\/w342\/[a-z0-9]+\.png$/.test(url.pathname)) { res.writeHead(200, { 'content-type': 'image/png' }); return res.end(PNG); }
  110. res.writeHead(404, { 'content-type': 'application/json' });
  111. res.end('{"status_code":34,"status_message":"The resource you requested could not be found."}');
  112. };
  113. if (fake.delayMs > 0) setTimeout(answer, fake.delayMs); else answer();
  114. });
  115. await new Promise((ok, fail) => { server.once('error', fail); server.listen(port, '127.0.0.1', ok); });
  116. fake.stop = () => new Promise(r => server.close(() => r()));
  117. return fake;
  118. }

Branches

Latest commits

  • 0553b51ftracker#19 (mission 066): franchises and timelines — tables, /franchises, /franchises/<slug>, /timelines/<slug> (Timeline | Release sort, series by last episode), the Prequel | Timeline | Sequel widget with the franchise above, the creator's editor, TMDB collection seed in the app (resumes, paced); gate tests/franchises.mjs 48/0 + browser.mjs 266/0, tests/realdata-066.mjs, docs/franchises.md, README + STATUSmre
  • fa1f9dfatracker#29 (mission 063): unwatched check muted grey outline + check (accent only on hover), watched stays solid — no code regression, the accent outline read as ticked; gate checks real checks visibly (computed style + screenshot pixel) on /my/unwatched, show, movie, /my/movies; gate 266, tests/realdata-063.mjs, README + STATUSmre
  • d8b12d67tracker#27 (mission 060): short ids for movies, series and persons — old 702 kept (data/old-short-ids.json), new random [a-z0-9]{5} unique across both, claimed at creation, background backfill (resumes), shown under poster/photo, /<shortId> → 301; gate 259, tests/realdata-060*, README + STATUSmre
  • f14db671tracker#22-#25 (mission 058): episode air dates, season check = all episodes watched, movie watched check (+ /my/movies count), /genres/<genre> pages (movies + series, newest first, paginated); gate 238, tests/realdata-058.mjs, README + STATUSmre
  • 1704ec45tracker#17 (mission 057): season caret down/up, skeleton rows while a season loads, sessionless showSeasonEpisodes face (no page re-mount), client-only close; gate 214, tests/realdata-057.mjs, README + STATUSmre
  • f2fe3e36mission 056: README + STATUS (merge, fixes, Hybriel 8590df63, real-data check), tests/realdata-056.mjs, tools/check-public-slugs.hlmre
  • f40c250emission 056: re-vendor hybriel master 8590df63 (#121, #122); an adult title's page is Not found for non-followers; gate: leave the page before stopping the servermre
  • 2b7fdd6cmission 056: signed-out header one row on phones ("Log in", nowrap), backfill skips adult titles' posters, gate checksmre
  • 2c53d5efMerge branch 't16-person' (tracker#16 person pages) into main; filmography shows only public titles (054 adult flag), gate race fix (backfill start line)mre
  • c171227emission 054: hide adult/unknown titles from the public lists and the search; in-app adult-flag backfill (TMDB details + poster per title, resumes), gate + real-data proofmre
  • 139fafd8tracker#16: short bio (4 lines, click = all), real-data check script, README + STATUSmre
  • 93be9476tracker#16: person pages /person/<slug> with the filmography fetched from TMDB on the first visit (step by step), gatemre
  • 47a3cae6STATUS: mission 053 merge commit idsmre
  • dcc5eecaMerge branch 't14-search'mre
  • 03edc783Merge branch 't15-tvmaze'mre
  • 71b46345tracker#15: numbering check by date or title, placeholder titles in other languages, docs + real-data proofmre
  • 6bb2daf1tracker#13: homepage (tiles, intro, latest movies/shows), /shows, /movies/page/N, /my/movies; lists cached in memorymre
  • b8bd1157tracker#14: README + STATUS (search, real-data numbers, gate, merge notes)mre
  • 65c694a8tracker#14: search — header magnifier, /search/<text> (in-memory word-prefix index over titles + people), Fetch from web (TMDB search/multi, ours left out), Add = import via syncShow; gate +25 checks, real-data scriptmre
  • 34f2c15btracker#15: TVmaze merge in the sync (gaps only: new episodes/seasons, empty titles/air dates; numbering check), fake TVmaze episodes + gatemre