radiomanifest.js/test/example-onlyics.test.js

60 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-09-14 01:07:07 +02:00
const ICAL = require("ical.js");
2022-01-30 02:24:56 +01:00
2023-09-14 01:07:07 +02:00
const radiomanifest = require("../radiomanifest.js");
const chai = require("chai");
chai.use(require("chai-as-promised"));
const assert = chai.assert;
2022-01-30 02:24:56 +01:00
2023-09-14 01:07:07 +02:00
const exampleName = "onlyics";
const expect = chai.expect;
const url =
"https://radiomanifest.degenerazione.xyz/v0.2/examples/" + exampleName + "/";
2022-01-30 02:24:56 +01:00
2023-09-14 01:07:07 +02:00
describe("examples/" + exampleName, () => {
describe("schedule", () => {
it("should find one event", async () => {
const rm = await radiomanifest.get(url);
assert.equal(rm.getSchedule().getEvents().length, 1);
});
it("with a specific name", async () => {
const rm = await radiomanifest.get(url);
const ev = rm.getSchedule().getEvents()[0];
const summary = ev.getFirstProperty("summary").getFirstValue();
assert.equal(summary, "JavaScript show");
});
2022-01-30 02:24:56 +01:00
2023-09-14 01:07:07 +02:00
it("happens every monday at 6AM", async () => {
const rm = await radiomanifest.get(url);
const rs = rm.getSchedule();
2022-01-30 02:24:56 +01:00
const now = new ICAL.Time({
2023-09-14 01:07:07 +02:00
year: 2022,
month: 1,
day: 3,
hour: 6,
minute: 30,
second: 0,
isDate: false,
});
const show = rs.getNowShow(now);
assert.notEqual(show, null);
assert.equal(show.getName(), "JavaScript show");
});
2022-01-30 02:24:56 +01:00
2023-09-14 01:07:07 +02:00
it("doesnt happen at any other time than 6AM", async () => {
const rm = await radiomanifest.get(url);
const rs = rm.getSchedule();
2022-01-30 02:24:56 +01:00
const now = new ICAL.Time({
2023-09-14 01:07:07 +02:00
year: 2022,
month: 1,
day: 3,
hour: 9,
minute: 0,
second: 0,
isDate: false,
});
const ev = rs.getNowEvent(now);
assert.equal(ev, null);
});
});
});