-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.test.js
More file actions
43 lines (36 loc) · 1.53 KB
/
app.test.js
File metadata and controls
43 lines (36 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const request = require('supertest');
const { app, closeApp} = require('./server'); // Adjust the path according to your project structure
require('dotenv').config();
describe('API Endpoints', () => {
afterAll(async () => {
// Call the function to close your app or server and ensure all connections are closed
await closeApp();
});
it('GET / should return Hello World', async () => {
const res = await request(app).get('/');
expect(res.statusCode).toEqual(200);
expect(res.text).toContain('Hello World!');
});
it('POST /api/users should validate request body', async () => {
const userData = { email: 'test@example.com', displayName: '' }; // Intentionally missing required fields
const res = await request(app)
.post('/api/users')
.send(userData);
expect(res.statusCode).toEqual(400);
expect(res.body).toHaveProperty('message', 'Missing required fields');
});
it('GET /api/user/:id should handle non-existing users', async () => {
const userId = 'nonExistingId';
const res = await request(app).get(`/api/user/${userId}`);
expect(res.statusCode).toEqual(404);
});
it('POST /api/chats/select should handle chat selection or creation', async () => {
const chatData = { currentUserUid: 'user1', userUid: 'user2' };
const res = await request(app)
.post('/api/chats/select')
.send(chatData);
expect(res.statusCode).toBe(200);
expect(res.body).toHaveProperty('message', 'Chat selected or created successfully');
});
// Additional tests can be added here
});