lhdn_api_simulation/tests/headers.test.js

92 lines
2.2 KiB
JavaScript

const request = require('supertest')
const app = require('../server')
const userInfo = require('./userInfo')
describe('END-POINT headers', () => {
let newID="";
var auth = {accessToken:""};
it("Login", async () => {
const login = await request(app)
.post('/auth')
.send({
email: userInfo.email,
password: userInfo.password
});
if(login.statusCode==201){
auth = login.body;
console.log(auth.accessToken);
}
expect(login.statusCode).toEqual(201)
})
it("POST '/headers/'", async () => {
const res = await request(app)
.post('/headers')
.auth(auth.accessToken, { type: 'bearer' })
.send({
"headerItems":"minim"
})
expect(res.statusCode).toEqual(200)
newID=res.statusCode==200?res.body["id"]:"";
})
it("POST '/headers/'", async () => {
const res = await request(app)
.post('/headers')
.auth(auth.accessToken, { type: 'bearer' })
.send({
"headerItems":"exclf"
})
expect(res.statusCode).toEqual(200)
newID=res.statusCode==200?res.body["id"]:"";
})
it("GET '/headers/'", async () => {
const res = await request(app)
.get('/headers?headerItems=minim')
.auth(auth.accessToken, { type: 'bearer' })
.send()
expect(res.statusCode).toEqual(200)
})
it("GET '/headers/"+newID+"'", async () => {
if(newID!=""){
const res = await request(app)
.get('/headers/'+newID)
.auth(auth.accessToken, { type: 'bearer' })
.send()
expect(res.statusCode).toEqual(200)
}else{
console.log("**GET[ID] TEST HAS BEEN SKIPED")
}
})
it("PATCH '/headers/"+newID+"'", async () => {
if(newID!=""){
const res = await request(app)
.patch('/headers/'+newID)
.auth(auth.accessToken, { type: 'bearer' })
.send({
"headerItems":"sint"
})
expect(res.statusCode).toEqual(204)
}else{
console.log("**PATCH TEST HAS BEEN SKIPED")
}
})
it("DELETE '/headers/"+newID+"'", async () => {
if(newID!=""){
const res = await request(app)
.delete('/headers/'+newID)
.auth(auth.accessToken, { type: 'bearer' })
.send()
expect(res.statusCode).toEqual(204)
}else{
console.log("**DELETE TEST HAS BEEN SKIPED")
}
})
})