Skip to content

Commit 104f0a2

Browse files
committed
modified testing
1 parent 91fc3fc commit 104f0a2

File tree

1 file changed

+49
-45
lines changed

1 file changed

+49
-45
lines changed

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

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,108 @@
1-
import { describe, expect, it, test } from "@jest/globals";
1+
import {describe, expect, it, test} from '@jest/globals';
22

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

10-
describe("isValidOffering", () => {
6+
describe('isValidOffering', () => {
117
const sampleOffering: Offering = createOffering({
128
id: 1,
139
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',
1713
});
1814

19-
test("should allow offering if there are no restrictions", () => {
15+
test('should allow offering if there are no restrictions', () => {
2016
expect(isValidOffering(sampleOffering, [])).toBe(true);
2117
});
2218

23-
test("should allow offering if all restrictions are disabled", () => {
19+
test('should allow offering if all restrictions are disabled', () => {
2420
const restrictions: Restriction[] = [
2521
{
2622
type: RestrictionType.RestrictBefore,
27-
days: ["MO"],
28-
startTime: "",
29-
endTime: "09:00:00",
23+
days: ['MO'],
24+
startTime: '',
25+
endTime: '09:00:00',
3026
disabled: true,
3127
numDays: 0,
28+
maxGap: 24
3229
},
3330
];
3431
expect(isValidOffering(sampleOffering, restrictions)).toBe(true);
3532
});
3633

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

51-
test("should reject offering if it ends after restriction end time", () => {
51+
test('should reject offering if it ends after restriction end time', () => {
5252
const restrictions: Restriction[] = [
5353
{
5454
type: RestrictionType.RestrictAfter,
55-
days: ["MO"],
56-
startTime: "10:30:00",
57-
endTime: "",
55+
days: ['MO'],
56+
startTime: '10:30:00',
57+
endTime: '',
5858
disabled: false,
5959
numDays: 0,
60+
maxGap: 24
6061
},
6162
];
6263
expect(isValidOffering(sampleOffering, restrictions)).toBe(false);
6364
});
6465

65-
test("should reject offering if it is within restricted time range", () => {
66+
test('should reject offering if it is within restricted time range', () => {
6667
const restrictions: Restriction[] = [
6768
{
6869
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',
7273
disabled: false,
7374
numDays: 0,
75+
maxGap: 24
7476
},
7577
];
7678
expect(isValidOffering(sampleOffering, restrictions)).toBe(false);
7779
});
7880

79-
test("should reject offering if the day is restricted", () => {
81+
test('should reject offering if the day is restricted', () => {
8082
const restrictions: Restriction[] = [
8183
{
8284
type: RestrictionType.RestrictDay,
83-
days: ["MO"],
84-
startTime: "",
85-
endTime: "",
85+
days: ['MO'],
86+
startTime: '',
87+
endTime: '',
8688
disabled: false,
8789
numDays: 0,
90+
maxGap: 24
8891
},
8992
];
9093
expect(isValidOffering(sampleOffering, restrictions)).toBe(false);
9194
});
9295

93-
test("should allow offering if the day is not restricted", () => {
96+
test('should allow offering if the day is not restricted', () => {
9497
const restrictions: Restriction[] = [
9598
{
9699
type: RestrictionType.RestrictDay,
97-
days: ["TU"],
98-
startTime: "",
99-
endTime: "",
100+
days: ['TU'],
101+
startTime: '',
102+
endTime: '',
100103
disabled: false,
101104
numDays: 0,
105+
maxGap: 24
102106
},
103107
];
104108
expect(isValidOffering(sampleOffering, restrictions)).toBe(true);

0 commit comments

Comments
 (0)