-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * Fix login not failing properly. * Add an initial user-store test along with test config files. * ➕ add alert store * 📦 update frontend dependencies * ➕ add appointment store tests * ➕ add calendar store tests --------- Co-authored-by: Andreas Müller <mail@devmount.de>
- Loading branch information
1 parent
fea6eec
commit c687fde
Showing
11 changed files
with
10,216 additions
and
641 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,5 @@ | ||
// Polyfill to fix use/createFetch... | ||
// Reference: https://github.com/reduxjs/redux-toolkit/issues/3254#issuecomment-1587624955 | ||
import nodeFetch, { Request, Response } from 'node-fetch'; | ||
|
||
Object.assign(global, { fetch: nodeFetch, Request, Response }); |
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,45 @@ | ||
import { expect, test, beforeEach, describe } from 'vitest'; | ||
import { useSiteNotificationStore } from '@/stores/alert-store'; | ||
import { createPinia, setActivePinia } from 'pinia'; | ||
|
||
|
||
describe('Site Notifications Store', () => { | ||
// Create a pinia instance before each test | ||
beforeEach(() => { | ||
setActivePinia(createPinia()); | ||
}); | ||
|
||
test('visible', () => { | ||
const alert = useSiteNotificationStore(); | ||
alert.show(123, 'title', 'message', 'url'); | ||
expect(alert.isVisible === true); | ||
}); | ||
test('attributes', () => { | ||
const alert = useSiteNotificationStore(); | ||
alert.show(123, 'title', 'message', 'url'); | ||
expect(alert.title === 'title'); | ||
expect(alert.actionUrl === 'url'); | ||
expect(alert.message === 'message'); | ||
}); | ||
test('same', () => { | ||
const alert = useSiteNotificationStore(); | ||
alert.show(123, 'title', 'message', 'url'); | ||
expect(alert.isSameNotification(123) === true); | ||
}); | ||
test('invisible at start', () => { | ||
const alert = useSiteNotificationStore(); | ||
expect(alert.isVisible === false); | ||
}); | ||
test('invisible after reset', () => { | ||
const alert = useSiteNotificationStore(); | ||
alert.show(123, 'title', 'message', 'url'); | ||
alert.reset(); | ||
expect(alert.isVisible === false); | ||
}); | ||
test('lock', () => { | ||
const alert = useSiteNotificationStore(); | ||
alert.lock(123); | ||
expect(alert.isVisible === false); | ||
expect(alert.isSameNotification(123) === true); | ||
}); | ||
}); |
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,101 @@ | ||
import { | ||
expect, | ||
test, | ||
beforeEach, | ||
describe, | ||
beforeAll, | ||
afterAll, | ||
afterEach, | ||
} from 'vitest'; | ||
import { useAppointmentStore } from '@/stores/appointment-store'; | ||
import { createPinia, setActivePinia } from 'pinia'; | ||
import { setupServer } from 'msw/node'; | ||
import { HttpResponse, http } from 'msw'; | ||
import { createFetch } from '@vueuse/core'; | ||
|
||
const API_URL = 'http://localhost'; | ||
|
||
const restHandlers = [ | ||
http.get(`${API_URL}/me/appointments`, async (request) => { | ||
return HttpResponse.json([ | ||
{ | ||
calendar_id: 1, | ||
title: "title", | ||
duration: 180, | ||
location_type: 2, | ||
slots: [ | ||
{ start: "3000-01-01T09:00:00Z", duration: 60 }, | ||
{ start: "3000-01-01T11:00:00Z", duration: 15 }, | ||
{ start: "3000-01-01T15:00:00Z", duration: 275 }, | ||
], | ||
}, | ||
{ | ||
calendar_id: 1, | ||
title: "title", | ||
duration: 180, | ||
location_type: 2, | ||
slots: [ | ||
{ start: "2024-01-01T09:00:00Z", duration: 60 }, | ||
{ start: "2024-01-01T11:00:00Z", duration: 15, attendee_id: 1 }, | ||
{ start: "2024-01-01T15:00:00Z", duration: 275 }, | ||
], | ||
}, | ||
]); | ||
}), | ||
]; | ||
|
||
const server = setupServer(...restHandlers); | ||
server.events.on('request:start', ({ request }) => { | ||
// console.log('Outgoing:', request.method, request.url); | ||
}); | ||
|
||
describe('Appointment Store', () => { | ||
// Create a pinia instance before each test | ||
beforeEach(() => { | ||
setActivePinia(createPinia()); | ||
}); | ||
// Start server before all tests | ||
beforeAll(() => server.listen()); | ||
|
||
// Close server after all tests | ||
afterAll(() => server.close()); | ||
|
||
// Reset handlers after each test `important for test isolation` | ||
afterEach(() => server.resetHandlers()); | ||
|
||
|
||
test('init', () => { | ||
const apmt = useAppointmentStore(); | ||
expect(apmt.isLoaded === false); | ||
expect(apmt.appointments.length === 0); | ||
}); | ||
|
||
test('fetch', async () => { | ||
const apmt = useAppointmentStore(); | ||
await apmt.fetch(createFetch({ baseUrl: API_URL })); | ||
expect(apmt.appointments.length === 2); | ||
expect(apmt.appointments[0].slots.length === 3); | ||
}); | ||
|
||
test('pending', async () => { | ||
const apmt = useAppointmentStore(); | ||
await apmt.fetch(createFetch({ baseUrl: API_URL })); | ||
expect(apmt.pendingAppointments.length === 1); | ||
}); | ||
|
||
test('reset', async () => { | ||
const apmt = useAppointmentStore(); | ||
await apmt.fetch(createFetch({ baseUrl: API_URL })); | ||
|
||
// Check if appointments exist | ||
expect(apmt.isLoaded === true); | ||
expect(apmt.appointments.length === 2); | ||
|
||
// Reset the user which should null all user data. | ||
apmt.reset(); | ||
|
||
// Ensure our data is null/don't exist | ||
expect(apmt.isLoaded === false); | ||
expect(apmt.appointments.length === 0); | ||
}); | ||
}); |
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,96 @@ | ||
import { | ||
expect, | ||
test, | ||
beforeEach, | ||
describe, | ||
beforeAll, | ||
afterAll, | ||
afterEach, | ||
} from 'vitest'; | ||
import { useCalendarStore } from '@/stores/calendar-store'; | ||
import { createPinia, setActivePinia } from 'pinia'; | ||
import { setupServer } from 'msw/node'; | ||
import { HttpResponse, http } from 'msw'; | ||
import { createFetch } from '@vueuse/core'; | ||
|
||
const API_URL = 'http://localhost'; | ||
|
||
const restHandlers = [ | ||
http.get(`${API_URL}/me/calendars`, async (request) => { | ||
return HttpResponse.json([ | ||
{ | ||
id: 1, | ||
title: "title", | ||
color: "#123456", | ||
connected: true, | ||
}, | ||
{ | ||
id: 2, | ||
title: "title", | ||
color: "#123456", | ||
connected: false, | ||
}, | ||
]); | ||
}), | ||
]; | ||
|
||
const server = setupServer(...restHandlers); | ||
server.events.on('request:start', ({ request }) => { | ||
// console.log('Outgoing:', request.method, request.url); | ||
}); | ||
|
||
describe('Calendar Store', () => { | ||
// Create a pinia instance before each test | ||
beforeEach(() => { | ||
setActivePinia(createPinia()); | ||
}); | ||
// Start server before all tests | ||
beforeAll(() => server.listen()); | ||
|
||
// Close server after all tests | ||
afterAll(() => server.close()); | ||
|
||
// Reset handlers after each test `important for test isolation` | ||
afterEach(() => server.resetHandlers()); | ||
|
||
|
||
test('init', () => { | ||
const calStore = useCalendarStore(); | ||
expect(calStore.isLoaded === false); | ||
expect(calStore.allCalendars.length === 0); | ||
}); | ||
|
||
test('fetch', async () => { | ||
const calStore = useCalendarStore(); | ||
await calStore.fetch(createFetch({ baseUrl: API_URL })); | ||
expect(calStore.allCalendars.length === 2); | ||
}); | ||
|
||
test('unconnected', async () => { | ||
const calStore = useCalendarStore(); | ||
await calStore.fetch(createFetch({ baseUrl: API_URL })); | ||
expect(calStore.unconnectedCalendars.length === 1); | ||
}); | ||
|
||
test('connected', async () => { | ||
const calStore = useCalendarStore(); | ||
await calStore.fetch(createFetch({ baseUrl: API_URL })); | ||
expect(calStore.connectedCalendars.length === 1); | ||
}); | ||
|
||
test('reset', async () => { | ||
const calStore = useCalendarStore(); | ||
await calStore.fetch(createFetch({ baseUrl: API_URL })); | ||
|
||
// Check if calendars exist | ||
expect(calStore.isLoaded === true); | ||
expect(calStore.allCalendars.length === 2); | ||
|
||
// Reset the user which should null all user data. | ||
calStore.reset(); | ||
|
||
// Ensure our data is null/don't exist | ||
expect(calStore.isLoaded === false); | ||
expect(calStore.allCalendars.length === 0); | ||
}); | ||
}); |
Oops, something went wrong.