+31
.github/workflows/test.yml
+31
.github/workflows/test.yml
···
1
+
name: Testing
2
+
3
+
on:
4
+
push:
5
+
branches:
6
+
- main
7
+
pull_request:
8
+
branches: ["main"]
9
+
10
+
11
+
concurrency:
12
+
group: ${{ github.workflow }}-${{ github.ref }}
13
+
cancel-in-progress: true
14
+
15
+
jobs:
16
+
lint:
17
+
runs-on: ubuntu-latest
18
+
steps:
19
+
- uses: actions/checkout@v4
20
+
- name: Install PNPM
21
+
uses: pnpm/action-setup@v4
22
+
with:
23
+
version: 10
24
+
- name: Setup Node
25
+
uses: actions/setup-node@v4
26
+
with:
27
+
cache: "pnpm"
28
+
- name: Install dependencies
29
+
run: pnpm install
30
+
- name: Test
31
+
run: pnpm test
+1
package.json
+1
package.json
···
20
20
"scripts": {
21
21
"lint": "biome lint",
22
22
"format": "biome format --write ./src",
23
+
"test": "vitest --run",
23
24
"lex-gen": "lex gen-api ./src/leaflet/lexicons ./lexicons/pub/leaflet/* ./lexicons/pub/leaflet/*/* ./lexicons/com/atproto/*/* --yes",
24
25
"typecheck": "tsc --noEmit",
25
26
"build": "rm -rf dist && tsc"
+14
src/tests/uri-to-rkey.test.ts
+14
src/tests/uri-to-rkey.test.ts
···
1
+
import { expect, test } from "vitest";
2
+
import { uriToRkey } from "../utils";
3
+
4
+
test("should throw if invalid at uri is passed in", () => {
5
+
expect(() => uriToRkey("test")).toThrowError("get rkey");
6
+
});
7
+
8
+
test("should pass if valid at uri is passed in", () => {
9
+
expect(
10
+
uriToRkey(
11
+
"at://did:plc:qttsv4e7pu2jl3ilanfgc3zn/pub.leaflet.document/3lvl7m6jd4s2e",
12
+
),
13
+
).toBe("3lvl7m6jd4s2e");
14
+
});
+4
-4
src/utils.ts
+4
-4
src/utils.ts
···
1
-
import { UnicodeString } from "@atproto/api";
1
+
import { AtUri, UnicodeString } from "@atproto/api";
2
2
import sanitizeHTML from "sanitize-html";
3
3
import {
4
4
PubLeafletBlocksHeader,
···
19
19
} from "./types.js";
20
20
21
21
export function uriToRkey(uri: string): string {
22
-
const rkey = uri.split("/").pop();
23
-
if (!rkey) {
22
+
const u = AtUri.make(uri);
23
+
if (!u.rkey) {
24
24
throw new Error("Failed to get rkey from uri.");
25
25
}
26
-
return rkey;
26
+
return u.rkey;
27
27
}
28
28
29
29
export async function resolveMiniDoc(handleOrDid: string) {