added products_spec handler tests
parent
372a5ee059
commit
a04f395db9
@ -1 +1,63 @@
|
||||
import sueprtest from "supertest"
|
||||
import supertest from "supertest"
|
||||
import app from "../../server"
|
||||
import { Product } from '../../models/product'
|
||||
|
||||
|
||||
|
||||
const token = process.env.TOKEN_SECRET_TEST as string
|
||||
const request = supertest(app);
|
||||
|
||||
const testProduct: Product = {
|
||||
name: "metro",
|
||||
price: 10
|
||||
}
|
||||
|
||||
const updatedProduct: Product = {
|
||||
name: "1984",
|
||||
price: 5
|
||||
}
|
||||
|
||||
|
||||
|
||||
describe("Product handler", () => {
|
||||
|
||||
it('Should create a new product', async () => {
|
||||
const response = await request
|
||||
.post("/products")
|
||||
.auth(token, { type: "bearer" })
|
||||
.send(testProduct);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
})
|
||||
|
||||
it('Should index products', async () => {
|
||||
const response = await request
|
||||
.get("/products")
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
})
|
||||
|
||||
it('Should read product with id', async () => {
|
||||
const response = await request
|
||||
.get("/products/1")
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
})
|
||||
|
||||
it('Should update product with id', async () => {
|
||||
const response = await request
|
||||
.put("/products/1")
|
||||
.auth(token, { type: 'bearer'})
|
||||
.send(updatedProduct)
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
})
|
||||
|
||||
it('Should delete product with id', async () => {
|
||||
const response = await request
|
||||
.delete("/products/1")
|
||||
.auth(token, { type: 'bearer'})
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue