From 0594690c2a4ee55532702e6e1b559a318b8b9e0a Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Tue, 17 Dec 2024 12:49:34 +0000 Subject: [PATCH] Add test for a FOSDEM JSON schedule --- .../backends/json/JsonScheduleBackend.test.ts | 62 +++++ .../JsonScheduleBackend.test.ts.snap | 219 ++++++++++++++++++ .../backends/json/fosdem_democon.json | 142 ++++++++++++ 3 files changed, 423 insertions(+) create mode 100644 src/__tests__/backends/json/JsonScheduleBackend.test.ts create mode 100644 src/__tests__/backends/json/__snapshots__/JsonScheduleBackend.test.ts.snap create mode 100644 src/__tests__/backends/json/fosdem_democon.json diff --git a/src/__tests__/backends/json/JsonScheduleBackend.test.ts b/src/__tests__/backends/json/JsonScheduleBackend.test.ts new file mode 100644 index 0000000..6d6611b --- /dev/null +++ b/src/__tests__/backends/json/JsonScheduleBackend.test.ts @@ -0,0 +1,62 @@ +import { test, expect, afterEach, beforeEach, describe } from "@jest/globals"; +import { Server, createServer } from "node:http"; +import { AddressInfo } from "node:net"; +import path from "node:path"; +import * as fs from "fs"; +import { IConfig, JsonScheduleFormat } from "../../../config"; +import { JsonScheduleBackend } from "../../../backends/json/JsonScheduleBackend"; + +function getFixture(fixtureFile: string) { + return fs.readFileSync(path.join(__dirname, fixtureFile), "utf8"); +} + +function jsonScheduleServer() { + return new Promise((resolve) => { + const server = createServer((req, res) => { + if (req.url === "/schedule.json") { + res.writeHead(200); + const json = getFixture("original_democon.json"); + res.end(json); + } else if (req.url === "/fosdem/p/matrix") { + res.writeHead(200); + const json = getFixture("fosdem_democon.json"); + res.end(json); + } else { + console.log(req.url); + res.writeHead(404); + res.end("Not found"); + } + }).listen(undefined, "127.0.0.1", undefined, () => { + resolve(server); + }); + }); +} + +describe("JsonScheduleBackend", () => { + let serv; + beforeEach(async () => { + serv = await jsonScheduleServer(); + }); + afterEach(async () => { + serv.close(); + }); + + test("can parse a FOSDEM JSON format", async () => { + const globalConfig = { conference: { name: "DemoCon" } } as IConfig; + const backend = await JsonScheduleBackend.new( + "/dev/null", + { + backend: "json", + scheduleFormat: JsonScheduleFormat.FOSDEM, + scheduleDefinition: `http://127.0.0.1:${ + (serv.address() as AddressInfo).port + }/fosdem/p/matrix`, + }, + globalConfig + ); + expect(backend.conference.title).toBe("DemoCon"); + expect(backend.auditoriums).toMatchSnapshot("auditoriums"); + expect(backend.talks).toMatchSnapshot("talks"); + expect(backend.interestRooms.size).toBe(0); + }); +}); diff --git a/src/__tests__/backends/json/__snapshots__/JsonScheduleBackend.test.ts.snap b/src/__tests__/backends/json/__snapshots__/JsonScheduleBackend.test.ts.snap new file mode 100644 index 0000000..9590ba2 --- /dev/null +++ b/src/__tests__/backends/json/__snapshots__/JsonScheduleBackend.test.ts.snap @@ -0,0 +1,219 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`JsonScheduleBackend can parse a FOSDEM JSON format: auditoriums 1`] = ` +Map { + "5" => { + "id": "5", + "isPhysical": true, + "kind": "auditorium", + "name": "Open CAD/CAM devroom", + "slug": "open_cad_cam", + "talks": Map { + "3" => { + "auditoriumId": "5", + "dateTs": 1706745600000, + "endTime": 1706778000000, + "id": "3", + "livestream_endTime": 1706778000000, + "prerecorded": false, + "qa_startTime": 0, + "speakers": [ + { + "email": "ioferrell@localhost", + "id": "4", + "matrix_id": "", + "name": "Iarlaith O'Ferrell", + "role": "speaker", + }, + { + "email": "niamh@localhost", + "id": "5", + "matrix_id": "", + "name": "Niamh O'Donnellan", + "role": "speaker", + }, + { + "email": "conal@example.org", + "id": "1", + "matrix_id": "@conal:example.org", + "name": "Conal Cördinator", + "role": "coordinator", + }, + ], + "startTime": 1706778000000, + "subtitle": "", + "title": "Panacea3D: The Final Word in Open Source 3D Solid Modelling", + }, + }, + }, + "6" => { + "id": "6", + "isPhysical": true, + "kind": "auditorium", + "name": "Self-Hosted Software devroom", + "slug": "selfhosting", + "talks": Map { + "14" => { + "auditoriumId": "6", + "dateTs": 1706745600000, + "endTime": 1706779800000, + "id": "14", + "livestream_endTime": 1706779800000, + "prerecorded": false, + "qa_startTime": 0, + "speakers": [ + { + "email": "tysnr@localhost", + "id": "42", + "matrix_id": "", + "name": "Yasunori Takeda", + "role": "speaker", + }, + { + "email": "chloe@example.org", + "id": "246", + "matrix_id": "@chloe:example.org", + "name": "Chloé Coordinator", + "role": "coordinator", + }, + ], + "startTime": 1706779800000, + "subtitle": "", + "title": "A new architecture for Local-First Computing without boundaries", + }, + "19" => { + "auditoriumId": "6", + "dateTs": 1706745600000, + "endTime": 1706783400000, + "id": "19", + "livestream_endTime": 1706783400000, + "prerecorded": false, + "qa_startTime": 0, + "speakers": [ + { + "email": "vivaldo@localhost", + "id": "94", + "matrix_id": "@vivaldo:example.org", + "name": "Vivaldo Corradetti", + "role": "speaker", + }, + { + "email": "chloe@example.org", + "id": "246", + "matrix_id": "@chloe:example.org", + "name": "Chloé Coordinator", + "role": "coordinator", + }, + ], + "startTime": 1706783400000, + "subtitle": "", + "title": "Devising a Blended Federation Topology that reaches Cosmique Perfection", + }, + }, + }, + "7" => { + "id": "7", + "isPhysical": true, + "kind": "auditorium", + "name": "Keynotes (TALKS NOT ANNOUNCED YET)", + "slug": "key_notes", + "talks": Map {}, + }, +} +`; + +exports[`JsonScheduleBackend can parse a FOSDEM JSON format: talks 1`] = ` +Map { + "3" => { + "auditoriumId": "5", + "dateTs": 1706745600000, + "endTime": 1706778000000, + "id": "3", + "livestream_endTime": 1706778000000, + "prerecorded": false, + "qa_startTime": 0, + "speakers": [ + { + "email": "ioferrell@localhost", + "id": "4", + "matrix_id": "", + "name": "Iarlaith O'Ferrell", + "role": "speaker", + }, + { + "email": "niamh@localhost", + "id": "5", + "matrix_id": "", + "name": "Niamh O'Donnellan", + "role": "speaker", + }, + { + "email": "conal@example.org", + "id": "1", + "matrix_id": "@conal:example.org", + "name": "Conal Cördinator", + "role": "coordinator", + }, + ], + "startTime": 1706778000000, + "subtitle": "", + "title": "Panacea3D: The Final Word in Open Source 3D Solid Modelling", + }, + "14" => { + "auditoriumId": "6", + "dateTs": 1706745600000, + "endTime": 1706779800000, + "id": "14", + "livestream_endTime": 1706779800000, + "prerecorded": false, + "qa_startTime": 0, + "speakers": [ + { + "email": "tysnr@localhost", + "id": "42", + "matrix_id": "", + "name": "Yasunori Takeda", + "role": "speaker", + }, + { + "email": "chloe@example.org", + "id": "246", + "matrix_id": "@chloe:example.org", + "name": "Chloé Coordinator", + "role": "coordinator", + }, + ], + "startTime": 1706779800000, + "subtitle": "", + "title": "A new architecture for Local-First Computing without boundaries", + }, + "19" => { + "auditoriumId": "6", + "dateTs": 1706745600000, + "endTime": 1706783400000, + "id": "19", + "livestream_endTime": 1706783400000, + "prerecorded": false, + "qa_startTime": 0, + "speakers": [ + { + "email": "vivaldo@localhost", + "id": "94", + "matrix_id": "@vivaldo:example.org", + "name": "Vivaldo Corradetti", + "role": "speaker", + }, + { + "email": "chloe@example.org", + "id": "246", + "matrix_id": "@chloe:example.org", + "name": "Chloé Coordinator", + "role": "coordinator", + }, + ], + "startTime": 1706783400000, + "subtitle": "", + "title": "Devising a Blended Federation Topology that reaches Cosmique Perfection", + }, +} +`; diff --git a/src/__tests__/backends/json/fosdem_democon.json b/src/__tests__/backends/json/fosdem_democon.json new file mode 100644 index 0000000..dcb6cca --- /dev/null +++ b/src/__tests__/backends/json/fosdem_democon.json @@ -0,0 +1,142 @@ +{ + "talks": [ + { + "event_id": 3, + "title": "Panacea3D: The Final Word in Open Source 3D Solid Modelling", + "persons": [ + { + "person_id": 4, + "event_role": "speaker", + "name": "Iarlaith O'Ferrell", + "email": "ioferrell@localhost", + "matrix_id": "" + }, + { + "person_id": 5, + "event_role": "speaker", + "name": "Niamh O'Donnellan", + "email": "niamh@localhost", + "matrix_id": "" + }, + { + "person_id": 1, + "event_role": "coordinator", + "name": "Conal Cördinator", + "email": "conal@example.org", + "matrix_id": "@conal:example.org" + } + ], + "conference_room": "C.1.111", + "start_datetime": "2024-02-01T09:30:00+01:00", + "duration": 30, + "track": { + "id": 5, + "slug": "open_cad_cam", + "name": "Open CAD/CAM devroom" + } + }, + { + "event_id": 14, + "title": "A new architecture for Local-First Computing without boundaries", + "persons": [ + { + "person_id": 42, + "event_role": "speaker", + "name": "Yasunori Takeda", + "email": "tysnr@localhost", + "matrix_id": "" + }, + { + "person_id": 246, + "event_role": "coordinator", + "name": "Chloé Coordinator", + "email": "chloe@example.org", + "matrix_id": "@chloe:example.org" + } + ], + "conference_room": "C.4.172", + "start_datetime": "2024-02-01T09:45:00+01:00", + "duration": 45, + "track": { + "id": 6, + "slug": "selfhosting", + "name": "Self-Hosted Software devroom" + } + }, + { + "event_id": 19, + "title": "Devising a Blended Federation Topology that reaches Cosmique Perfection", + "persons": [ + { + "person_id": 94, + "event_role": "speaker", + "name": "Vivaldo Corradetti", + "email": "vivaldo@localhost", + "matrix_id": "@vivaldo:example.org" + }, + { + "person_id": 246, + "event_role": "coordinator", + "name": "Chloé Coordinator", + "email": "chloe@example.org", + "matrix_id": "@chloe:example.org" + } + ], + "conference_room": "C.4.172", + "start_datetime": "2024-02-01T10:45:00+01:00", + "duration": 45, + "track": { + "id": 6, + "slug": "selfhosting", + "name": "Self-Hosted Software devroom" + } + } + ], + "tracks": [ + { + "id": 5, + "slug": "open_cad_cam", + "name": "Open CAD/CAM devroom", + "type": "devroom", + "managers": [ + { + "person_id": 1, + "event_role": "coordinator", + "name": "Conal Coordinator", + "email": "conal@example.org", + "matrix_id": "@conal:example.org" + } + ] + }, + { + "id": 6, + "slug": "selfhosting", + "name": "Self-Hosted Software devroom", + "type": "devroom", + "managers": [ + { + "person_id": 246, + "event_role": "coordinator", + "name": "Chloé Coordinator", + "email": "chloe@example.org", + "matrix_id": "@chloe:example.org" + } + ] + }, + { + "id": 7, + "slug": "key_notes", + "name": "Keynotes (TALKS NOT ANNOUNCED YET)", + "type": "maintrack", + "managers": [ + { + "person_id": 0, + "event_role": "coordinator", + "name": "Bert Boss", + "email": "bert@example.org", + "matrix_id": "@bert:example.org" + } + ] + } + ] +}