example-onlyics.test.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const ICAL = require("ical.js");
  2. const radiomanifest = require("../radiomanifest.js");
  3. const chai = require("chai");
  4. chai.use(require("chai-as-promised"));
  5. const assert = chai.assert;
  6. const exampleName = "onlyics";
  7. const expect = chai.expect;
  8. const url =
  9. "https://radiomanifest.degenerazione.xyz/v0.2/examples/" + exampleName + "/";
  10. describe("examples/" + exampleName, () => {
  11. describe("schedule", () => {
  12. it("should find one event", async () => {
  13. const rm = await radiomanifest.get(url);
  14. assert.equal(rm.getSchedule().getEvents().length, 1);
  15. });
  16. it("with a specific name", async () => {
  17. const rm = await radiomanifest.get(url);
  18. const ev = rm.getSchedule().getEvents()[0];
  19. const summary = ev.getFirstProperty("summary").getFirstValue();
  20. assert.equal(summary, "JavaScript show");
  21. });
  22. it("happens every monday at 6AM", async () => {
  23. const rm = await radiomanifest.get(url);
  24. const rs = rm.getSchedule();
  25. const now = new ICAL.Time({
  26. year: 2022,
  27. month: 1,
  28. day: 3,
  29. hour: 6,
  30. minute: 30,
  31. second: 0,
  32. isDate: false,
  33. });
  34. const show = rs.getNowShow(now);
  35. assert.notEqual(show, null);
  36. assert.equal(show.getName(), "JavaScript show");
  37. });
  38. it("doesnt happen at any other time than 6AM", async () => {
  39. const rm = await radiomanifest.get(url);
  40. const rs = rm.getSchedule();
  41. const now = new ICAL.Time({
  42. year: 2022,
  43. month: 1,
  44. day: 3,
  45. hour: 9,
  46. minute: 0,
  47. second: 0,
  48. isDate: false,
  49. });
  50. const ev = rs.getNowEvent(now);
  51. assert.equal(ev, null);
  52. });
  53. });
  54. });