-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from st-tech/test
test: more tests
- Loading branch information
Showing
2 changed files
with
103 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |