Skip to content

Commit

Permalink
fix: db test
Browse files Browse the repository at this point in the history
Signed-off-by: ramprasathmk <[email protected]>
  • Loading branch information
ramprasathmk committed Dec 9, 2024
1 parent 3a2d23f commit 1c21f9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
24 changes: 6 additions & 18 deletions tests/app.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
const request = require('supertest');
const { app, server } = require('../server');
const mongoose = require('mongoose');

// describe('GET /', () => {
// it('should return 200 OK', async () => {
// const res = await request(app).get('/');
// expect(res.status).toBe(200);
// });

// it('should render the index view', async () => {
// const res = await request(app).get('/');
// expect(res.text).toContain('<h1>Poet App</h1>');
// });
// });
const DB_URL = process.env.MONGODB_URI;

describe('GET /search', () => {
it('should return 200 OK', async () => {
Expand All @@ -35,11 +24,10 @@ afterAll(async () => {
// MongoDB Database Connection Test
describe('Database Connection', () => {
it('should return database connection results', async () => {
const DB_URL = process.env.MONGODB_LOCAL_URL;
const database = mongoose.connect(DB_URL)
.then( () => { console.log('Connected to MongoDB') } )
.catch( (err) => {console.error("Error ", err)} );

if (!database) throw mongoose.Error("Database is not Connected!");
const database = await mongoose.connect(DB_URL);

if (!database)
throw mongoose.Error('Database is not Connected! :(');
else console.log('MongoDB Connected Successfully :)');
});
});
2 changes: 1 addition & 1 deletion tests/setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const mongoose = require('mongoose');
require('dotenv').config();

const DB_URL = process.env.MONGODB_LOCAL_URL;
const DB_URL = process.env.MONGODB_URI;

module.exports = async () => {
await mongoose.connect(DB_URL, { useNewUrlParser: true, useUnifiedTopology: true });
Expand Down

0 comments on commit 1c21f9a

Please sign in to comment.