|
1 | | -import {describe, expect, it, test} from '@jest/globals'; |
| 1 | +import { describe, expect, it, test } from "@jest/globals"; |
2 | 2 |
|
3 | | -import {createOffering, isValidOffering, Offering, Restriction, RestrictionType,} from '../src/controllers/generatorController'; |
| 3 | +import { |
| 4 | + createOffering, |
| 5 | + isValidOffering, |
| 6 | + Offering, |
| 7 | + Restriction, |
| 8 | + RestrictionType, |
| 9 | +} from "../src/controllers/generatorController"; |
4 | 10 |
|
5 | | -describe('isValidOffering', () => { |
| 11 | +describe("isValidOffering", () => { |
6 | 12 | const sampleOffering: Offering = createOffering({ |
7 | 13 | id: 1, |
8 | 14 | course_id: 101, |
9 | | - day: 'MO', |
10 | | - start: '10:00:00', |
11 | | - end: '11:00:00', |
| 15 | + day: "MO", |
| 16 | + start: "10:00:00", |
| 17 | + end: "11:00:00", |
12 | 18 | }); |
13 | 19 |
|
14 | | - test('should allow offering if there are no restrictions', () => { |
| 20 | + test("should allow offering if there are no restrictions", () => { |
15 | 21 | expect(isValidOffering(sampleOffering, [])).toBe(true); |
16 | 22 | }); |
17 | 23 |
|
18 | | - test('should allow offering if all restrictions are disabled', () => { |
| 24 | + test("should allow offering if all restrictions are disabled", () => { |
19 | 25 | const restrictions: Restriction[] = [ |
20 | 26 | { |
21 | 27 | type: RestrictionType.RestrictBefore, |
22 | | - days: ['MO'], |
23 | | - startTime: '', |
24 | | - endTime: '09:00:00', |
| 28 | + days: ["MO"], |
| 29 | + startTime: "", |
| 30 | + endTime: "09:00:00", |
25 | 31 | disabled: true, |
26 | 32 | numDays: 0, |
27 | 33 | }, |
28 | 34 | ]; |
29 | 35 | expect(isValidOffering(sampleOffering, restrictions)).toBe(true); |
30 | 36 | }); |
31 | 37 |
|
32 | | - test( |
33 | | - 'should reject offering if it starts before restriction start time', |
34 | | - () => { |
35 | | - const restrictions: Restriction[] = [ |
36 | | - { |
37 | | - type: RestrictionType.RestrictBefore, |
38 | | - days: ['MO'], |
39 | | - startTime: '', |
40 | | - endTime: '11:00:00', |
41 | | - disabled: false, |
42 | | - numDays: 0, |
43 | | - }, |
44 | | - ]; |
45 | | - expect(isValidOffering(sampleOffering, restrictions)).toBe(false); |
46 | | - }); |
| 38 | + test("should reject offering if it starts before restriction start time", () => { |
| 39 | + const restrictions: Restriction[] = [ |
| 40 | + { |
| 41 | + type: RestrictionType.RestrictBefore, |
| 42 | + days: ["MO"], |
| 43 | + startTime: "", |
| 44 | + endTime: "11:00:00", |
| 45 | + disabled: false, |
| 46 | + numDays: 0, |
| 47 | + }, |
| 48 | + ]; |
| 49 | + expect(isValidOffering(sampleOffering, restrictions)).toBe(false); |
| 50 | + }); |
47 | 51 |
|
48 | | - test('should reject offering if it ends after restriction end time', () => { |
| 52 | + test("should reject offering if it ends after restriction end time", () => { |
49 | 53 | const restrictions: Restriction[] = [ |
50 | 54 | { |
51 | 55 | type: RestrictionType.RestrictAfter, |
52 | | - days: ['MO'], |
53 | | - startTime: '10:30:00', |
54 | | - endTime: '', |
| 56 | + days: ["MO"], |
| 57 | + startTime: "10:30:00", |
| 58 | + endTime: "", |
55 | 59 | disabled: false, |
56 | 60 | numDays: 0, |
57 | 61 | }, |
58 | 62 | ]; |
59 | 63 | expect(isValidOffering(sampleOffering, restrictions)).toBe(false); |
60 | 64 | }); |
61 | 65 |
|
62 | | - test('should reject offering if it is within restricted time range', () => { |
| 66 | + test("should reject offering if it is within restricted time range", () => { |
63 | 67 | const restrictions: Restriction[] = [ |
64 | 68 | { |
65 | 69 | type: RestrictionType.RestrictBetween, |
66 | | - days: ['MO'], |
67 | | - startTime: '09:00:00', |
68 | | - endTime: '12:00:00', |
| 70 | + days: ["MO"], |
| 71 | + startTime: "09:00:00", |
| 72 | + endTime: "12:00:00", |
69 | 73 | disabled: false, |
70 | 74 | numDays: 0, |
71 | 75 | }, |
72 | 76 | ]; |
73 | 77 | expect(isValidOffering(sampleOffering, restrictions)).toBe(false); |
74 | 78 | }); |
75 | 79 |
|
76 | | - test('should reject offering if the day is restricted', () => { |
| 80 | + test("should reject offering if the day is restricted", () => { |
77 | 81 | const restrictions: Restriction[] = [ |
78 | 82 | { |
79 | 83 | type: RestrictionType.RestrictDay, |
80 | | - days: ['MO'], |
81 | | - startTime: '', |
82 | | - endTime: '', |
| 84 | + days: ["MO"], |
| 85 | + startTime: "", |
| 86 | + endTime: "", |
83 | 87 | disabled: false, |
84 | 88 | numDays: 0, |
85 | 89 | }, |
86 | 90 | ]; |
87 | 91 | expect(isValidOffering(sampleOffering, restrictions)).toBe(false); |
88 | 92 | }); |
89 | 93 |
|
90 | | - test('should allow offering if the day is not restricted', () => { |
| 94 | + test("should allow offering if the day is not restricted", () => { |
91 | 95 | const restrictions: Restriction[] = [ |
92 | 96 | { |
93 | 97 | type: RestrictionType.RestrictDay, |
94 | | - days: ['TU'], |
95 | | - startTime: '', |
96 | | - endTime: '', |
| 98 | + days: ["TU"], |
| 99 | + startTime: "", |
| 100 | + endTime: "", |
97 | 101 | disabled: false, |
98 | 102 | numDays: 0, |
99 | 103 | }, |
|
0 commit comments