Skip to content

Commit 12f4526

Browse files
committed
bug fix for isValidOffering
1 parent 5dda1c6 commit 12f4526

File tree

2 files changed

+134
-126
lines changed

2 files changed

+134
-126
lines changed

course-matrix/backend/__tests__/isValidOffering.test.ts

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,99 @@
1-
import { describe, expect, it, test } from "@jest/globals";
1+
import {describe, expect, it, test} from '@jest/globals';
22

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';
104

11-
describe("isValidOffering", () => {
5+
describe('isValidOffering', () => {
126
const sampleOffering: Offering = createOffering({
137
id: 1,
148
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',
1812
});
1913

20-
test("should allow offering if there are no restrictions", () => {
14+
test('should allow offering if there are no restrictions', () => {
2115
expect(isValidOffering(sampleOffering, [])).toBe(true);
2216
});
2317

24-
test("should allow offering if all restrictions are disabled", () => {
18+
test('should allow offering if all restrictions are disabled', () => {
2519
const restrictions: Restriction[] = [
2620
{
2721
type: RestrictionType.RestrictBefore,
28-
days: [],
29-
startTime: "09:00:00",
30-
endTime: "",
22+
days: ['MO'],
23+
startTime: '',
24+
endTime: '09:00:00',
3125
disabled: true,
3226
numDays: 0,
3327
},
3428
];
3529
expect(isValidOffering(sampleOffering, restrictions)).toBe(true);
3630
});
3731

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+
});
5147

52-
test("should reject offering if it ends after restriction end time", () => {
48+
test('should reject offering if it ends after restriction end time', () => {
5349
const restrictions: Restriction[] = [
5450
{
5551
type: RestrictionType.RestrictAfter,
56-
days: [],
57-
startTime: "",
58-
endTime: "10:30:00",
52+
days: ['MO'],
53+
startTime: '10:30:00',
54+
endTime: '',
5955
disabled: false,
6056
numDays: 0,
6157
},
6258
];
6359
expect(isValidOffering(sampleOffering, restrictions)).toBe(false);
6460
});
6561

66-
test("should reject offering if it is within restricted time range", () => {
62+
test('should reject offering if it is within restricted time range', () => {
6763
const restrictions: Restriction[] = [
6864
{
6965
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',
7369
disabled: false,
7470
numDays: 0,
7571
},
7672
];
7773
expect(isValidOffering(sampleOffering, restrictions)).toBe(false);
7874
});
7975

80-
test("should reject offering if the day is restricted", () => {
76+
test('should reject offering if the day is restricted', () => {
8177
const restrictions: Restriction[] = [
8278
{
8379
type: RestrictionType.RestrictDay,
84-
days: ["MO"],
85-
startTime: "",
86-
endTime: "",
80+
days: ['MO'],
81+
startTime: '',
82+
endTime: '',
8783
disabled: false,
8884
numDays: 0,
8985
},
9086
];
9187
expect(isValidOffering(sampleOffering, restrictions)).toBe(false);
9288
});
9389

94-
test("should allow offering if the day is not restricted", () => {
90+
test('should allow offering if the day is not restricted', () => {
9591
const restrictions: Restriction[] = [
9692
{
9793
type: RestrictionType.RestrictDay,
98-
days: ["TU"],
99-
startTime: "",
100-
endTime: "",
94+
days: ['TU'],
95+
startTime: '',
96+
endTime: '',
10197
disabled: false,
10298
numDays: 0,
10399
},

0 commit comments

Comments
 (0)