Skip to content

Commit

Permalink
updating the workflow file to close the server that was started
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyg37 committed Apr 3, 2024
1 parent fbbaaa1 commit 0217aab
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
16 changes: 11 additions & 5 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@ const PORT = 4000;

mongoose.connect('mongodb://localhost:27017/portfolio',);



app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());


app.use('/v1/auth', authRoutes);
app.use('/v1/blog', blogRoutes);
app.use('/v1/feedback', contactRoutes);
app.use('/v1/profile', detailsRoutes);

app.listen(PORT, () => {
let server: any;

export const startServer = () => {
server = app.listen(PORT, () => {
console.log(`⚡️[server]: Server is running at https://localhost:${PORT}`);
});
});
return server;
}

export const closeServer = () => {
server.close();
}

export default app;
30 changes: 30 additions & 0 deletions backend/src/test/server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect } from 'chai';
import mongoose from 'mongoose';
import request from 'supertest';
import app from '../server';
import { startServer, closeServer } from '../server';

describe('App', () => {
before(() => {
startServer();
mongoose.connect('mongodb://localhost:27017/portfolio');
mongoose.connection.once('open', () => {
console.log('Connected to MongoDB');
});
});

after(() => {
mongoose.disconnect();
closeServer();
});

it('should return a 200 status code for GET /v1/auth', async () => {
const res = await request(app).get('/v1/auth');
});
it('should return a 200 status code for GET /v1/blog', async () => {
const res = await request(app).get('/v1/blog');
});
it('should return a 200 status code for GET /v1/feedback', async () => {
const res = await request(app).get('/v1/feedback');
});
});

0 comments on commit 0217aab

Please sign in to comment.