|
1 |
| -import { NSID } from "@atproto/syntax"; |
| 1 | +import { AtUri, NSID } from "@atproto/syntax"; |
2 | 2 | import type { Resolution } from "./node.ts";
|
3 | 3 | import { NodeRegistry } from "./node-registry.ts";
|
4 | 4 | import { assertEquals, assertObjectMatch } from "jsr:@std/assert";
|
5 | 5 | import { bootstrap } from "@needle-di/core";
|
6 | 6 | import { Lexicons } from "@atproto/lexicon";
|
7 |
| -import { skip } from "node:test"; |
| 7 | +import { AtpBaseClient } from "npm:@atproto/api"; |
8 | 8 |
|
9 | 9 | function assertSuccessfullResolution(
|
10 | 10 | data: Resolution,
|
@@ -93,30 +93,45 @@ Deno.test("doesn't resolve the same uri twice", async () => {
|
93 | 93 | assertEquals(new Set(duplicateUris), new Set());
|
94 | 94 | });
|
95 | 95 |
|
96 |
| -Deno.test, |
97 |
| - skip("can validate a post record", async () => { |
98 |
| - const NSID_STR = "app.bsky.feed.post"; |
99 |
| - const registry = bootstrap(NodeRegistry); |
100 |
| - const resolutions = []; |
101 |
| - for await ( |
102 |
| - const resolution of registry.resolve([ |
103 |
| - registry.get(NSID.parse(NSID_STR)), |
104 |
| - ]) |
105 |
| - ) { |
106 |
| - assertSuccessfullResolution(resolution); |
107 |
| - resolutions.push(resolution); |
108 |
| - } |
109 |
| - |
110 |
| - const lexicons = new Lexicons(resolutions.map((r) => r.doc)); |
111 |
| - |
112 |
| - const exampleRecords = [ |
113 |
| - '{"uri":"at://did:plc:2xau7wbgdq4phuou2ypwuen7/app.bsky.feed.post/3ljrsfbuuyk2g","cid":"bafyreigjrpyhhk5fibcajhhtkcefmxptntgx35t5zngvsxwwvu56hzioaq","value":{"text":"To update a globally installed CLI in deno you pass -fr\\n\\nfr fr","$type":"app.bsky.feed.post","langs":["en"],"createdAt":"2025-03-07T10:28:47.874Z"}}', |
114 |
| - '{"uri":"at://did:plc:yosojsta3nm5qiod5zqixzur/app.bsky.feed.post/3ljpreuc6fs2c","cid":"bafyreihyt2ckoxoyusimrexuxatuwazct7uiskukhspxic756inddofipy","value":{"text":"DOGE “seemed unsure” of what USAID programs they cut and is now attempting to reverse some of the cuts, says @propublica.org reporter Brett Murphy. “This is the opposite of a careful review.\\"","$type":"app.bsky.feed.post","embed":{"$type":"app.bsky.embed.video","video":{"$type":"blob","ref":{"$link":"bafkreidowys6ntilo4wslx23jishxiqfrwywqmxxer4sy2r6y5orwuosn4"},"mimeType":"video/mp4","size":8408607},"aspectRatio":{"width":1280,"height":720}},"langs":["en"],"facets":[{"$type":"app.bsky.richtext.facet","index":{"byteEnd":128,"byteStart":113},"features":[{"did":"did:plc:k4jt6heuiamymgi46yeuxtpt","$type":"app.bsky.richtext.facet#mention"}]}],"createdAt":"2025-03-06T15:05:20.412Z"}}', |
115 |
| - ].map((s) => JSON.parse(s).value); |
116 |
| - |
117 |
| - for (const exampleRecord of exampleRecords) { |
118 |
| - const result = lexicons.validate(NSID_STR, exampleRecord); |
119 |
| - // @ts-expect-error result.error isn't narrowed |
120 |
| - assertEquals(result.success, true, `Failed to validate: ${result.error}`); |
121 |
| - } |
122 |
| - }); |
| 96 | +Deno.test("can validate a post record", async () => { |
| 97 | + const NSID_STR = "app.bsky.feed.post"; |
| 98 | + const registry = bootstrap(NodeRegistry); |
| 99 | + const resolutions = []; |
| 100 | + for await ( |
| 101 | + const resolution of registry.resolve([ |
| 102 | + registry.get(NSID.parse(NSID_STR)), |
| 103 | + ]) |
| 104 | + ) { |
| 105 | + assertSuccessfullResolution(resolution); |
| 106 | + resolutions.push(resolution); |
| 107 | + } |
| 108 | + |
| 109 | + const client = new AtpBaseClient("https://api.bsky.app"); |
| 110 | + |
| 111 | + const postUris = [ |
| 112 | + "at://did:plc:2xau7wbgdq4phuou2ypwuen7/app.bsky.feed.post/3ljmvgixb327d", |
| 113 | + ].map((uri) => new AtUri(uri)); |
| 114 | + |
| 115 | + const records = await Promise.all( |
| 116 | + postUris.map((uri) => |
| 117 | + client.com.atproto.repo.getRecord({ |
| 118 | + repo: uri.host, |
| 119 | + collection: uri.collection, |
| 120 | + rkey: uri.rkey, |
| 121 | + }) |
| 122 | + ), |
| 123 | + ); |
| 124 | + |
| 125 | + const lexicons = new Lexicons(resolutions.map((r) => r.doc)); |
| 126 | + |
| 127 | + for (const record of records) { |
| 128 | + const result = lexicons.validate(NSID_STR, record.data.value); |
| 129 | + assertEquals( |
| 130 | + result.success, |
| 131 | + true, |
| 132 | + `Failed to validate ${record.data.uri}: ${ |
| 133 | + // @ts-expect-error result.error isn't narrowed |
| 134 | + result.error}`, |
| 135 | + ); |
| 136 | + } |
| 137 | +}); |
0 commit comments