@happychef/algorithm 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,174 +1,168 @@
1
- const { isTimeAvailable } = require('../isTimeAvailable');
2
-
3
- // Mock the timeblocksAvailable function
4
- jest.mock('../processing/timeblocksAvailable', () => ({
5
- timeblocksAvailable: jest.fn()
6
- }));
7
-
8
- const { timeblocksAvailable } = require('../processing/timeblocksAvailable');
9
-
10
- describe('isTimeAvailable', () => {
11
- beforeEach(() => {
12
- jest.clearAllMocks();
13
- });
14
-
15
- test('should return true when the specific time is available', () => {
16
- timeblocksAvailable.mockReturnValue({
17
- '12:00': { name: '12:00' },
18
- '12:30': { name: '12:30' },
19
- '13:00': { name: '13:00' }
20
- });
21
-
22
- const data = { 'general-settings': {} };
23
- const result = isTimeAvailable(data, '2025-06-15', '12:30', [], 4);
24
-
25
- expect(result).toBe(true);
26
- expect(timeblocksAvailable).toHaveBeenCalledWith(
27
- data,
28
- '2025-06-15',
29
- [],
30
- 4,
31
- [],
32
- null,
33
- false,
34
- null
35
- );
36
- });
37
-
38
- test('should return false when the specific time is not available', () => {
39
- timeblocksAvailable.mockReturnValue({
40
- '12:00': { name: '12:00' },
41
- '13:00': { name: '13:00' }
42
- });
43
-
44
- const data = { 'general-settings': {} };
45
- const result = isTimeAvailable(data, '2025-06-15', '12:30', [], 4);
46
-
47
- expect(result).toBe(false);
48
- });
49
-
50
- test('should return false when no timeblocks are available', () => {
51
- timeblocksAvailable.mockReturnValue({});
52
-
53
- const data = { 'general-settings': {} };
54
- const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4);
55
-
56
- expect(result).toBe(false);
57
- });
58
-
59
- test('should handle reservations parameter', () => {
60
- timeblocksAvailable.mockReturnValue({
61
- '12:00': { name: '12:00' }
62
- });
63
-
64
- const data = { 'general-settings': {} };
65
- const reservations = [
66
- { date: '2025-06-15', time: '11:00', guests: 2 }
67
- ];
68
-
69
- const result = isTimeAvailable(data, '2025-06-15', '12:00', reservations, 4);
70
-
71
- expect(result).toBe(true);
72
- expect(timeblocksAvailable).toHaveBeenCalledWith(
73
- data,
74
- '2025-06-15',
75
- reservations,
76
- 4,
77
- [],
78
- null,
79
- false,
80
- null
81
- );
82
- });
83
-
84
- test('should handle blockedSlots parameter', () => {
85
- timeblocksAvailable.mockReturnValue({
86
- '12:00': { name: '12:00' }
87
- });
88
-
89
- const data = { 'general-settings': {} };
90
- const blockedSlots = [
91
- { date: '2025-06-15', time: '13:00' }
92
- ];
93
-
94
- const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4, blockedSlots);
95
-
96
- expect(result).toBe(true);
97
- expect(timeblocksAvailable).toHaveBeenCalledWith(
98
- data,
99
- '2025-06-15',
100
- [],
101
- 4,
102
- blockedSlots,
103
- null,
104
- false,
105
- null
106
- );
107
- });
108
-
109
- test('should handle giftcard parameter', () => {
110
- timeblocksAvailable.mockReturnValue({
111
- '12:00': { name: '12:00' }
112
- });
113
-
114
- const data = { 'general-settings': {} };
115
-
116
- const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4, [], 'LUNCH50');
117
-
118
- expect(result).toBe(true);
119
- expect(timeblocksAvailable).toHaveBeenCalledWith(
120
- data,
121
- '2025-06-15',
122
- [],
123
- 4,
124
- [],
125
- 'LUNCH50',
126
- false,
127
- null
128
- );
129
- });
130
-
131
- test('should handle isAdmin parameter', () => {
132
- timeblocksAvailable.mockReturnValue({
133
- '12:00': { name: '12:00' }
134
- });
135
-
136
- const data = { 'general-settings': {} };
137
-
138
- const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4, [], null, true);
139
-
140
- expect(result).toBe(true);
141
- expect(timeblocksAvailable).toHaveBeenCalledWith(
142
- data,
143
- '2025-06-15',
144
- [],
145
- 4,
146
- [],
147
- null,
148
- true,
149
- null
150
- );
151
- });
152
-
153
- test('should handle different guest counts', () => {
154
- timeblocksAvailable.mockReturnValue({
155
- '12:00': { name: '12:00' }
156
- });
157
-
158
- const data = { 'general-settings': {} };
159
-
160
- const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 10);
161
-
162
- expect(result).toBe(true);
163
- expect(timeblocksAvailable).toHaveBeenCalledWith(
164
- data,
165
- '2025-06-15',
166
- [],
167
- 10,
168
- [],
169
- null,
170
- false,
171
- null
172
- );
173
- });
174
- });
1
+ const { isTimeAvailable } = require('../isTimeAvailable');
2
+
3
+ // Mock the timeblocksAvailable function
4
+ jest.mock('../processing/timeblocksAvailable', () => ({
5
+ timeblocksAvailable: jest.fn()
6
+ }));
7
+
8
+ const { timeblocksAvailable } = require('../processing/timeblocksAvailable');
9
+
10
+ describe('isTimeAvailable', () => {
11
+ beforeEach(() => {
12
+ jest.clearAllMocks();
13
+ });
14
+
15
+ test('should return true when the specific time is available', () => {
16
+ timeblocksAvailable.mockReturnValue({
17
+ '12:00': { name: '12:00' },
18
+ '12:30': { name: '12:30' },
19
+ '13:00': { name: '13:00' }
20
+ });
21
+
22
+ const data = { 'general-settings': {} };
23
+ const result = isTimeAvailable(data, '2025-06-15', '12:30', [], 4);
24
+
25
+ expect(result).toBe(true);
26
+ expect(timeblocksAvailable).toHaveBeenCalledWith(
27
+ data,
28
+ '2025-06-15',
29
+ [],
30
+ 4,
31
+ [],
32
+ null,
33
+ false
34
+ );
35
+ });
36
+
37
+ test('should return false when the specific time is not available', () => {
38
+ timeblocksAvailable.mockReturnValue({
39
+ '12:00': { name: '12:00' },
40
+ '13:00': { name: '13:00' }
41
+ });
42
+
43
+ const data = { 'general-settings': {} };
44
+ const result = isTimeAvailable(data, '2025-06-15', '12:30', [], 4);
45
+
46
+ expect(result).toBe(false);
47
+ });
48
+
49
+ test('should return false when no timeblocks are available', () => {
50
+ timeblocksAvailable.mockReturnValue({});
51
+
52
+ const data = { 'general-settings': {} };
53
+ const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4);
54
+
55
+ expect(result).toBe(false);
56
+ });
57
+
58
+ test('should handle reservations parameter', () => {
59
+ timeblocksAvailable.mockReturnValue({
60
+ '12:00': { name: '12:00' }
61
+ });
62
+
63
+ const data = { 'general-settings': {} };
64
+ const reservations = [
65
+ { date: '2025-06-15', time: '11:00', guests: 2 }
66
+ ];
67
+
68
+ const result = isTimeAvailable(data, '2025-06-15', '12:00', reservations, 4);
69
+
70
+ expect(result).toBe(true);
71
+ expect(timeblocksAvailable).toHaveBeenCalledWith(
72
+ data,
73
+ '2025-06-15',
74
+ reservations,
75
+ 4,
76
+ [],
77
+ null,
78
+ false
79
+ );
80
+ });
81
+
82
+ test('should handle blockedSlots parameter', () => {
83
+ timeblocksAvailable.mockReturnValue({
84
+ '12:00': { name: '12:00' }
85
+ });
86
+
87
+ const data = { 'general-settings': {} };
88
+ const blockedSlots = [
89
+ { date: '2025-06-15', time: '13:00' }
90
+ ];
91
+
92
+ const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4, blockedSlots);
93
+
94
+ expect(result).toBe(true);
95
+ expect(timeblocksAvailable).toHaveBeenCalledWith(
96
+ data,
97
+ '2025-06-15',
98
+ [],
99
+ 4,
100
+ blockedSlots,
101
+ null,
102
+ false
103
+ );
104
+ });
105
+
106
+ test('should handle giftcard parameter', () => {
107
+ timeblocksAvailable.mockReturnValue({
108
+ '12:00': { name: '12:00' }
109
+ });
110
+
111
+ const data = { 'general-settings': {} };
112
+
113
+ const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4, [], 'LUNCH50');
114
+
115
+ expect(result).toBe(true);
116
+ expect(timeblocksAvailable).toHaveBeenCalledWith(
117
+ data,
118
+ '2025-06-15',
119
+ [],
120
+ 4,
121
+ [],
122
+ 'LUNCH50',
123
+ false
124
+ );
125
+ });
126
+
127
+ test('should handle isAdmin parameter', () => {
128
+ timeblocksAvailable.mockReturnValue({
129
+ '12:00': { name: '12:00' }
130
+ });
131
+
132
+ const data = { 'general-settings': {} };
133
+
134
+ const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 4, [], null, true);
135
+
136
+ expect(result).toBe(true);
137
+ expect(timeblocksAvailable).toHaveBeenCalledWith(
138
+ data,
139
+ '2025-06-15',
140
+ [],
141
+ 4,
142
+ [],
143
+ null,
144
+ true
145
+ );
146
+ });
147
+
148
+ test('should handle different guest counts', () => {
149
+ timeblocksAvailable.mockReturnValue({
150
+ '12:00': { name: '12:00' }
151
+ });
152
+
153
+ const data = { 'general-settings': {} };
154
+
155
+ const result = isTimeAvailable(data, '2025-06-15', '12:00', [], 10);
156
+
157
+ expect(result).toBe(true);
158
+ expect(timeblocksAvailable).toHaveBeenCalledWith(
159
+ data,
160
+ '2025-06-15',
161
+ [],
162
+ 10,
163
+ [],
164
+ null,
165
+ false
166
+ );
167
+ });
168
+ });