# test.govlab/context/core/factories/field.factory.test.ts

> 47 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-context-core-factories-field-factory-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/context/core/factories/field.factory.test.ts.txt

Listed in [test.govlab/context/core/factories](https://banes-lab.com/api/source/testing/test.govlab/context/core/factories.md), before [test.govlab/context/core/factories/grammar.factory.test.ts](https://banes-lab.com/source/testing/test.govlab/context/core/factories/grammar.factory.test.ts.md).

## Contained in

- [test.govlab/context/core/factories](https://banes-lab.com/anatomy/testing/folder-testing-test-govlab-context-core-factories.md)

## Source

```typescript
import {
    freeRefs,
    kept,
    listedBy,
    optionalRef,
    optionalRefs,
    ref,
    refs,
} from "@govlab/context/core/factories/field.factory.ts";
import assert from "node:assert/strict";
import { test } from "vitest";

test("ref and refs are required, and carry their target and inverse", () => {
    assert.deepEqual(ref("reasoning:axis", "nodes"), {
        inverse: "nodes",
        required: true,
        target: "reasoning:axis",
        type: "ref",
    });
    assert.deepEqual(refs("reasoning:node"), { required: true, target: "reasoning:node", type: "refs" });
});

test("optionalRef, optionalRefs and freeRefs are optional, and carry the declared inverse", () => {
    assert.deepEqual(optionalRef("architecture"), { required: false, target: "architecture", type: "ref" });
    assert.deepEqual(optionalRefs("algorithms", "composed-by"), {
        inverse: "composed-by",
        required: false,
        target: "algorithms",
        type: "refs",
    });
    assert.deepEqual(optionalRefs("algorithms"), { required: false, target: "algorithms", type: "refs" });
    assert.deepEqual(freeRefs("grounded-by"), { inverse: "grounded-by", required: false, type: "refs" });
});

test("listedBy flips the relation onto its target, and kept holds it on the record", () => {
    assert.deepEqual(listedBy(ref("reasoning:mode"), "techniques"), {
        flip: true,
        relation: "techniques",
        required: true,
        target: "reasoning:mode",
        type: "ref",
    });
    assert.deepEqual(kept(refs("reasoning:node"), "grounds"), {
        flip: false,
        relation: "grounds",
        required: true,
        target: "reasoning:node",
        type: "refs",
    });
});
```
