-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ac1b52
commit 0594690
Showing
3 changed files
with
423 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<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") { | ||
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); | ||
}); | ||
}); |
219 changes: 219 additions & 0 deletions
219
src/__tests__/backends/json/__snapshots__/JsonScheduleBackend.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": 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", | ||
}, | ||
} | ||
`; |
Oops, something went wrong.