Debian Codegraph @

__tests__/internal/unit/model-test.js

raw
1 import { Model } from "@lib";
2
3 describe("Unit | Model", function () {
4 test("it can be instantiated", () => {
5 let model = new Model({}, "user");
6 expect(model).toBeTruthy();
7 });
8
9 test("it cannot be instantiated without a schema", () => {
10 expect(function () {
11 new Model();
12 }).toThrow("A model requires a schema");
13 });
14
15 test("it cannot be instantiated without a modelName", () => {
16 expect(function () {
17 new Model({});
18 }).toThrow("A model requires a modelName");
19 });
20
21 test("findBelongsToAssociation returns association for given type if defined", () => {
22 let ModelClass = Model.extend();
23 let authorAssociationMock = {};
24 ModelClass.prototype.belongsToAssociations = {
25 author: authorAssociationMock,
26 };
27
28 expect(ModelClass.findBelongsToAssociation("article")).toBeUndefined();
29 expect(ModelClass.findBelongsToAssociation("author")).toEqual(
30 authorAssociationMock
31 );
32 });
33 });