Archived
1
0
Fork 0

Reorganise test

This commit is contained in:
Ethanell 2020-08-25 17:53:21 +02:00
parent 39b847c79e
commit 43227d42ad
2 changed files with 434 additions and 424 deletions

View file

@ -17,8 +17,8 @@ async function databaseExit(models) {
delete require.cache[require.resolve("../models")];
}
describe("Database Department tests", () => {
describe("Database objects tests", () => {
describe("Database Department tests", () => {
let models;
before(async () => {
@ -39,9 +39,9 @@ describe("Database Department tests", () => {
await models.Department.create({name: "TestDepartment"});
return expect(models.Department.create({name: "TestDepartment"})).to.be.rejectedWith(models.Sequelize.ValidationError);
});
});
});
describe("Database Sandwich tests", () => {
describe("Database Sandwich tests", () => {
let models;
before(async () => {
@ -60,11 +60,14 @@ describe("Database Sandwich tests", () => {
});
it("Sandwich validation", async () => {
await models.Sandwich.create({name: "TestSandwich", price: 1.5});
return expect(models.Sandwich.create({name: "TestSandwich", price: 1.5})).to.be.rejectedWith(models.Sequelize.ValidationError);
return expect(models.Sandwich.create({
name: "TestSandwich",
price: 1.5
})).to.be.rejectedWith(models.Sequelize.ValidationError);
});
});
});
describe("Database User test", () => {
describe("Database User test", () => {
let models;
before(async () => {
@ -94,7 +97,8 @@ describe("Database User test", () => {
email: "test@test.fr",
firstName: "Test",
lastName: "Test",
passwordHash: testPassword});
passwordHash: testPassword
});
expect(testUser.checkPassword(testPassword)).to.be.equal(true);
});
it("User validation", async () => {
@ -170,9 +174,9 @@ describe("Database User test", () => {
expect(testUser.Department).to.be.instanceOf(models.Department);
expect(testUser.Department.name).to.be.equal(testDepartment.name);
});
});
});
describe("Database Order tests", () => {
describe("Database Order tests", () => {
let models;
before(async () => {
@ -194,7 +198,7 @@ describe("Database Order tests", () => {
})).to.be.instanceOf(models.Order);
});
it("Order associations", async () => {
let testOrder = await models.Order.create({firstName: "Test", lastName: "Test", price: 1.5, },
let testOrder = await models.Order.create({firstName: "Test", lastName: "Test", price: 1.5,},
{include: [models.Department, models.Sandwich, models.User]});
let testDepartment = await models.Department.create({name: "TestDepartment"});
let testSandwich = await models.Sandwich.create({name: "TestSandwich", price: 1.5});
@ -203,7 +207,8 @@ describe("Database Order tests", () => {
email: "test@test.fr",
firstName: "Test",
lastName: "Test",
passwordHash: "test"});
passwordHash: "test"
});
await testOrder.setDepartment(testDepartment);
await testOrder.reload();
@ -220,9 +225,9 @@ describe("Database Order tests", () => {
expect(testOrder.User).to.be.instanceOf(models.User);
expect(testOrder.User.username).to.be.equal(testUser.username);
});
});
});
describe("Database Data tests", () => {
describe("Database Data tests", () => {
let models;
before(async () => {
@ -249,4 +254,5 @@ describe("Database Data tests", () => {
value: "test"
})).to.be.rejectedWith(models.Sequelize.ValidationError);
})
});
});

View file

@ -39,7 +39,8 @@ async function getLoginAgent(app) {
}
describe("Public pages test", () => {
describe("Pages tests", () => {
describe("Public pages test", () => {
let app;
let models;
@ -145,9 +146,9 @@ describe("Public pages test", () => {
.get("/foo/bar")
.expect(404, done);
});
});
});
describe("Global logged user pages", () => {
describe("Global logged user pages", () => {
let app;
let models;
@ -155,7 +156,7 @@ describe("Global logged user pages", () => {
[app, models] = await setup();
await createTestUser(models);
});
after( () => {
after(() => {
return clean;
});
@ -199,14 +200,15 @@ describe("Global logged user pages", () => {
.get("/profile")
.expect(200);
});
});
});
for (let [p, a] of Object.entries({
describe("Permissions pages tests", () => {
for (let [p, a] of Object.entries({
0: [403, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403],
1: [200, 403, 403, 403, 403, 403, 403, 403, 403, 403, 403],
2: [200, 200, 403, 403, 403, 403, 403, 403, 403, 403, 403],
3: [200, 200, 200, 200, 200, 200, 200, 400, 200, 200, 400]
}))
}))
describe(`Permission ${p} pages`, () => {
let app;
let models;
@ -215,7 +217,7 @@ for (let [p, a] of Object.entries({
[app, models] = await setup();
await createTestUser(models, p);
});
after( () => {
after(() => {
return clean;
});
@ -275,3 +277,5 @@ for (let [p, a] of Object.entries({
.expect(a[10])
});
});
});
});