example-full-spore.test.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 = 'full-spore'
  7. const expect = chai.expect
  8. const url = 'https://radiomanifest.degenerazione.xyz/v0.2/examples/' + exampleName + '/'
  9. const testShowName = 'scaricomerci'
  10. const testNextShowName = 'nastrone notte'
  11. describe('examples/' + exampleName, () => {
  12. describe('schedule.getNow', () => {
  13. it('observes priority correctly', async () => {
  14. // tuesday, half past midnight
  15. const rm = await radiomanifest.get(url)
  16. const rs = rm.getSchedule()
  17. const now = new ICAL.Time({
  18. year: 2022,
  19. month: 1,
  20. day: 30,
  21. hour: 2,
  22. minute: 20,
  23. second: 0,
  24. isDate: false
  25. },
  26. ICAL.Timezone.utcTimezone
  27. );
  28. const vevent = rs.getNowEvent(now)
  29. assert.notEqual(vevent, null)
  30. const show = rs.getNowShow(now)
  31. assert.notEqual(show, null)
  32. assert.equal(show.getName(), testShowName)
  33. })
  34. })
  35. describe('schedule.getNext', () => {
  36. it('getNext observes priority correctly', async () => {
  37. // tuesday, half past midnight
  38. const rm = await radiomanifest.get(url)
  39. const rs = rm.getSchedule()
  40. const now = new ICAL.Time({
  41. year: 2022,
  42. month: 2,
  43. day: 2,
  44. hour: 2,
  45. minute: 20,
  46. second: 0,
  47. isDate: false
  48. },
  49. );
  50. const vevent = rs.getNowEvent(now)
  51. assert.notEqual(vevent, null)
  52. const show = rs.getNowShow(now)
  53. assert.notEqual(show, null)
  54. assert.equal(show.getName(), testShowName)
  55. const next_event = rs.getNextEvent(now)
  56. assert.notEqual(next_event, null)
  57. assert.isObject(next_event.event)
  58. assert.isObject(next_event.time)
  59. const next_show = rs.getNextShow(now)
  60. assert.isObject(next_show)
  61. assert.isObject(next_show.show)
  62. assert.equal(next_show.show.getName(), testNextShowName)
  63. const time = next_event.time.toJSDate()
  64. assert.equal(time.getHours(), 2)
  65. assert.equal(time.getMinutes(), 58)
  66. })
  67. })
  68. })