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