Skip to content

Commit

Permalink
convert built-in package tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeVanti committed Aug 15, 2024
1 parent 45c56f7 commit 2e66bbb
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 86 deletions.
8 changes: 4 additions & 4 deletions test/unit/domain/data-packument.ts → test/data-packument.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import assert from "assert";
import { DomainName } from "../../../src/domain/domain-name";
import { SemanticVersion } from "../../../src/domain/semantic-version";
import { DomainName } from "../src/domain/domain-name";
import { SemanticVersion } from "../src/domain/semantic-version";
import {
UnityPackument,
UnityPackumentVersion,
} from "../../../src/domain/packument";
import { isZod } from "../../../src/utils/zod-utils";
} from "../src/domain/packument";
import { isZod } from "../src/utils/zod-utils";

/**
* Builder class for {@link UnityPackumentVersion}.
Expand Down
12 changes: 12 additions & 0 deletions test/integration/docs.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import nock from "nock";
import { DomainName } from "../../src/domain/domain-name";

/**
* Mocks the existence of a Unity documentation page for a package.
* @param packageName The name of the package.
*/
export function mockUnityDocPage(packageName: DomainName) {
nock(`https://docs.unity3d.com`)
.head(`/Manual/${packageName}.html`)
.reply(200);
}
23 changes: 23 additions & 0 deletions test/integration/registry.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import nock from "nock";
import { UnityPackument } from "../../src/domain/packument";
import { RegistryUrl, unityRegistryUrl } from "../../src/domain/registry-url";

/**
* Mocks a packument on a remote package registry.
* @param registryUrl The url of the registry.
* @param packument The packument.
*/
export function mockRegistryPackument(
registryUrl: RegistryUrl,
packument: UnityPackument
) {
nock(registryUrl).get(`/${packument.name}`).reply(200, packument);
}

/**
* Mocks a packument on the Unity package registry.
* @param packument The packument.
*/
export function mockUnityRegistryPackument(packument: UnityPackument) {
mockRegistryPackument(unityRegistryUrl, packument);
}
43 changes: 43 additions & 0 deletions test/integration/services/built-in-package-check.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import nock from "nock";
import { DomainName } from "../../../src/domain/domain-name";
import { SemanticVersion } from "../../../src/domain/semantic-version";
import { checkIsBuiltInPackage } from "../../../src/services/built-in-package-check";
import { buildPackument } from "../../data-packument";
import { mockUnityDocPage } from "../docs.mock";
import { mockUnityRegistryPackument } from "../registry.mock";

describe("check Unity package is built-in", () => {
const somePackage = DomainName.parse("com.some.package");
const someVersion = SemanticVersion.parse("1.0.0");

beforeEach(() => {
nock.cleanAll();
});

it("should be false if package is not a Unity package", async () => {
const actual = await checkIsBuiltInPackage(somePackage, someVersion);

expect(actual).toBeFalsy();
});

it("should be false if package is Unity package and exists on Unity registry", async () => {
mockUnityDocPage(somePackage);
mockUnityRegistryPackument(
buildPackument(somePackage, (packument) =>
packument.addVersion(someVersion)
)
);

const actual = await checkIsBuiltInPackage(somePackage, someVersion);

expect(actual).toBeFalsy();
});

it("should be true if package is Unity package, but does not exist on Unity registry", async () => {
mockUnityDocPage(somePackage);

const actual = await checkIsBuiltInPackage(somePackage, someVersion);

expect(actual).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion test/unit/cli/cmd-add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from "../../../src/services/get-registry-packument-version";
import { Env, ParseEnv } from "../../../src/services/parse-env";
import { AsyncErr, AsyncOk } from "../../../src/utils/result-utils";
import { buildPackument } from "../domain/data-packument";
import { buildPackument } from "../../data-packument";
import { buildProjectManifest } from "../domain/data-project-manifest";
import { exampleRegistryUrl } from "../domain/data-registry";
import { mockResolvedPackuments } from "../services/remote-packuments.mock";
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cli/cmd-view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SemanticVersion } from "../../../src/domain/semantic-version";
import { GetRegistryPackument } from "../../../src/io/packument-io";
import { GetRegistryAuth } from "../../../src/services/get-registry-auth";
import { Env, ParseEnv } from "../../../src/services/parse-env";
import { buildPackument } from "../domain/data-packument";
import { buildPackument } from "../../data-packument";
import { exampleRegistryUrl } from "../domain/data-registry";
import { mockService } from "../services/service.mock";
import { makeMockLogger } from "./log.mock";
Expand Down
2 changes: 1 addition & 1 deletion test/unit/domain/packument.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
VersionNotFoundError,
} from "../../../src/domain/packument";
import { SemanticVersion } from "../../../src/domain/semantic-version";
import { buildPackument } from "./data-packument";
import { buildPackument } from "../../data-packument";
import { DomainName } from "../../../src/domain/domain-name";

describe("packument", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/io/packument-io.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DomainName } from "../../../src/domain/domain-name";
import { Registry } from "../../../src/domain/registry";
import { FetchRegistryPackument } from "../../../src/io/packument-io";
import { noopLogger } from "../../../src/logging";
import { buildPackument } from "../domain/data-packument";
import { buildPackument } from "../../data-packument";
import { exampleRegistryUrl } from "../domain/data-registry";
import { mockRegClientGetResult } from "../services/registry-client.mock";

Expand Down
77 changes: 0 additions & 77 deletions test/unit/services/built-in-package-check.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/services/get-registry-packument-version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Registry } from "../../../src/domain/registry";
import { SemanticVersion } from "../../../src/domain/semantic-version";
import { GetRegistryPackument } from "../../../src/io/packument-io";
import { FetchRegistryPackumentVersion } from "../../../src/services/get-registry-packument-version";
import { buildPackument } from "../domain/data-packument";
import { buildPackument } from "../../data-packument";
import { exampleRegistryUrl } from "../domain/data-registry";
import { mockService } from "./service.mock";

Expand Down

0 comments on commit 2e66bbb

Please sign in to comment.