Skip to content

Commit

Permalink
Add tests for pretalx
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Jan 3, 2024
1 parent 47e3dad commit 479f105
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 0 deletions.
104 changes: 104 additions & 0 deletions src/__tests__/backends/pretalx/PretalxBackend.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { test, expect, afterEach, beforeEach, describe } from "@jest/globals";
import { PretalxScheduleBackend } from "../../../backends/pretalx/PretalxBackend";
import { Server, createServer } from "node:http";
import { AddressInfo } from "node:net";
import path from "node:path";

const pretalxSpeakers = [{
code: "37RA83",
name: "AnyConf Staff",
biography: null,
submissions: [],
avatar: "",
answers: [],
email: "[email protected]",
availabilities: [],
},{
code: "YT3EFD",
name: "Alice AnyConf",
biography: "Alice is a test user with a big robotic brain.",
submissions: [],
avatar: "",
answers: [],
email: "[email protected]",
availabilities: [],
}];

function fakePretalxServer() {
return new Promise<Server>(resolve => { const server = createServer((req, res) => {
if (req.url?.startsWith('/speakers/?')) {
res.writeHead(200);
res.end(JSON.stringify({
count: pretalxSpeakers.length,
next: null,
previous: null,
results: pretalxSpeakers,
}));
} else if (req.url?.startsWith('/speakers/')) {
const speakerCode = req.url.slice('/speakers/'.length);
const speaker = pretalxSpeakers.find(s => s.code === speakerCode);
if (speaker) {
res.writeHead(200);
res.end(speaker);
} else {
res.writeHead(404);
res.end(`Speaker "${speakerCode}" not found`);
}
} else {
console.log(req.url);
res.writeHead(404);
res.end("Not found");
}
}).listen(undefined, '127.0.0.1', undefined, () => {
resolve(server);
})});
}

const prefixConfig = {
// Unused here.
aliases: "", displayNameSuffixes: {}, suffixes: {}, physicalAuditoriumRooms: [],

auditoriumRooms: [
"AW1.",
"D.",
"H.",
"Janson",
"K.",
"M.",
"UA2.",
"UB2.252A",
"UB4.",
"UB5.",
"UD2."
],
qaAuditoriumRooms: [
"AQ.",
],
interestRooms: [
"I."
],
nameOverrides: {
"A.special": "special-room",
},
};
describe('PretalxBackend', () => {
let pretalxServ;
beforeEach(async () => {
pretalxServ = await fakePretalxServer();
});
afterEach(async () => {
pretalxServ.close();

});
test("can parse a standard JSON format", async () => {
const pretalxServ = await fakePretalxServer();
const backend = await PretalxScheduleBackend.new("/dev/null", {
backend: "pretalx",
scheduleDefinition: path.join(__dirname, 'anyconf.json'),
pretalxAccessToken: "123456",
pretalxApiEndpoint: `http://localhost:${(pretalxServ.address() as AddressInfo).port}`,
}, prefixConfig);
expect(backend.conference.title).toBe('AnyConf 2024');
expect(backend.conference.auditoriums).toHaveLength(7);
});
});
40 changes: 40 additions & 0 deletions src/__tests__/backends/pretalx/PretalxParser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import path from "node:path";
import { test, expect } from "@jest/globals";
import { parseFromJSON } from "../../../backends/pretalx/PretalxParser";
import { readFile } from "node:fs/promises";
import { IPrefixConfig } from "../../../config";

const prefixConfig: IPrefixConfig = {
// Unused here.
aliases: "", displayNameSuffixes: {}, suffixes: {}, physicalAuditoriumRooms: [],

auditoriumRooms: [
"AW1.",
"D.",
"H.",
"Janson",
"K.",
"M.",
"UA2.",
"UB2.252A",
"UB4.",
"UB5.",
"UD2."
],
qaAuditoriumRooms: [
"AQ.",
],
interestRooms: [
"I."
],
nameOverrides: {
"A.special": "special-room",
},
};

