import request from 'supertest';
import app from '../../app';
import { createUser, updateUser, userList } from './user.fixtures';
describe('User API', () => {
let userId;
it('should create a new user', async () => {
const response = await request(app)
.post('/api/users')
.send(createUser)
.expect(201);
expect(response.body).toHaveProperty('id');
userId = response.body.id;
});
it('should get all users', async () => {
const response = await request(app)
.get('/api/users')
.expect(200);
expect(Array.isArray(response.body)).toBe(true);
});
it('should get a user by id', async () => {
const response = await request(app)
.get(`/api/users/${userId}`)
.expect(200);
expect(response.body).toHaveProperty('id', userId);
});
it('should update a user', async () => {
const response = await request(app)
.put(`/api/users/${userId}`)
.send(updateUser)
.expect(200);
expect(response.body).toHaveProperty('name', updateUser.name);
});
it('should delete a user', async () => {
await request(app)
.delete(`/api/users/${userId}`)
.expect(204);
});
});