|
3 | 3 | adjustToLosAngelesTime, |
4 | 4 | isSameUTCDate, |
5 | 5 | doesEventExist, |
6 | | - createEvent, |
| 6 | + createEvents, |
7 | 7 | filterAndCreateEvents, |
8 | 8 | runTask, |
9 | 9 | scheduleTask, |
@@ -189,7 +189,7 @@ describe('createRecurringEvents Module Tests', () => { |
189 | 189 | expect(fetch).toHaveBeenCalledWith( |
190 | 190 | `${mockURL}/api/events/`, |
191 | 191 | expect.objectContaining({ |
192 | | - body: JSON.stringify(expectedEvent), |
| 192 | + body: JSON.stringify([expectedEvent]), |
193 | 193 | }), |
194 | 194 | ); |
195 | 195 |
|
@@ -222,7 +222,7 @@ describe('createRecurringEvents Module Tests', () => { |
222 | 222 | expect(fetch).toHaveBeenCalledWith( |
223 | 223 | `${mockURL}/api/events/`, |
224 | 224 | expect.objectContaining({ |
225 | | - body: JSON.stringify(expectedEvent), |
| 225 | + body: JSON.stringify([expectedEvent]), |
226 | 226 | }), |
227 | 227 | ); |
228 | 228 |
|
@@ -256,7 +256,7 @@ describe('createRecurringEvents Module Tests', () => { |
256 | 256 | expect(fetch).toHaveBeenCalledWith( |
257 | 257 | `${mockURL}/api/events/`, |
258 | 258 | expect.objectContaining({ |
259 | | - body: JSON.stringify(expectedEvent), |
| 259 | + body: JSON.stringify([expectedEvent]), |
260 | 260 | }), |
261 | 261 | ); |
262 | 262 |
|
@@ -289,7 +289,7 @@ describe('createRecurringEvents Module Tests', () => { |
289 | 289 | expect(fetch).toHaveBeenCalledWith( |
290 | 290 | `${mockURL}/api/events/`, |
291 | 291 | expect.objectContaining({ |
292 | | - body: JSON.stringify(expectedEvent), |
| 292 | + body: JSON.stringify([expectedEvent]), |
293 | 293 | }), |
294 | 294 | ); |
295 | 295 |
|
@@ -330,31 +330,32 @@ describe('createRecurringEvents Module Tests', () => { |
330 | 330 | }); |
331 | 331 | }); |
332 | 332 |
|
333 | | - describe('createEvent', () => { |
| 333 | + describe('createEvents', () => { |
334 | 334 | it('should create a new event via POST request', async () => { |
335 | 335 | const mockEvent = { name: 'Event 1', date: '2023-11-02T19:00:00Z' }; |
| 336 | + const mockEventArray = [mockEvent]; |
336 | 337 | fetch.mockResolvedValueOnce({ |
337 | 338 | ok: true, |
338 | 339 | json: jest.fn().mockResolvedValue({ id: 1, ...mockEvent }), |
339 | 340 | }); |
340 | 341 |
|
341 | | - const result = await createEvent(mockEvent, mockURL, mockHeader, fetch); |
| 342 | + const result = await createEvents(mockEventArray, mockURL, mockHeader, fetch); |
342 | 343 |
|
343 | 344 | expect(fetch).toHaveBeenCalledWith(`${mockURL}/api/events/`, { |
344 | 345 | method: 'POST', |
345 | 346 | headers: { |
346 | 347 | 'Content-Type': 'application/json', |
347 | 348 | 'x-customrequired-header': mockHeader, |
348 | 349 | }, |
349 | | - body: JSON.stringify(mockEvent), |
| 350 | + body: JSON.stringify(mockEventArray), |
350 | 351 | }); |
351 | 352 | expect(result).toEqual({ id: 1, ...mockEvent }); |
352 | 353 | }); |
353 | 354 |
|
354 | 355 | it('should return null if event creation fails', async () => { |
355 | 356 | fetch.mockRejectedValueOnce(new Error('Network error')); |
356 | 357 |
|
357 | | - const result = await createEvent(null, mockURL, mockHeader, fetch); |
| 358 | + const result = await createEvents(null, mockURL, mockHeader, fetch); |
358 | 359 |
|
359 | 360 | expect(result).toBeNull(); |
360 | 361 | }); |
|
0 commit comments