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"
}
},
"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": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",

View file

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