Skip to content

Commit

Permalink
added a backend call on the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunbalaji99 committed Jan 19, 2025
1 parent e54ca51 commit 4b070c3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 15 additions & 1 deletion client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import {
Header,
Calendar,
Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
});
10 changes: 7 additions & 3 deletions server/tests/eventRoutes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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);
Expand Down

0 comments on commit 4b070c3

Please sign in to comment.