~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/pds.js

An atproto PDS in JavaScript, for Cloudflare Workers and Node

0
0
main
65 lines · 2.0 KB Raw History
// The records the signed-in visitor writes, built from what the page has in
// hand. The writes themselves go through OAuth and a live PDS, which the
// browser exercises; the shapes are what a unit can hold still.

import { describe, expect, it } from 'vitest';
import { buildPull, buildReview } from '../src/lib/publish.js';

const SUBJECT = {
  uri: 'at://did:plc:owner/dev.pdsjs.git.repo/project',
  cid: 'bafysubject',
};

describe('buildReview', () => {
  it('names the record version, the version read and the pull request', () => {
    const record = buildReview({
      subject: SUBJECT,
      sha: 'a'.repeat(40),
      author: 'did:plc:bob',
      ref: 'refs/heads/fix',
      verdict: 'approve',
      note: 'Reads well.',
    });
    expect(record.$type).toBe('dev.pdsjs.git.review');
    expect(record.subject).toEqual(SUBJECT);
    expect(record.author).toBe('did:plc:bob');
    expect(record.ref).toBe('refs/heads/fix');
    expect(record.verdict).toBe('approve');
    expect(record.note).toBe('Reads well.');
    expect(typeof record.reviewedAt).toBe('string');
  });

  it('leaves out what there is none of', () => {
    const record = buildReview({
      subject: SUBJECT,
      sha: 'a'.repeat(40),
      author: null,
      ref: null,
      verdict: 'comment',
      note: '',
    });
    expect('author' in record).toBe(false);
    expect('ref' in record).toBe(false);
    expect('note' in record).toBe(false);
  });
});

describe('buildPull', () => {
  it('names the branch in the author’s own copy', () => {
    const record = buildPull({
      subject: SUBJECT,
      repo: 'project',
      ref: 'refs/heads/fix',
      sha: 'b'.repeat(40),
      title: 'Fix the reader',
      status: 'draft',
      note: 'Half done.',
    });
    expect(record.$type).toBe('dev.pdsjs.git.pull');
    expect(record.repo).toBe('project');
    expect(record.ref).toBe('refs/heads/fix');
    expect(record.title).toBe('Fix the reader');
    expect(record.status).toBe('draft');
    expect(typeof record.createdAt).toBe('string');
  });
});