Added deleteOne tests
This commit is contained in:
parent
918f873fea
commit
a77e068c73
1 changed files with 133 additions and 0 deletions
133
test/deleteOne.test.js
Normal file
133
test/deleteOne.test.js
Normal file
|
@ -0,0 +1,133 @@
|
|||
/* eslint-disable jest/no-test-callback */
|
||||
import { createBrand, truncate } from "./utils/common";
|
||||
|
||||
import models from "../models";
|
||||
import Brands from "../rules/Brands";
|
||||
import Middelware from "../index";
|
||||
|
||||
let brand = {};
|
||||
|
||||
describe("deleteOne", () => {
|
||||
beforeAll(done => {
|
||||
createBrand((err, item) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
} else {
|
||||
brand = item;
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(done => {
|
||||
truncate(["Brands"], done);
|
||||
});
|
||||
|
||||
test("It should return 401.1 if guest tries to delete item", async done => {
|
||||
const middleware = new Middelware(Brands, models);
|
||||
const req = {
|
||||
method: "DELETE",
|
||||
user: null,
|
||||
params: {
|
||||
brandId: brand.id
|
||||
},
|
||||
query: {},
|
||||
protocol: "http",
|
||||
get: () => {
|
||||
return "internal.test/";
|
||||
},
|
||||
originalUrl: "v1/"
|
||||
};
|
||||
|
||||
middleware.deleteOne(req, (err, res) => {
|
||||
expect(res).toBeUndefined();
|
||||
expect(parseFloat(err.errorCode)).toBe(401.1);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test("It should return 401.1 if bad role tries to delete item", async done => {
|
||||
const middleware = new Middelware(Brands, models);
|
||||
const req = {
|
||||
method: "DELETE",
|
||||
user: {
|
||||
role: "user"
|
||||
},
|
||||
params: {
|
||||
brandId: brand.id
|
||||
},
|
||||
query: {},
|
||||
protocol: "http",
|
||||
get: () => {
|
||||
return "internal.test/";
|
||||
},
|
||||
originalUrl: "v1/"
|
||||
};
|
||||
|
||||
middleware.deleteOne(req, (err, res) => {
|
||||
expect(res).toBeUndefined();
|
||||
expect(parseFloat(err.errorCode)).toBe(401.1);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test("It should return empty item if allowed user delete item", async done => {
|
||||
const middleware = new Middelware(Brands, models);
|
||||
const req = {
|
||||
method: "DELETE",
|
||||
user: {
|
||||
role: "admin"
|
||||
},
|
||||
params: {
|
||||
brandId: brand.id
|
||||
},
|
||||
query: {},
|
||||
body: {
|
||||
name: "TEST"
|
||||
},
|
||||
protocol: "http",
|
||||
get: () => {
|
||||
return "internal.test/";
|
||||
},
|
||||
originalUrl: "v1/"
|
||||
};
|
||||
|
||||
middleware.deleteOne(req, (err, res) => {
|
||||
expect(err).toBeNull();
|
||||
expect(res).toEqual({});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test("It should return 404.0 if allowed user tries to delete not found item", async done => {
|
||||
const middleware = new Middelware(Brands, models);
|
||||
const req = {
|
||||
method: "DELETE",
|
||||
user: {
|
||||
role: "admin"
|
||||
},
|
||||
params: {
|
||||
brandId: brand.id
|
||||
},
|
||||
query: {},
|
||||
body: {
|
||||
name: "TEST"
|
||||
},
|
||||
protocol: "http",
|
||||
get: () => {
|
||||
return "internal.test/";
|
||||
},
|
||||
originalUrl: "v1/"
|
||||
};
|
||||
|
||||
middleware.deleteOne(req, (err, res) => {
|
||||
expect(res).toBeUndefined();
|
||||
expect(parseFloat(err.errorCode)).toBe(404.0);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue