sub-manager-backend/test/Entity.test.mjs

26 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-09-07 09:39:09 +00:00
import { describe } from "mocha";
import Entity from "../objects/Entity.mjs";
import chaiAsPromised from "chai-as-promised";
import chai from "chai";
import { expect} from "chai";
import { testDb as db } from "../db.mjs";
chai.use(chaiAsPromised)
describe("tetsing Entity object",async function(){
2023-09-07 10:07:34 +00:00
it("should throw TypeError if passed an invalid data.id",async function(){
2023-09-07 09:39:09 +00:00
expect(()=>{new Entity({id:"string"})}).to.throw(TypeError)
expect(()=>{new Entity({id:{}})}).to.throw(TypeError)
expect(()=>{new Entity({id:[]})}).to.throw(TypeError)
})
it("should not throw if given a valid id",function(){
expect(()=>{new Entity({id:1})}).not.to.throw()
})
it(".delete() should throw if initialised without .id",function(){
const entity = new Entity()
return expect(entity.del(db)).to.eventually.be.rejectedWith(Error)
})
it(".delete() should throw if not passed a db",function(){
const entity = new Entity({id:1})
return expect(entity.del()).to.eventually.be.rejectedWith(Error)
})
})