test("can parse a standard XML format", async () => {
const xml = await readFile(path.join(__dirname, "anyconf.json"), 'utf-8');
const { title, talks } = await parseFromJSON(xml, prefixConfig);
expect(talks.size).toBe(2);
expect(title).toBe('AnyConf 2024');
});
168 changes: 168 additions & 0 deletions src/__tests__/backends/pretalx/anyconf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"_note": "This a snapshot of the FOSDEM 2024 schedule schema, with fake data.",
"schedule": {
"version": "2024-01-02 20:35",
"base_url": "https://pretalx.example.com/conf/schedule/",
"conference": {
"acronym": "anyconf-2024",
"title": "AnyConf 2024",
"start": "2024-02-03",
"end": "2024-02-04",
"daysCount": 2,
"timeslot_duration": "00:05",
"time_zone_name": "Europe/Brussels",
"rooms": [
{
"name": "janson",
"guid": null,
"description": "Janson",
"capacity": 1415
},
{
"name": "j1106",
"guid": null,
"description": "J.1.106",
"capacity": 70
},
{
"name": "k1105",
"guid": null,
"description": "K.1.105 (A room)",
"capacity": 805
},
{
"name": "h1301",
"guid": null,
"description": "H.1301 (Another room)",
"capacity": 189
},
{
"name": "aw1120",
"guid": null,
"description": "AW1.120",
"capacity": 74
},
{
"name": "ua2114",
"guid": null,
"description": "UA2.114 (Wow)",
"capacity": 207
},
{
"name": "ub2252a",
"guid": null,
"description": "UB2.252A (More)",
"capacity": 532
},
{
"name": "ud2120",
"guid": null,
"description": "UD2.120 (Rooms)",
"capacity": 446
},
{
"name": "a01",
"guid": null,
"description": "A.01 (Someroom)",
"capacity": 175
}
],
"days": [
{
"index": 1,
"date": "2024-02-03",
"day_start": "2024-02-03T04:00:00+01:00",
"day_end": "2024-02-04T03:59:00+01:00",
"rooms":{
"janson": [{
"id": 1234,
"guid": "5bb0aa4e-0c0e-5ccd-9523-0ed1ca679039",
"logo": "",
"date": "2024-02-03T09:00:00+01:00",
"start": "09:00",
"duration": "00:25",
"room": "janson",
"slug": "welcome talk",
"url": "https://pretalx.example.com/conf/talk/GK99DE/",
"title": "Welcome to AnyConf 2024",
"subtitle": "",
"track": "Keynotes",
"type": "Talk",
"language": "en",
"abstract": "AnyConf welcome and opening talk.",
"description": null,
"recording_license": "",
"do_not_record": false,
"persons": [
{
"id": 2,
"code": "37RA83",
"public_name": "AnyConf Staff",
"biography": null,
"answers": []
},
{
"id": 1324,
"code": "YT3EFD",
"public_name": "Alice AnyConf",
"biography": "Alice is a test user with a big robotic brain.",
"answers": []
}
],
"links": [],
"attachments": [],
"answers": []
}]
}
},
{
"index": 2,
"date": "2024-02-04",
"day_start": "2024-02-04T04:00:00+01:00",
"day_end": "2024-02-05T03:59:00+01:00",
"rooms":{
"janson": [{
"id": 1235,
"guid": "b8325b99-84af-45a7-806b-5819c79b6dc5",
"logo": "",
"date": "2024-02-03T09:00:00+01:00",
"start": "09:00",
"duration": "00:25",
"room": "janson",
"slug": "welcome talk",
"url": "https://pretalx.example.com/conf/talk/GK99DE/",
"title": "Welcome to AnyConf 2024",
"subtitle": "",
"track": "Keynotes",
"type": "Talk",
"language": "en",
"abstract": "AnyConf welcome and opening talk.",
"description": null,
"recording_license": "",
"do_not_record": false,
"persons": [
{
"id": 2,
"code": "37RA83",
"public_name": "AnyConf Staff",
"biography": null,
"answers": []
},
{
"id": 1324,
"code": "YT3EFD",
"public_name": "Alice AnyConf",
"biography": "Alice is a test user with a big robotic brain.",
"answers": []
}
],
"links": [],
"attachments": [],
"answers": []
}]
}
}
]
}
}
}

0 comments on commit 479f105

Please sign in to comment.