Archived
1
0
Fork 0

Fix async assertion

This commit is contained in:
Ethanell 2020-08-25 17:09:50 +02:00
parent 316a2c27bc
commit 29b5581876
3 changed files with 26 additions and 39 deletions

9
package-lock.json generated
View file

@ -363,6 +363,15 @@
"type-detect": "^4.0.5" "type-detect": "^4.0.5"
} }
}, },
"chai-as-promised": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz",
"integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==",
"dev": true,
"requires": {
"check-error": "^1.0.2"
}
},
"chalk": { "chalk": {
"version": "2.4.2", "version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",

View file

@ -24,6 +24,7 @@
}, },
"devDependencies": { "devDependencies": {
"chai": "^4.2.0", "chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"mocha": "^8.1.1", "mocha": "^8.1.1",
"sqlite3": "^5.0.0", "sqlite3": "^5.0.0",
"supertest": "^4.0.2" "supertest": "^4.0.2"

View file

@ -1,4 +1,6 @@
let expect = require("chai").expect; let chai = require("chai");
chai.use(require("chai-as-promised"));
let expect = chai.expect;
let wipeDatabase = require("./utils/wipeDatabase"); let wipeDatabase = require("./utils/wipeDatabase");
@ -35,12 +37,7 @@ describe("Database Department tests", () => {
}); });
it("Department validation", async () => { it("Department validation", async () => {
await models.Department.create({name: "TestDepartment"}); await models.Department.create({name: "TestDepartment"});
try { return expect(models.Department.create({name: "TestDepartment"})).to.be.rejectedWith(models.Sequelize.ValidationError);
await models.Department.create({name: "TestDepartment"});
} catch (e) {
if (!(e instanceof models.Sequelize.ValidationError))
throw e;
}
}); });
}); });
@ -63,12 +60,7 @@ describe("Database Sandwich tests", () => {
}); });
it("Sandwich validation", async () => { it("Sandwich validation", async () => {
await models.Sandwich.create({name: "TestSandwich", price: 1.5}); await models.Sandwich.create({name: "TestSandwich", price: 1.5});
try { return expect(models.Sandwich.create({name: "TestSandwich", price: 1.5})).to.be.rejectedWith(models.Sequelize.ValidationError);
await models.Sandwich.create({name: "TestSandwich", price: 1.5});
} catch (e) {
if (!(e instanceof models.Sequelize.ValidationError))
throw e;
}
}); });
}); });
@ -113,47 +105,32 @@ describe("Database User test", () => {
lastName: "Test", lastName: "Test",
passwordHash: "test"}); passwordHash: "test"});
//Username return Promise.all([
try { //Username
await models.User.create({ expect(models.User.create({
username: "test", username: "test",
email: "test2@test.fr", email: "test2@test.fr",
firstName: "Test2", firstName: "Test2",
lastName: "Test2", lastName: "Test2",
passwordHash: "test" passwordHash: "test"
}) })).to.be.rejectedWith(models.Sequelize.ValidationError),
} catch (e) { //Email
if (!(e instanceof models.Sequelize.ValidationError)) expect(models.User.create({
throw e;
}
//Email
try {
await models.User.create({
username: "test2", username: "test2",
email: "test@test.fr", email: "test@test.fr",
firstName: "Test2", firstName: "Test2",
lastName: "Test2", lastName: "Test2",
passwordHash: "test" passwordHash: "test"
}) })).to.be.rejectedWith(models.Sequelize.ValidationError),
} catch (e) { //First & last name
if (!(e instanceof models.Sequelize.ValidationError)) expect(models.User.create({
throw e;
}
//First & last name
try {
await models.User.create({
username: "test2", username: "test2",
email: "test2@test.fr", email: "test2@test.fr",
firstName: "Test", firstName: "Test",
lastName: "Test", lastName: "Test",
passwordHash: "test" passwordHash: "test"
}) })).to.be.rejectedWith(models.Sequelize.ValidationError),
} catch (e) { ])
if (!(e instanceof models.Sequelize.ValidationError))
throw e;
}
}); });
it("User associations", async () => { it("User associations", async () => {
let testUser = await models.User.create({ let testUser = await models.User.create({