-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from yamitzky/feat/private-calendar
Feat/private calendar
- Loading branch information
Showing
8 changed files
with
272 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { getEvents } from '@synk-cal/usecase' | ||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
import { loader } from '../app/routes/_index' | ||
|
||
vi.mock('@synk-cal/usecase', () => ({ | ||
getEvents: vi.fn(), | ||
})) | ||
|
||
vi.mock('@synk-cal/core', () => ({ | ||
config: { | ||
CALENDAR_IDS: ['public_calendar_id'], | ||
PRIVATE_CALENDAR_IDS: ['private_calendar_id'], | ||
}, | ||
})) | ||
|
||
// getAuthRepository のモックを変数として定義 | ||
const mockGetUserFromHeader = vi.fn() | ||
vi.mock('~/services/getAuthRepository', () => ({ | ||
getAuthRepository: vi.fn(() => ({ | ||
getUserFromHeader: mockGetUserFromHeader, | ||
})), | ||
})) | ||
|
||
vi.mock('~/services/getCalendarRepository', () => ({ | ||
getCalendarRepository: vi.fn(() => ({ | ||
getEvents: vi.fn(), | ||
})), | ||
})) | ||
|
||
vi.mock('~/services/getGroupRepository', () => ({ | ||
getGroupRepository: vi.fn(), | ||
})) | ||
|
||
describe('_index', () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks() | ||
mockGetUserFromHeader.mockResolvedValue(undefined) | ||
}) | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks() | ||
}) | ||
|
||
describe('loader', () => { | ||
it('should load events with default date range', async () => { | ||
const request = new Request('http://localhost/') | ||
vi.mocked(getEvents).mockResolvedValue([]) | ||
|
||
const response = await loader({ request, params: {}, context: {} }) | ||
const data = await response.json() | ||
|
||
expect(data).toEqual({ | ||
calendars: [ | ||
{ calendarId: 'public_calendar_id', events: [] }, | ||
{ calendarId: 'private_calendar_id', events: [] }, | ||
], | ||
isMobile: false, | ||
startDate: expect.any(String), | ||
endDate: expect.any(String), | ||
user: undefined, | ||
}) | ||
}) | ||
|
||
it('should load events with specified date range', async () => { | ||
const request = new Request('http://localhost/?startDate=2025-02-14&endDate=2025-02-21') | ||
vi.mocked(getEvents).mockResolvedValue([]) | ||
|
||
const response = await loader({ request, params: {}, context: {} }) | ||
const data = await response.json() | ||
|
||
expect(data).toEqual({ | ||
calendars: [ | ||
{ calendarId: 'public_calendar_id', events: [] }, | ||
{ calendarId: 'private_calendar_id', events: [] }, | ||
], | ||
isMobile: false, | ||
startDate: '2025-02-14', | ||
endDate: '2025-02-21', | ||
user: undefined, | ||
}) | ||
}) | ||
|
||
it('should detect mobile user agent', async () => { | ||
const request = new Request('http://localhost/', { | ||
headers: { | ||
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) Mobile/123', | ||
}, | ||
}) | ||
vi.mocked(getEvents).mockResolvedValue([]) | ||
|
||
const response = await loader({ request, params: {}, context: {} }) | ||
const data = await response.json() | ||
|
||
expect(data.isMobile).toBe(true) | ||
}) | ||
|
||
it('should load private calendar events for authenticated user', async () => { | ||
const request = new Request('http://localhost/') | ||
const mockUser = { email: '[email protected]' } | ||
mockGetUserFromHeader.mockResolvedValue(mockUser) | ||
vi.mocked(getEvents).mockResolvedValue([]) | ||
|
||
const response = await loader({ request, params: {}, context: {} }) | ||
const data = await response.json() | ||
|
||
expect(data.user).toEqual(mockUser) | ||
expect(getEvents).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
attendeeEmail: mockUser.email, | ||
}), | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ describe('Config', () => { | |
NODE_ENV: 'test', | ||
GOOGLE_AUTH_SUBJECT: '[email protected]', | ||
CALENDAR_IDS: 'calendar1,calendar2', | ||
PRIVATE_CALENDAR_IDS: 'calendar3,calendar4', | ||
REMINDER_SETTINGS: JSON.stringify([ | ||
{ minutesBefore: 10, notificationType: 'email' }, | ||
{ hour: 9, minute: 0, notificationType: 'sms', target: '+1234567890' }, | ||
|
@@ -25,6 +26,7 @@ describe('Config', () => { | |
expect(parsedConfig).toEqual({ | ||
GOOGLE_AUTH_SUBJECT: '[email protected]', | ||
CALENDAR_IDS: ['calendar1', 'calendar2'], | ||
PRIVATE_CALENDAR_IDS: ['calendar3', 'calendar4'], | ||
TIMEZONE: 'UTC', | ||
REMINDER_SETTINGS: [ | ||
{ minutesBefore: 10, notificationType: 'email' }, | ||
|
@@ -50,6 +52,7 @@ describe('Config', () => { | |
expect(parsedConfig).toEqual({ | ||
GOOGLE_AUTH_SUBJECT: undefined, | ||
CALENDAR_IDS: ['calendar1'], | ||
PRIVATE_CALENDAR_IDS: [], | ||
TIMEZONE: 'UTC', | ||
REMINDER_SETTINGS: [], | ||
REMINDER_TEMPLATE: undefined, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.