Skip to content

Commit

Permalink
add test case for server.js
Browse files Browse the repository at this point in the history
Signed-off-by: ramprasathmk <[email protected]>
  • Loading branch information
ramprasathmk committed Dec 19, 2024
1 parent 4676c0d commit 629d8c1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/server.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const request = require('supertest')
const { app, server } = require('./server')
const mongoose = require('mongoose')

const DB_URL = process.env.MONGODB_URI

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

it('should return search results', async () => {
const res = await request(app).get('/search?query=test')
expect(res.text).toContain('Search Results for')
})
})

afterAll(async () => {
server.close()
await mongoose.connection.close()
})

// MongoDB Database Connection Test
describe('Database Connection', () => {
it('should connect to the database successfully', async () => {
const database = await mongoose.connect(DB_URL)

if (!database) throw new Error('Database is not Connected! :(')
else console.log('MongoDB Connected Successfully :)')
})
})

0 comments on commit 629d8c1

Please sign in to comment.