Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: more tests #16

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: more tests
  • Loading branch information
ssssota committed Dec 10, 2024
commit 39af9f7f8b1d958ff80b90e0896d40f651361766
3 changes: 3 additions & 0 deletions src/sim/verify.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,9 @@ export const createVerify: CreateVerify = (json) => {
if (!details || details.length === 0) return "unset";

for (const detail of details) {
if (!detail.appID && (!detail.appIDs || detail.appIDs.length === 0))
continue;

const components = detail.components;
if (!components) continue;
for (const component of components) {
125 changes: 100 additions & 25 deletions tests/node.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,110 @@
import * as assert from "node:assert";
import { test } from "node:test";
import { type AppleAppSiteAssociation, verify } from "universal-links-test";
import {
type AppleAppSiteAssociation,
type ApplinksDetailsComponents,
verify,
} from "universal-links-test";
import { verify as verifySim } from "universal-links-test/sim";

const json = {
applinks: {
details: [
{
appIDs: ["HOGE.com.example.app"],
components: [
{ "#": "nondeeplinking", exclude: true },
{ "/": "/search/" },
],
},
],
},
} as const satisfies AppleAppSiteAssociation;
const getJson = (
components: ApplinksDetailsComponents[],
): AppleAppSiteAssociation => ({
applinks: { details: [{ appID: "HOGE.com.example.app", components }] },
});

test("/search/ should match", async () => {
assert.strictEqual(await verify(json, "/search/"), "match");
assert.strictEqual(await verifySim(json, "/search/"), "match");
test("empty json", async () => {
const json = {};
const path = "/";
assert.strictEqual(await verify(json, path), "unset");
assert.strictEqual(await verifySim(json, path), "unset");
});

test("#nondeeplinking should block", async () => {
assert.strictEqual(await verify(json, "/search/#nondeeplinking"), "block");
assert.strictEqual(await verifySim(json, "/search/#nondeeplinking"), "block");
test("invalid json", async () => {
const json = "{[]}";
const path = "/";
await assert.rejects(() => verify(json, path));
await assert.rejects(() => verifySim(json, path));
});

test("empty json", async () => {
assert.strictEqual(await verify({}, "/"), "unset");
assert.strictEqual(await verifySim({}, "/"), "unset");
assert.strictEqual(await verify("{}", "/"), "unset");
assert.strictEqual(await verifySim("{}", "/"), "unset");
test("empty rule", async () => {
const json = getJson([]);
const path = "/";
assert.strictEqual(await verify(json, path), "unset");
assert.strictEqual(await verifySim(json, path), "unset");
});

test("should match path", async () => {
const json = getJson([{ "/": "/search/" }]);
const path = "/search/";
assert.strictEqual(await verify(json, path), "match");
assert.strictEqual(await verifySim(json, path), "match");
});

test("should exclude", async () => {
const json = getJson([
{ "#": "nondeeplinking", exclude: true },
{ "/": "/search/" },
]);
const path = "/search/#nondeeplinking";
assert.strictEqual(await verify(json, path), "block");
assert.strictEqual(await verifySim(json, path), "block");
});

test("default case sensitive", async () => {
const json = getJson([{ "/": "/search/" }]);
const path = "/SEARCH/";
assert.strictEqual(await verify(json, path), "unset");
assert.strictEqual(await verifySim(json, path), "unset");
});

test("case insensitive", async () => {
const json = getJson([{ "/": "/search/", caseSensitive: false }]);
const path = "/SEARCH/";
assert.strictEqual(await verify(json, path), "match");
assert.strictEqual(await verifySim(json, path), "match");
});

test("should match path with query string and hash", async () => {
const json = getJson([{ "/": "/search/" }]);
const path = "/search/?q=foo#bar";
assert.strictEqual(await verify(json, path), "match");
assert.strictEqual(await verifySim(json, path), "match");
});

test("should match query string", async () => {
const json = getJson([{ "?": "key=value" }]);
const path = "/?key=value";
assert.strictEqual(await verify(json, path), "match");
assert.strictEqual(await verifySim(json, path), "match");
});

test("should not match query string with extras", async () => {
const json = getJson([{ "?": "key=value" }]);
const path = "/?key=value&extra=value";
assert.strictEqual(await verify(json, path), "unset");
assert.strictEqual(await verifySim(json, path), "unset");
});

test("should match query string with key-value object", async () => {
const json = getJson([{ "?": { key: "value" } }]);
const path = "/?key=value";
assert.strictEqual(await verify(json, path), "match");
assert.strictEqual(await verifySim(json, path), "match");
});

test("should match query string with key-value object with extras", async () => {
const json = getJson([{ "?": { key: "value" } }]);
const path = "/?key=value&extra=value";
assert.strictEqual(await verify(json, path), "match");
assert.strictEqual(await verifySim(json, path), "match");
});

test("should unset appIDs and appID not provided", async () => {
const json = {
applinks: { details: [{ components: [{ "/": "/search/" }] }] },
};
const path = "/search/";
assert.strictEqual(await verify(json, path), "unset");
assert.strictEqual(await verifySim(json, path), "unset");
});
Loading