|
| 1 | +import { describe, expect, it, test } from "@jest/globals"; |
| 2 | + |
| 3 | +import { |
| 4 | + createOffering, |
| 5 | + Offering, |
| 6 | + isValidOffering, |
| 7 | + Restriction, |
| 8 | + RestrictionType |
| 9 | +} from "../src/controllers/generatorController"; |
| 10 | + |
| 11 | +describe("isValidOffering", () => { |
| 12 | + const sampleOffering: Offering = createOffering({ |
| 13 | + id: 1, |
| 14 | + course_id: 101, |
| 15 | + day: "MO", |
| 16 | + start: "10:00:00", |
| 17 | + end: "11:00:00", |
| 18 | +}); |
| 19 | + |
| 20 | + test("should allow offering if there are no restrictions", () => { |
| 21 | + expect(isValidOffering(sampleOffering, [])).toBe(true); |
| 22 | + }); |
| 23 | + |
| 24 | + test("should allow offering if all restrictions are disabled", () => { |
| 25 | + const restrictions: Restriction[] = [ |
| 26 | + { type: RestrictionType.RestrictBefore, days: [], startTime: "09:00:00", endTime: "", disabled: true, numDays: 0 }, |
| 27 | + ]; |
| 28 | + expect(isValidOffering(sampleOffering, restrictions)).toBe(true); |
| 29 | + }); |
| 30 | + |
| 31 | + test("should reject offering if it starts before restriction start time", () => { |
| 32 | + const restrictions: Restriction[] = [ |
| 33 | + { type: RestrictionType.RestrictBefore, days: [], startTime: "10:30:00", endTime: "", disabled: false, numDays: 0 }, |
| 34 | + ]; |
| 35 | + expect(isValidOffering(sampleOffering, restrictions)).toBe(false); |
| 36 | + }); |
| 37 | + |
| 38 | + test("should reject offering if it ends after restriction end time", () => { |
| 39 | + const restrictions: Restriction[] = [ |
| 40 | + { type: RestrictionType.RestrictAfter, days: [], startTime: "", endTime: "10:30:00", disabled: false, numDays: 0 }, |
| 41 | + ]; |
| 42 | + expect(isValidOffering(sampleOffering, restrictions)).toBe(false); |
| 43 | + }); |
| 44 | + |
| 45 | + test("should reject offering if it is within restricted time range", () => { |
| 46 | + const restrictions: Restriction[] = [ |
| 47 | + { type: RestrictionType.RestrictBetween, days: [], startTime: "09:00:00", endTime: "12:00:00", disabled: false, numDays: 0 }, |
| 48 | + ]; |
| 49 | + expect(isValidOffering(sampleOffering, restrictions)).toBe(false); |
| 50 | + }); |
| 51 | + |
| 52 | + test("should reject offering if the day is restricted", () => { |
| 53 | + const restrictions: Restriction[] = [ |
| 54 | + { type: RestrictionType.RestrictDay, days: ["MO"], startTime: "", endTime: "", disabled: false, numDays: 0 }, |
| 55 | + ]; |
| 56 | + expect(isValidOffering(sampleOffering, restrictions)).toBe(false); |
| 57 | + }); |
| 58 | + |
| 59 | + test("should allow offering if the day is not restricted", () => { |
| 60 | + const restrictions: Restriction[] = [ |
| 61 | + { type: RestrictionType.RestrictDay, days: ["TU"], startTime: "", endTime: "", disabled: false, numDays: 0 }, |
| 62 | + ]; |
| 63 | + expect(isValidOffering(sampleOffering, restrictions)).toBe(true); |
| 64 | + }); |
| 65 | +}); |
0 commit comments