mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 04:46:05 +00:00
public commit
This commit is contained in:
78
app/__test__/data/specs/relations/EntityRelation.spec.ts
Normal file
78
app/__test__/data/specs/relations/EntityRelation.spec.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { describe, expect, it, test } from "bun:test";
|
||||
import { Entity, type EntityManager } from "../../../../src/data";
|
||||
import {
|
||||
type BaseRelationConfig,
|
||||
EntityRelation,
|
||||
EntityRelationAnchor,
|
||||
RelationTypes
|
||||
} from "../../../../src/data/relations";
|
||||
|
||||
class TestEntityRelation extends EntityRelation {
|
||||
constructor(config?: BaseRelationConfig) {
|
||||
super(
|
||||
new EntityRelationAnchor(new Entity("source"), "source"),
|
||||
new EntityRelationAnchor(new Entity("target"), "target"),
|
||||
config
|
||||
);
|
||||
}
|
||||
initialize(em: EntityManager<any>) {}
|
||||
type() {
|
||||
return RelationTypes.ManyToOne; /* doesn't matter */
|
||||
}
|
||||
setDirections(directions: ("source" | "target")[]) {
|
||||
this.directions = directions;
|
||||
return this;
|
||||
}
|
||||
|
||||
buildWith(a: any, b: any, c: any): any {
|
||||
return;
|
||||
}
|
||||
|
||||
buildJoin(a: any, b: any): any {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
describe("[data] EntityRelation", async () => {
|
||||
test("other", async () => {
|
||||
const relation = new TestEntityRelation();
|
||||
expect(relation.other("source").entity.name).toBe("target");
|
||||
expect(relation.other("target").entity.name).toBe("source");
|
||||
});
|
||||
|
||||
it("visibleFrom", async () => {
|
||||
const relation = new TestEntityRelation();
|
||||
// by default, both sides are visible
|
||||
expect(relation.visibleFrom("source")).toBe(true);
|
||||
expect(relation.visibleFrom("target")).toBe(true);
|
||||
|
||||
// make source invisible
|
||||
relation.setDirections(["target"]);
|
||||
expect(relation.visibleFrom("source")).toBe(false);
|
||||
expect(relation.visibleFrom("target")).toBe(true);
|
||||
|
||||
// make target invisible
|
||||
relation.setDirections(["source"]);
|
||||
expect(relation.visibleFrom("source")).toBe(true);
|
||||
expect(relation.visibleFrom("target")).toBe(false);
|
||||
});
|
||||
|
||||
it("hydrate", async () => {
|
||||
// @todo: implement
|
||||
});
|
||||
|
||||
it("isListableFor", async () => {
|
||||
// by default, the relation is listable from target side
|
||||
const relation = new TestEntityRelation();
|
||||
expect(relation.isListableFor(relation.target.entity)).toBe(true);
|
||||
expect(relation.isListableFor(relation.source.entity)).toBe(false);
|
||||
});
|
||||
|
||||
it("required", async () => {
|
||||
const relation1 = new TestEntityRelation();
|
||||
expect(relation1.config.required).toBe(false);
|
||||
|
||||
const relation2 = new TestEntityRelation({ required: true });
|
||||
expect(relation2.config.required).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user