-
-
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.
- Loading branch information
1 parent
68a190a
commit 4dfe036
Showing
6 changed files
with
154 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2021-present the Registerable authors. All rights reserved. MIT license. | ||
import { assertEquals } from "../dev_deps.ts"; | ||
import { client } from "./client.ts"; | ||
|
||
Deno.test("client", async () => { | ||
const table: [ | ||
...Parameters<typeof client>, | ||
any, | ||
][] = [ | ||
["fonction", { registry: ["deno.land"] }, { | ||
error: {}, | ||
errorRegistry: [], | ||
hasError: false, | ||
name: "fonction", | ||
result: { | ||
"deno.land": false, | ||
}, | ||
}], | ||
["@@@", { registry: ["deno.land", "nest.land"] }, { | ||
error: { | ||
"deno.land": "Name contains only the characters a-z, 0-9 and _", | ||
"nest.land": "Name contains only the characters a-z, 0-9 and _", | ||
}, | ||
errorRegistry: ["deno.land", "nest.land"], | ||
hasError: true, | ||
name: "@@@", | ||
result: { | ||
"deno.land": false, | ||
"nest.land": false, | ||
}, | ||
}], | ||
]; | ||
|
||
await Promise.all(table.map(async ([name, option, expected]) => { | ||
assertEquals(await client(name, option), expected); | ||
})); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Registry } from "../types/mod.ts"; | ||
const BASE_URL = "https://registerable-cpqkjhmf3-tomoki-miyauci.vercel.app/"; | ||
|
||
const stringify = ( | ||
val: { name: string; registry: Registry[] }, | ||
): string => { | ||
const url = new URL("check-name", BASE_URL); | ||
url.search = constructSearchParams(val).toString(); | ||
|
||
return url.toString(); | ||
}; | ||
|
||
const constructSearchParams = ( | ||
{ name, registry }: { name: string; registry: Registry[] }, | ||
): URLSearchParams => { | ||
const urlSearchParams = new URLSearchParams({ name }); | ||
registry.forEach((reg) => { | ||
urlSearchParams.append("registry", reg); | ||
}); | ||
|
||
return urlSearchParams; | ||
}; | ||
|
||
export { BASE_URL, constructSearchParams, stringify }; |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { BASE_URL, constructSearchParams, stringify } from "./stringify.ts"; | ||
import { Registry } from "../types/mod.ts"; | ||
|
||
import { assertEquals } from "../dev_deps.ts"; | ||
Deno.test("stringify", () => { | ||
const table: [{ name: string; registry: Registry[] }, string][] = [[{ | ||
name: "fonction", | ||
registry: [], | ||
}, `${BASE_URL}check-name?name=fonction`], [ | ||
{ | ||
name: "fonction", | ||
registry: ["deno.land", "nest.land"], | ||
}, | ||
`${BASE_URL}check-name?name=fonction®istry=deno.land®istry=nest.land`, | ||
]]; | ||
|
||
table.forEach(([val, expected]) => { | ||
assertEquals(stringify(val), expected); | ||
}); | ||
}); | ||
Deno.test("constructSearchParams", () => { | ||
const table: [{ name: string; registry: Registry[] }, string][] = [[ | ||
{ name: "hoge", registry: [] }, | ||
"name=hoge", | ||
], [ | ||
{ name: "hoge", registry: ["npm"] }, | ||
"name=hoge®istry=npm", | ||
], [ | ||
{ name: "hoge", registry: ["npm", "nest.land", "deno.land"] }, | ||
"name=hoge®istry=npm®istry=nest.land®istry=deno.land", | ||
], [ | ||
{ name: "hoge", registry: ["nest.land", "npm"] }, | ||
"name=hoge®istry=nest.land®istry=npm", | ||
]]; | ||
|
||
table.forEach(([val, expected]) => { | ||
assertEquals(constructSearchParams(val).toString(), expected); | ||
}); | ||
}); |
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