Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Teste de integração - Categoria
const request = require('supertest');
const { Category } = require('../../src/models/category');
describe('/categories', () => {
let server;
beforeEach(async () => {
server = require('../../index');
const categories = [{ name: 'Electronics' }, { name: 'Books' }];
await Category.deleteMany({});
await Category.insertMany(categories);
});
afterEach(async () => {
await Category.deleteMany({});
});
describe('GET /', () => {
it('should return all categories', async () => {
const response = await request(server).get('/categories');
expect(response.status).toBe(200);
expect(response.body.length).toBe(2);
});
});
describe('POST /', () => {
it('should register a new category', async () => {
const category = { name: 'Video Game' };
const response = await request(server)
.post('/categories')
.send(category);
expect(response.status).toBe(201);
expect(response.body).toHaveProperty('name', category.name);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.