Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add missing tests to project and session routes
Sebastian Martinez committed 2 years ago
commit d03f0ae2c0a32e68ace455af05cf8ed0a54a84b0
parent 4bf37b6d266ca0bb79b6abe81ce48dd8cce0dc2f
2 files changed +251 -19
modified httpd-client/tests/project.test.ts
@@ -4,16 +4,26 @@ import { HttpdClient } from "@httpd-client";
import {
  aliceMainHead,
  aliceRemote,
+
  bobRemote,
+
  cobRid,
  sourceBrowsingRid,
-
} from "@tests/support/fixtures";
-

-
const api = new HttpdClient({
-
  hostname: "127.0.0.1",
-
  port: 8080,
-
  scheme: "http",
-
});
+
} from "@tests/support/fixtures.js";
+
import {
+
  assertIssue,
+
  assertPatch,
+
  createIssueToBeModified,
+
  createPatchToBeModified,
+
} from "@httpd-client/tests/support/support";
+
import { authenticate } from "@httpd-client/tests/support/httpd.js";
+
import { testFixture as testWithAPI } from "@httpd-client/tests/support/fixtures.js";

describe("project", () => {
+
  const api = new HttpdClient({
+
    hostname: "127.0.0.1",
+
    port: 8080,
+
    scheme: "http",
+
  });
+

  test("#getByDelegate(delegateId)", async () => {
    await api.project.getByDelegate(aliceRemote);
  });
@@ -76,12 +86,191 @@ describe("project", () => {
    await api.project.getCommitBySha(sourceBrowsingRid, aliceMainHead);
  });

-
  test.todo("#getDiff(id, revisionBase, revisionOid)");
-
  test.todo("#getIssueById(id, issueId)");
-
  test.todo("#getAllIssues(id)");
-
  test.todo("#createIssue(id, { title, description, assignees, tags })");
-
  test.todo("#updateIssue(id, issueId, issueUpdateAction, authToken)");
-
  test.todo("#getPatchById(id, patchId)");
-
  test.todo("#getAllPatches(id)");
-
  test.todo("#updatePatch(id, patchId, patchUpdateAction, authToken)");
+
  test("#getDiff(id, revisionBase, revisionOid)", async () => {
+
    await api.project.getDiff(
+
      sourceBrowsingRid,
+
      "90f6d058ece12f75f349bc7bbe88142187fe0379",
+
      aliceMainHead,
+
    );
+
  });
+

+
  test("#getIssueById(id, issueId)", async () => {
+
    await api.project.getIssueById(
+
      cobRid,
+
      "4fc727e722d3979fd2073d9b56b2751658a4ae79",
+
    );
+
  });
+

+
  test("#getAllIssues(id)", async () => {
+
    await api.project.getAllIssues(cobRid, {
+
      page: 0,
+
      perPage: 5,
+
      state: "open",
+
    });
+
  });
+

+
  testWithAPI(
+
    "#createIssue(id, { title, description, assignees, tags })",
+
    async ({ httpd: { api, peer } }) => {
+
      const sessionId = await authenticate(api, peer);
+
      const { id: issueId } = await api.project.createIssue(
+
        cobRid,
+
        {
+
          title: "aaa",
+
          description: "bbb",
+
          assignees: [],
+
          tags: ["bug", "documentation"],
+
        },
+
        sessionId,
+
      );
+
      await assertIssue(
+
        issueId,
+
        {
+
          title: "aaa",
+
          discussion: [{ body: "bbb" }],
+
          assignees: [],
+
          tags: ["bug", "documentation"],
+
        },
+
        api,
+
      );
+
    },
+
  );
+

+
  testWithAPI(
+
    "#updateIssue(id, issueId, { type: 'edit' }, authToken)",
+
    async ({ httpd: { api, peer } }) => {
+
      const sessionId = await authenticate(api, peer);
+
      const issueId = await createIssueToBeModified(api, sessionId);
+
      await api.project.updateIssue(
+
        cobRid,
+
        issueId,
+
        { type: "edit", title: "ccc" },
+
        sessionId,
+
      );
+
      await assertIssue(issueId, { title: "ccc" }, api);
+
    },
+
  );
+

+
  testWithAPI(
+
    "#updateIssue(id, issueId, { type: 'tag' }, authToken)",
+
    async ({ httpd: { api, peer } }) => {
+
      const sessionId = await authenticate(api, peer);
+
      const issueId = await createIssueToBeModified(api, sessionId);
+
      await api.project.updateIssue(
+
        cobRid,
+
        issueId,
+
        { type: "tag", add: ["bug"], remove: [] },
+
        sessionId,
+
      );
+
      await assertIssue(issueId, { tags: ["bug"] }, api);
+
    },
+
  );
+

+
  testWithAPI(
+
    "#updateIssue(id, issueId, { type: 'assign' }, authToken)",
+
    async ({ httpd: { api, peer } }) => {
+
      const sessionId = await authenticate(api, peer);
+
      const issueId = await createIssueToBeModified(api, sessionId);
+
      const assignee = bobRemote.replace("did:key:", "");
+
      await api.project.updateIssue(
+
        cobRid,
+
        issueId,
+
        {
+
          type: "assign",
+
          add: [assignee],
+
          remove: [],
+
        },
+
        sessionId,
+
      );
+
      await assertIssue(issueId, { assignees: [`did:key:${assignee}`] }, api);
+
    },
+
  );
+

+
  testWithAPI(
+
    "#updateIssue(id, issueId, { type: 'lifecycle' }, authToken)",
+
    async ({ httpd: { api, peer } }) => {
+
      const sessionId = await authenticate(api, peer);
+
      const issueId = await createIssueToBeModified(api, sessionId);
+
      await api.project.updateIssue(
+
        cobRid,
+
        issueId,
+
        { type: "lifecycle", state: { status: "closed", reason: "solved" } },
+
        sessionId,
+
      );
+
      await assertIssue(
+
        issueId,
+
        {
+
          state: { status: "closed", reason: "solved" },
+
        },
+
        api,
+
      );
+
    },
+
  );
+

+
  test("#getPatchById(id, patchId)", async () => {
+
    await api.project.getPatchById(
+
      cobRid,
+
      "013f8b2734df1840b2e33d52ff5632c8d66b199a",
+
    );
+
  });
+

+
  test("#getAllPatches(id)", async () => {
+
    await api.project.getAllPatches(cobRid);
+
  });
+

+
  testWithAPI(
+
    "#createPatch(id, patchCreate, authToken)",
+
    async ({ httpd: { api, peer } }) => {
+
      const sessionId = await authenticate(api, peer);
+
      const { id: oid } = await api.project.createPatch(
+
        cobRid,
+
        {
+
          title: "ppp",
+
          description: "qqq",
+
          target: "d7dd8cecae16b1108234e09dbdb5d64ae394bc25",
+
          oid: "38c225e2a0b47ba59def211f4e4825c31d9463ec",
+
          tags: [],
+
        },
+
        sessionId,
+
      );
+
      await assertPatch(
+
        oid,
+
        {
+
          title: "ppp",
+
          state: { status: "open" },
+
          target: "delegates",
+
          tags: [],
+
          revisions: [
+
            {
+
              description: "qqq",
+
              base: "d7dd8cecae16b1108234e09dbdb5d64ae394bc25",
+
              oid: "38c225e2a0b47ba59def211f4e4825c31d9463ec",
+
            },
+
          ],
+
        },
+
        api,
+
      );
+
    },
+
  );
+

+
  testWithAPI(
+
    "#updatePatch(id, patchId, { type: 'edit' }, authToken)",
+
    async ({ httpd: { api, peer } }) => {
+
      const sessionId = await authenticate(api, peer);
+
      const patchId = await createPatchToBeModified(api, sessionId);
+
      await api.project.updatePatch(
+
        cobRid,
+
        patchId,
+
        { type: "tag", add: ["bug"], remove: [] },
+
        sessionId,
+
      );
+
      await assertPatch(
+
        patchId,
+
        {
+
          tags: ["bug"],
+
        },
+
        api,
+
      );
+
    },
+
  );
});
modified httpd-client/tests/session.test.ts
@@ -1,7 +1,50 @@
+
import * as FsSync from "node:fs";
+
import * as Path from "node:path";
import { describe, test } from "vitest";

