You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.4 KiB
TypeScript
64 lines
1.4 KiB
TypeScript
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", () => {
|
|
|
|
console.log("PRODUCT")
|
|
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 get product by 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);
|
|
})
|
|
}) |