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