diff --git a/client/package.json b/client/package.json index a8d418e..f83c40b 100644 --- a/client/package.json +++ b/client/package.json @@ -2,7 +2,7 @@ "name": "calendub", "private": true, "version": "0.0.0", - "proxy": "http://localhost:5000/api", + "proxy": "http://localhost:5100", "type": "module", "scripts": { "dev": "vite", diff --git a/client/src/App.tsx b/client/src/App.tsx index 2366f37..603041d 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { Header, Calendar, @@ -17,6 +17,20 @@ const App = () => { setCurrentDate(newCurrentDate); }; + useEffect(() => { + getEvents(); + }); + + const getEvents = async () => { + try { + const response = await fetch('/api/events'); + const data = await response.json(); + console.log(data); + } catch (error) { + console.error('Error fetching events:', error); + } + }; + // TODO: How will this be structured? // Test events => feel free to change the values for testing // date and time field NOT FINAL => need to account for timezones (unless it's worked out in the backend) diff --git a/client/vite.config.ts b/client/vite.config.ts index d6d46b4..9518416 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -5,4 +5,13 @@ import tsconfigPaths from 'vite-tsconfig-paths'; // https://vite.dev/config/ export default defineConfig({ plugins: [react(), tsconfigPaths()], + server: { + proxy: { + '/api': { + target: 'http://localhost:5100', + changeOrigin: true, + secure: false, + }, + }, + }, }); diff --git a/server/tests/eventRoutes.test.js b/server/tests/eventRoutes.test.js index ec199fe..4fda359 100644 --- a/server/tests/eventRoutes.test.js +++ b/server/tests/eventRoutes.test.js @@ -6,6 +6,10 @@ dotenv.config({ path: '.env.local' }); beforeAll(async () => { await mongoose.connect(process.env.MONGO_URI); + const collections = await mongoose.connection.db.collections(); + for (let collection of collections) { + await collection.deleteMany(); + } }); afterEach(async () => { @@ -28,9 +32,9 @@ describe('Event API', () => { test('POST /api/events should create a new event', async () => { const newEvent = { - title: 'Conference 2025', - startTime: '2025-03-15T10:00:00.000Z', - endTime: '2025-03-15T12:00:00.000Z', + title: 'Writing this test', + startTime: new Date(2025, 0, 19, 12, 58), + endTime: new Date(2025, 0, 19, 12, 59) }; const res = await request(app).post('/api/events').send(newEvent);