mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-16 06:39:41 +02:00
test(calendar): add reminders API client tests
- 4 tests: getReminders (success + error), createReminder with body validation, deleteReminder endpoint - All 120 tests passing across 13 test files Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b38e5aecf9
commit
56c3086ec6
1 changed files with 83 additions and 0 deletions
83
apps/calendar/apps/web/src/lib/api/reminders.test.ts
Normal file
83
apps/calendar/apps/web/src/lib/api/reminders.test.ts
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('./client', () => ({
|
||||
fetchApi: vi.fn(),
|
||||
}));
|
||||
|
||||
import { fetchApi } from './client';
|
||||
import { getReminders, createReminder, deleteReminder } from './reminders';
|
||||
|
||||
const mockFetchApi = vi.mocked(fetchApi);
|
||||
|
||||
describe('reminders API client', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('getReminders', () => {
|
||||
it('should GET /events/:eventId/reminders', async () => {
|
||||
mockFetchApi.mockResolvedValue({
|
||||
data: [
|
||||
{ id: 'rem-1', eventId: 'evt-1', minutesBefore: 15, status: 'pending' },
|
||||
{ id: 'rem-2', eventId: 'evt-1', minutesBefore: 60, status: 'sent' },
|
||||
],
|
||||
error: null,
|
||||
});
|
||||
|
||||
const result = await getReminders('evt-1');
|
||||
|
||||
expect(mockFetchApi).toHaveBeenCalledWith('/events/evt-1/reminders');
|
||||
expect(result.data).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should return error on failure', async () => {
|
||||
mockFetchApi.mockResolvedValue({
|
||||
data: null,
|
||||
error: { message: 'Not found', code: 'NOT_FOUND', status: 404 },
|
||||
});
|
||||
|
||||
const result = await getReminders('nonexistent');
|
||||
|
||||
expect(result.error).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('createReminder', () => {
|
||||
it('should POST to /events/:eventId/reminders with body', async () => {
|
||||
mockFetchApi.mockResolvedValue({
|
||||
data: { id: 'rem-new', eventId: 'evt-1', minutesBefore: 30, status: 'pending' },
|
||||
error: null,
|
||||
});
|
||||
|
||||
const result = await createReminder('evt-1', {
|
||||
eventId: 'evt-1',
|
||||
minutesBefore: 30,
|
||||
notifyPush: true,
|
||||
notifyEmail: false,
|
||||
});
|
||||
|
||||
expect(mockFetchApi).toHaveBeenCalledWith('/events/evt-1/reminders', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
eventId: 'evt-1',
|
||||
minutesBefore: 30,
|
||||
notifyPush: true,
|
||||
notifyEmail: false,
|
||||
},
|
||||
});
|
||||
expect(result.data).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteReminder', () => {
|
||||
it('should DELETE /reminders/:id', async () => {
|
||||
mockFetchApi.mockResolvedValue({ data: null, error: null });
|
||||
|
||||
await deleteReminder('rem-1');
|
||||
|
||||
expect(mockFetchApi).toHaveBeenCalledWith('/reminders/rem-1', {
|
||||
method: 'DELETE',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue