Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a FOSDEM JSON schedule loader for the /p/matrix schema #240

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/__tests__/backends/json/JsonScheduleBackend.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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<Server>((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") {
if (req.headers.authorization !== "Bearer TOKEN") {
res.writeHead(401);
res.end("Not authorised");
return;
}
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`,
scheduleRequestHeaders: {
"Authorization": "Bearer TOKEN"
}
},
globalConfig
);
expect(backend.conference.title).toBe("DemoCon");
expect(backend.auditoriums).toMatchSnapshot("auditoriums");
expect(backend.talks).toMatchSnapshot("talks");
expect(backend.interestRooms.size).toBe(0);
});
});
Original file line number Diff line number Diff line change
@@ -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": null,
"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": "[email protected]",
"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": "[email protected]",
"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": "[email protected]",
"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": null,
"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": "[email protected]",
"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": "[email protected]",
"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": "[email protected]",
"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",
},
}
`;
Loading
Loading