|
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import { setupTest } from 'ember-qunit'; |
| 3 | +import { DateTime } from 'luxon'; |
| 4 | +import EventsBase from 'ilios-common/classes/events-base'; |
| 5 | +module('Unit | Services | events-base', function (hooks) { |
| 6 | + setupTest(hooks); |
| 7 | + |
| 8 | + hooks.beforeEach(function () { |
| 9 | + // EventsBase is declared in a non-standard location (i.e. not in a `/services` subdirectory). |
| 10 | + // So it doesn't get automatically registered as service here. |
| 11 | + this.owner.register('service:events-base', EventsBase); |
| 12 | + this.eventsBase = this.owner.lookup('service:events-base'); |
| 13 | + }); |
| 14 | + |
| 15 | + test.each( |
| 16 | + 'createEventFromData() - create user event from data for ILM', |
| 17 | + [ |
| 18 | + ['2025-11-10T09:45:00', '2025-11-10T10:00:00', '2025-11-10T09:45:00', '2025-11-10T10:00:00'], |
| 19 | + // these are edge-cases for ILM-based events. |
| 20 | + // If the event starts at 11:45p or later in the given day, |
| 21 | + // then pin the calendar start- and end-date to 11:45p and 11:59 in that day. |
| 22 | + ['2025-11-10T23:45:00', '2025-11-11T00:00:00', '2025-11-10T23:45:00', '2025-11-10T23:59:00'], |
| 23 | + ['2025-11-10T23:50:00', '2026-11-11T00:05:00', '2025-11-10T23:45:00', '2025-11-10T23:59:00'], |
| 24 | + ['2025-11-10T23:59:00', '2026-11-11T00:14:00', '2025-11-10T23:45:00', '2025-11-10T23:59:00'], |
| 25 | + ], |
| 26 | + async function ( |
| 27 | + assert, |
| 28 | + [startDate, endDate, expectedCalendarStartDate, expectedCalendarEndDate], |
| 29 | + ) { |
| 30 | + let event = this.eventsBase.createEventFromData( |
| 31 | + { |
| 32 | + ilmSession: 111, |
| 33 | + startDate: startDate, |
| 34 | + endDate: endDate, |
| 35 | + prerequisites: [], |
| 36 | + postrequisites: [], |
| 37 | + }, |
| 38 | + true, |
| 39 | + ); |
| 40 | + assert.strictEqual(event.startDate, startDate); |
| 41 | + assert.strictEqual(event.endDate, endDate); |
| 42 | + assert.strictEqual( |
| 43 | + DateTime.fromISO(event.calendarStartDate).toISO(), |
| 44 | + DateTime.fromISO(expectedCalendarStartDate).toISO(), |
| 45 | + ); |
| 46 | + assert.strictEqual( |
| 47 | + DateTime.fromISO(event.calendarEndDate).toISO(), |
| 48 | + DateTime.fromISO(expectedCalendarEndDate).toISO(), |
| 49 | + ); |
| 50 | + }, |
| 51 | + ); |
| 52 | +}); |
0 commit comments