# test.rules/rules/eslint/scoped-resource-release.eslint.rule.test.ts

> 48 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-rules-rules-eslint-scoped-resource-release-eslint-rule-test-ts
Source text: https://banes-lab.com/source/testing/test.rules/rules/eslint/scoped-resource-release.eslint.rule.test.ts.txt

Listed in [test.rules/rules/eslint](https://banes-lab.com/api/source/testing/test.rules/rules/eslint.md), after [test.rules/rules/eslint/retired-collection-id.eslint.rule.test.ts](https://banes-lab.com/source/testing/test.rules/rules/eslint/retired-collection-id.eslint.rule.test.ts.md) and before [test.rules/rules/eslint/strings-composition.eslint.rule.test.ts](https://banes-lab.com/source/testing/test.rules/rules/eslint/strings-composition.eslint.rule.test.ts.md).

## Contained in

- [test.rules/rules/eslint](https://banes-lab.com/anatomy/testing/folder-testing-test-rules-rules-eslint.md)

## Source

```typescript
import { RESOURCE_MARK, SCOPED_RESOURCES } from "@ssot/govlab/shared/manifests/invariant.manifest.ts";
import { describe, expect, it } from "vitest";
import { Linter } from "eslint";
import { absolutePath } from "@ssot/paths";
import rule from "@ssot/govlab/rules/eslint/scoped-resource-release.eslint.rule.ts";
import { sep } from "node:path";

const linter = new Linter();
const config = [
    {
        files: ["**/*.ts"],
        languageOptions: {
            ecmaVersion: 2025 as const,
            parser: await import("@typescript-eslint/parser"),
            sourceType: "module" as const,
        },
        plugins: { t: { rules: { r: rule } } },
        rules: { "t/r": "error" as const },
    },
];

const SRC = `${absolutePath("govlab.patterns").split(sep).join("/")}/core/factories/probe.factory.ts`;

const idsFor = function idsFor(code: string): string[] {
    return linter
        .verify(code, config, SRC)
        .map((message) => message.messageId)
        .filter((id): id is string => typeof id === "string");
};

const [entry] = [...SCOPED_RESOURCES];
const [key, release] = entry ?? ["", ""];
const source = key.slice(0, key.indexOf(RESOURCE_MARK));
const acquirer = key.slice(key.indexOf(RESOURCE_MARK) + RESOURCE_MARK.length);

describe("scoped-resource-release", () => {
    it("reports a registered acquirer imported where its release is neither imported nor declared", () => {
        expect(idsFor(`import { ${acquirer} } from "${source}";\nexport const open = ${acquirer};`)).toStrictEqual([
            "unreleased",
        ]);
    });

    it("accepts the acquirer beside a declared release function", () => {
        const code = `import { ${acquirer} } from "${source}";\nexport const ${release} = async function ${release}(): Promise<void> {};`;
        expect(idsFor(code)).toStrictEqual([]);
    });

    it("accepts the acquirer beside an imported release function", () => {
        const code = `import { ${acquirer} } from "${source}";\nimport { ${release} } from "./owner.factory.ts";`;
        expect(idsFor(code)).toStrictEqual([]);
    });

    it("ignores the same name taken from a module the registry does not classify", () => {
        expect(idsFor(`import { ${acquirer} } from "unregistered";`)).toStrictEqual([]);
    });
});
```
