Rename httpd-client to http-client

This commit is contained in:
Sebastian Martinez
2024-06-07 12:22:28 +02:00
parent f87c09c634
commit 2ee8bae82e
89 changed files with 110 additions and 122 deletions
+32
View File
@@ -0,0 +1,32 @@
import * as FsSync from "node:fs";
import * as Path from "node:path";
import { test } from "vitest";
import { HttpdClient } from "@http-client";
import { RadiclePeer, createPeerManager } from "@tests/support/peerManager.js";
import { gitOptions } from "@tests/support/fixtures.js";
import { tmpDir } from "@tests/support/support.js";
interface TestFixtures {
httpd: { api: HttpdClient; peer: RadiclePeer };
}
export const testFixture = test.extend<TestFixtures>({
// eslint-disable-next-line no-empty-pattern
httpd: async ({}, use) => {
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.createPeer({
name: "palm",
gitOptions: gitOptions["alice"],
});
await peer.startHttpd();
const api = new HttpdClient(peer.httpdBaseUrl);
await use({ api, peer });
await peer.shutdown();
},
});
+30
View File
@@ -0,0 +1,30 @@
import type { HttpdClient } from "@http-client";
import type { RadiclePeer } from "@tests/support/peerManager.js";
import assert from "node:assert";
export async function authenticate(
api: HttpdClient,
peer: RadiclePeer,
): Promise<string> {
const { stdout } = await peer.spawn("rad-web", [
"http://localhost:3001",
"--no-open",
"--connect",
`${peer.httpdBaseUrl.hostname}:${peer.httpdBaseUrl.port}`,
]);
const match = stdout.match(/Visit (http:\/\/\S+) to connect/);
assert(
match !== null && match[1],
`Failed to get authentication URL from: ${stdout}`,
);
const authUrl = new URL(match[1]);
const sessionId = authUrl.pathname.split("/")[2];
await api.session.update(sessionId, {
sig: authUrl.searchParams.get("sig")!,
pk: authUrl.searchParams.get("pk")!,
});
return sessionId;
}
+59
View File
@@ -0,0 +1,59 @@
import type { HttpdClient } from "@http-client";
import { expect } from "vitest";
import isMatch from "lodash/isMatch";
import { cobRid } from "@tests/support/fixtures";
export async function createIssueToBeModified(
api: HttpdClient,
sessionId: string,
) {
const { id } = await api.project.createIssue(
cobRid,
{ title: "aaa", description: "bbb", embeds: [], assignees: [], labels: [] },
sessionId,
);
return id;
}
export async function createPatchToBeModified(
api: HttpdClient,
sessionId: string,
) {
const { id } = await api.project.createPatch(
cobRid,
{
title: "rrr",
description: "ttt",
target: "d7dd8cecae16b1108234e09dbdb5d64ae394bc25",
oid: "38c225e2a0b47ba59def211f4e4825c31d9463ec",
labels: [],
},
sessionId,
);
return id;
}
export async function assertIssue(
oid: string,
change: Record<string, unknown>,
api: HttpdClient,
) {
expect(
//@prettier-ignore looks more readable than what prettier suggests.
isMatch(await api.project.getIssueById(cobRid, oid), change),
).toBe(true);
}
export async function assertPatch(
oid: string,
change: Record<string, unknown>,
api: HttpdClient,
) {
expect(
//@prettier-ignore looks more readable than what prettier suggests.
isMatch(await api.project.getPatchById(cobRid, oid), change),
).toBe(true);
}