testProfilesAreTheirSignedRecords

tcmts.registry.test.testProfilesAreTheirSignedRecords · #deusv4pw · term

Someone's profile is their signed app.bsky.actor.profile/self: its name and bio, and its picture as their PDS serves it; what isn't a string or a CID isn't taken, and no profile is nothing.

import { startFakeAtproto } from "#codebase/tcmts/cli/test/e2e/examples";
import { withChildren } from "#codebase/tcmts/cli/test/e2e/harness";
import { profileFields, profileOf } from "#codebase/tcmts/registry";
import { withEnv } from "#codebase/tcmts/registry/test";
import assert from "node:assert/strict";

export const testProfilesAreTheirSignedRecords = () =>
  withChildren(async (keep) => {
    const cid = "bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku";
    assert.deepEqual(
      profileFields(
        {
          displayName: " Alice Park ",
          description: "Maps.",
          avatar: { $type: "blob", ref: { $link: cid } },
        },
        "https://pds.example",
        "did:plc:alice",
      ),
      {
        name: "Alice Park",
        bio: "Maps.",
        avatar: `https://pds.example/xrpc/com.atproto.sync.getBlob?did=did%3Aplc%3Aalice&cid=${cid}`,
      },
    );
    assert.deepEqual(
      profileFields(
        { displayName: 3, avatar: { ref: { $link: "javascript:x" } } },
        "https://pds.example",
        "d",
      ),
      {},
    );

    const alice = {
      did: "did:plc:alice000000000000000000",
      handle: "alice.test",
      password: "a-pass",
    };
    const maya = {
      did: "did:plc:maya0000000000000000000",
      handle: "maya.test",
      password: "m-pass",
    };
    const net = await startFakeAtproto(keep, [alice, maya]);
    net.seed(alice.did, "app.bsky.actor.profile", "self", {
      displayName: "Alice Park",
      description: "Maps and geometry.",
    });
    await withEnv({ TCM_ATPROTO_DIRECTORY: net.url, TCM_ATPROTO_LOCAL: "1" }, async () => {
      assert.deepEqual(await profileOf(alice.did), {
        name: "Alice Park",
        bio: "Maps and geometry.",
      });
      assert.deepEqual(await profileOf(maya.did), {});
    });
  })

uses