-
describe("session", () => {
-
  test.todo("#getById(id)");
-
  test.todo("#update(id, {sig, pk})");
-
  test.todo("#delete(id)");
+
import { HttpdClient } from "@httpd-client";
+
import { authenticate } from "@httpd-client/tests/support/httpd.js";
+
import { createPeerManager } from "@tests/support/peerManager.js";
+
import { gitOptions } from "@tests/support/fixtures.js";
+
import { sessionPayloadSchema } from "@httpd-client/lib/session";
+
import { tmpDir } from "@tests/support/support.js";
+

+
describe("session", async () => {
+
  const peerManager = await createPeerManager({
+
    dataDir: Path.resolve(Path.join(tmpDir, "peers")),
+
    outputLog: FsSync.createWriteStream(
+
      Path.join(tmpDir, "peerManager.log"),
+
    ).setMaxListeners(16),
+
  });
+
  const peer = await peerManager.startPeer({
+
    name: "session",
+
    gitOptions: gitOptions["alice"],
+
  });
+
  await peer.startHttpd();
+
  const api = new HttpdClient(peer.httpdBaseUrl);
+

+
  test("#getById(id)", async () => {
+
    const id = await authenticate(api, peer);
+
    await api.session.getById(id);
+
  });
+

+
  test("#update(id, {sig, pk})", async () => {
+
    const { stdout } = await peer.rad(["web", "--backend", api.url, "--json"]);
+
    const session = sessionPayloadSchema.safeParse(JSON.parse(stdout));
+

+
    if (!session.success) {
+
      throw new Error("Failed to parse session payload");
+
    }
+

+
    const { sessionId, signature, publicKey } = session.data;
+
    await api.session.update(sessionId, {
+
      sig: signature,
+
      pk: publicKey,
+
    });
+
  });
+

+
  test("#delete(id)", async () => {
+
    const id = await authenticate(api, peer);
+
    await api.session.delete(id);
+
  });
});