# test.govlab/context/core/loaders/ontology.loader.test.ts

> 24 lines of code and 0 definitions.

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

Listed in [test.govlab/context/core/loaders](https://banes-lab.com/api/source/testing/test.govlab/context/core/loaders.md), after [test.govlab/context/core/loaders/lexicon.loader.test.ts](https://banes-lab.com/source/testing/test.govlab/context/core/loaders/lexicon.loader.test.ts.md) and before [test.govlab/context/core/loaders/reason.loader.test.ts](https://banes-lab.com/source/testing/test.govlab/context/core/loaders/reason.loader.test.ts.md).

## Contained in

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

## Source

```typescript
import { loadCategories, readJsonDir, readJsonFile } from "@govlab/context/core/loaders/ontology.loader.ts";
import { GRAPH_FILE } from "@govlab/context/configuration/constants/layer.constants.ts";
import { ReadAudit } from "@govlab/context/core/observers/record.observer.ts";
import { absolutePath } from "@ssot/paths";
import assert from "node:assert/strict";
import path from "node:path";
import { test } from "vitest";

const LAYERS = absolutePath("govlab.context.layers");

const isGraph = (name: string): boolean => name === GRAPH_FILE;

test("readJsonDir reads each data file once, filtered by only and exclude", () => {
    const all = readJsonDir(LAYERS);
    assert.ok(all.length > 1);
    assert.equal(readJsonDir(LAYERS, { only: isGraph }).length, 1);
    assert.equal(readJsonDir(LAYERS, { exclude: isGraph }).length, all.length - 1);
    assert.deepEqual(readJsonFile(path.join(LAYERS, GRAPH_FILE)), readJsonDir(LAYERS, { only: isGraph })[0]);
});

test("loadCategories folds every category of a data folder through the normalizer", () => {
    const ids = loadCategories(
        absolutePath("govlab.context.principles"),
        (raw) => String(raw["id"] ?? raw["name"]),
        new ReadAudit("architecture"),
    );
    assert.ok(ids.length > 0);
});
```
