mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 15:47:28 +00:00
test: tighten google meet cli assertions
This commit is contained in:
@@ -42,6 +42,27 @@ function captureStdout() {
|
||||
};
|
||||
}
|
||||
|
||||
function expectFields(value: unknown, expected: Record<string, unknown>): void {
|
||||
expect(value).toBeTypeOf("object");
|
||||
expect(value).not.toBeNull();
|
||||
const record = value as Record<string, unknown>;
|
||||
for (const [key, expectedValue] of Object.entries(expected)) {
|
||||
expect(record[key], key).toEqual(expectedValue);
|
||||
}
|
||||
}
|
||||
|
||||
function firstRecord(value: unknown): Record<string, unknown> {
|
||||
expect(Array.isArray(value)).toBe(true);
|
||||
const [record] = value as unknown[];
|
||||
expect(record).toBeTypeOf("object");
|
||||
expect(record).not.toBeNull();
|
||||
return record as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function parseStdoutJson(stdout: { output: () => string }): Record<string, unknown> {
|
||||
return JSON.parse(stdout.output()) as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function jsonResponse(value: unknown): Response {
|
||||
return new Response(JSON.stringify(value), {
|
||||
status: 200,
|
||||
@@ -260,9 +281,11 @@ describe("google-meet CLI", () => {
|
||||
}),
|
||||
},
|
||||
}).parseAsync(["googlemeet", "setup", "--json"], { from: "user" });
|
||||
expect(JSON.parse(stdout.output())).toMatchObject({
|
||||
const payload = parseStdoutJson(stdout);
|
||||
expectFields(payload, { ok: false });
|
||||
expectFields(firstRecord(payload.checks), {
|
||||
id: "twilio-voice-call-plugin",
|
||||
ok: false,
|
||||
checks: [{ id: "twilio-voice-call-plugin", ok: false }],
|
||||
});
|
||||
} finally {
|
||||
stdout.restore();
|
||||
@@ -289,22 +312,21 @@ describe("google-meet CLI", () => {
|
||||
],
|
||||
{ from: "user" },
|
||||
);
|
||||
expect(JSON.parse(artifactsStdout.output())).toMatchObject({
|
||||
conferenceRecords: [{ name: "conferenceRecords/rec-1" }],
|
||||
artifacts: [
|
||||
{
|
||||
recordings: [{ name: "conferenceRecords/rec-1/recordings/r1" }],
|
||||
transcripts: [{ name: "conferenceRecords/rec-1/transcripts/t1" }],
|
||||
transcriptEntries: [
|
||||
{
|
||||
transcript: "conferenceRecords/rec-1/transcripts/t1",
|
||||
entries: [{ text: "Hello from the transcript." }],
|
||||
},
|
||||
],
|
||||
smartNotes: [{ name: "conferenceRecords/rec-1/smartNotes/sn1" }],
|
||||
},
|
||||
],
|
||||
tokenSource: "cached-access-token",
|
||||
const payload = parseStdoutJson(artifactsStdout);
|
||||
expectFields(payload, { tokenSource: "cached-access-token" });
|
||||
expectFields(firstRecord(payload.conferenceRecords), { name: "conferenceRecords/rec-1" });
|
||||
const artifact = firstRecord(payload.artifacts);
|
||||
expectFields(firstRecord(artifact.recordings), {
|
||||
name: "conferenceRecords/rec-1/recordings/r1",
|
||||
});
|
||||
expectFields(firstRecord(artifact.transcripts), {
|
||||
name: "conferenceRecords/rec-1/transcripts/t1",
|
||||
});
|
||||
const transcriptEntries = firstRecord(artifact.transcriptEntries);
|
||||
expectFields(transcriptEntries, { transcript: "conferenceRecords/rec-1/transcripts/t1" });
|
||||
expectFields(firstRecord(transcriptEntries.entries), { text: "Hello from the transcript." });
|
||||
expectFields(firstRecord(artifact.smartNotes), {
|
||||
name: "conferenceRecords/rec-1/smartNotes/sn1",
|
||||
});
|
||||
} finally {
|
||||
artifactsStdout.restore();
|
||||
@@ -367,7 +389,7 @@ describe("google-meet CLI", () => {
|
||||
],
|
||||
{ from: "user" },
|
||||
);
|
||||
expect(JSON.parse(stdout.output())).toMatchObject({
|
||||
expectFields(parseStdoutJson(stdout), {
|
||||
space: "spaces/space-resource-123",
|
||||
ended: true,
|
||||
tokenSource: "cached-access-token",
|
||||
@@ -602,28 +624,26 @@ describe("google-meet CLI", () => {
|
||||
"Transcript document body.",
|
||||
);
|
||||
const manifest = JSON.parse(readFileSync(path.join(tempDir, "manifest.json"), "utf8"));
|
||||
expect(manifest).toMatchObject({
|
||||
request: {
|
||||
conferenceRecord: "rec-1",
|
||||
includeDocumentBodies: true,
|
||||
},
|
||||
tokenSource: "cached-access-token",
|
||||
counts: {
|
||||
attendanceRows: 1,
|
||||
warnings: 0,
|
||||
},
|
||||
files: [
|
||||
"summary.md",
|
||||
"attendance.csv",
|
||||
"transcript.md",
|
||||
"artifacts.json",
|
||||
"attendance.json",
|
||||
"manifest.json",
|
||||
],
|
||||
expectFields(manifest.request, {
|
||||
conferenceRecord: "rec-1",
|
||||
includeDocumentBodies: true,
|
||||
});
|
||||
expect(JSON.parse(readFileSync(path.join(tempDir, "artifacts.json"), "utf8"))).toMatchObject({
|
||||
conferenceRecords: [{ name: "conferenceRecords/rec-1" }],
|
||||
artifacts: [{ transcripts: [{ documentText: "Transcript document body." }] }],
|
||||
expectFields(manifest, {
|
||||
tokenSource: "cached-access-token",
|
||||
});
|
||||
expectFields(manifest.counts, { attendanceRows: 1, warnings: 0 });
|
||||
expect(manifest.files).toEqual([
|
||||
"summary.md",
|
||||
"attendance.csv",
|
||||
"transcript.md",
|
||||
"artifacts.json",
|
||||
"attendance.json",
|
||||
"manifest.json",
|
||||
]);
|
||||
const artifacts = JSON.parse(readFileSync(path.join(tempDir, "artifacts.json"), "utf8"));
|
||||
expectFields(firstRecord(artifacts.conferenceRecords), { name: "conferenceRecords/rec-1" });
|
||||
expectFields(firstRecord(firstRecord(artifacts.artifacts).transcripts), {
|
||||
documentText: "Transcript document body.",
|
||||
});
|
||||
expect(readFileSync(`${tempDir}.zip`).subarray(0, 4).toString("hex")).toBe("504b0304");
|
||||
} finally {
|
||||
@@ -660,15 +680,11 @@ describe("google-meet CLI", () => {
|
||||
expect(summary).toContain("### Warnings");
|
||||
expect(summary).toContain("Document body warning");
|
||||
const manifest = JSON.parse(readFileSync(path.join(tempDir, "manifest.json"), "utf8"));
|
||||
expect(manifest).toMatchObject({
|
||||
counts: { warnings: 1 },
|
||||
warnings: [
|
||||
{
|
||||
type: "smart_note_document_body",
|
||||
conferenceRecord: "conferenceRecords/rec-1",
|
||||
resource: "conferenceRecords/rec-1/smartNotes/sn1",
|
||||
},
|
||||
],
|
||||
expectFields(manifest.counts, { warnings: 1 });
|
||||
expectFields(firstRecord(manifest.warnings), {
|
||||
type: "smart_note_document_body",
|
||||
conferenceRecord: "conferenceRecords/rec-1",
|
||||
resource: "conferenceRecords/rec-1/smartNotes/sn1",
|
||||
});
|
||||
} finally {
|
||||
stdout.restore();
|
||||
@@ -700,9 +716,11 @@ describe("google-meet CLI", () => {
|
||||
}),
|
||||
},
|
||||
}).parseAsync(["googlemeet", "status", "--json"], { from: "user" });
|
||||
expect(JSON.parse(stdout.output())).toMatchObject({
|
||||
found: true,
|
||||
sessions: [{ id: "meet_1", transport: "twilio" }],
|
||||
const payload = parseStdoutJson(stdout);
|
||||
expectFields(payload, { found: true });
|
||||
expectFields(firstRecord(payload.sessions), {
|
||||
id: "meet_1",
|
||||
transport: "twilio",
|
||||
});
|
||||
} finally {
|
||||
stdout.restore();
|
||||
@@ -743,9 +761,11 @@ describe("google-meet CLI", () => {
|
||||
{ progress: false },
|
||||
);
|
||||
expect(ensureRuntime).not.toHaveBeenCalled();
|
||||
expect(JSON.parse(stdout.output())).toMatchObject({
|
||||
found: true,
|
||||
sessions: [{ id: "meet_gateway", transport: "chrome-node" }],
|
||||
const payload = parseStdoutJson(stdout);
|
||||
expectFields(payload, { found: true });
|
||||
expectFields(firstRecord(payload.sessions), {
|
||||
id: "meet_gateway",
|
||||
transport: "chrome-node",
|
||||
});
|
||||
} finally {
|
||||
stdout.restore();
|
||||
@@ -812,7 +832,7 @@ describe("google-meet CLI", () => {
|
||||
});
|
||||
expect(gatewayCall?.[3]).toEqual({ progress: false });
|
||||
expect(ensureRuntime).not.toHaveBeenCalled();
|
||||
expect(JSON.parse(stdout.output())).toMatchObject({
|
||||
expectFields(parseStdoutJson(stdout), {
|
||||
id: "meet_gateway",
|
||||
transport: "chrome-node",
|
||||
});
|
||||
@@ -875,10 +895,9 @@ describe("google-meet CLI", () => {
|
||||
{ progress: false },
|
||||
);
|
||||
expect(ensureRuntime).not.toHaveBeenCalled();
|
||||
expect(JSON.parse(stdout.output())).toMatchObject({
|
||||
createdSession: true,
|
||||
session: { mode: "bidi" },
|
||||
});
|
||||
const payload = parseStdoutJson(stdout);
|
||||
expectFields(payload, { createdSession: true });
|
||||
expectFields(payload.session, { mode: "bidi" });
|
||||
} finally {
|
||||
stdout.restore();
|
||||
}
|
||||
@@ -924,7 +943,7 @@ describe("google-meet CLI", () => {
|
||||
transport: "chrome-node",
|
||||
timeoutMs: 30000,
|
||||
});
|
||||
expect(JSON.parse(stdout.output())).toMatchObject({
|
||||
expectFields(parseStdoutJson(stdout), {
|
||||
listenVerified: true,
|
||||
transcriptLines: 1,
|
||||
});
|
||||
@@ -958,29 +977,27 @@ describe("google-meet CLI", () => {
|
||||
{ from: "user" },
|
||||
);
|
||||
const payload = JSON.parse(stdout.output());
|
||||
expect(payload).toMatchObject({
|
||||
expectFields(payload, {
|
||||
dryRun: true,
|
||||
manifest: {
|
||||
request: {
|
||||
conferenceRecord: "rec-1",
|
||||
includeDocumentBodies: true,
|
||||
},
|
||||
counts: {
|
||||
attendanceRows: 1,
|
||||
transcriptEntries: 1,
|
||||
warnings: 0,
|
||||
},
|
||||
files: [
|
||||
"summary.md",
|
||||
"attendance.csv",
|
||||
"transcript.md",
|
||||
"artifacts.json",
|
||||
"attendance.json",
|
||||
"manifest.json",
|
||||
],
|
||||
},
|
||||
tokenSource: "cached-access-token",
|
||||
});
|
||||
expectFields(payload.manifest.request, {
|
||||
conferenceRecord: "rec-1",
|
||||
includeDocumentBodies: true,
|
||||
});
|
||||
expectFields(payload.manifest.counts, {
|
||||
attendanceRows: 1,
|
||||
transcriptEntries: 1,
|
||||
warnings: 0,
|
||||
});
|
||||
expect(payload.manifest.files).toEqual([
|
||||
"summary.md",
|
||||
"attendance.csv",
|
||||
"transcript.md",
|
||||
"artifacts.json",
|
||||
"attendance.json",
|
||||
"manifest.json",
|
||||
]);
|
||||
expect(existsSync(outputDir)).toBe(false);
|
||||
} finally {
|
||||
stdout.restore();
|
||||
@@ -1115,15 +1132,15 @@ describe("google-meet CLI", () => {
|
||||
expect(output).not.toContain("new-access-token");
|
||||
expect(output).not.toContain("rt-secret");
|
||||
expect(output).not.toContain("client-secret");
|
||||
expect(JSON.parse(output)).toMatchObject({
|
||||
const payload = JSON.parse(output) as Record<string, unknown>;
|
||||
expectFields(payload, {
|
||||
ok: true,
|
||||
configured: true,
|
||||
tokenSource: "refresh-token",
|
||||
checks: [
|
||||
{ id: "oauth-config", ok: true },
|
||||
{ id: "oauth-token", ok: true },
|
||||
],
|
||||
});
|
||||
const checks = payload.checks as unknown[];
|
||||
expectFields(checks[0], { id: "oauth-config", ok: true });
|
||||
expectFields(checks[1], { id: "oauth-token", ok: true });
|
||||
expect(ensureRuntime).not.toHaveBeenCalled();
|
||||
const body = fetchMock.mock.calls[0]?.[1]?.body as URLSearchParams;
|
||||
expect(body.get("grant_type")).toBe("refresh_token");
|
||||
@@ -1166,17 +1183,17 @@ describe("google-meet CLI", () => {
|
||||
}).parseAsync(["googlemeet", "doctor", "--oauth", "--create-space", "--json"], {
|
||||
from: "user",
|
||||
});
|
||||
expect(JSON.parse(stdout.output())).toMatchObject({
|
||||
const payload = parseStdoutJson(stdout);
|
||||
expectFields(payload, {
|
||||
ok: true,
|
||||
tokenSource: "refresh-token",
|
||||
createdSpace: "spaces/new-space",
|
||||
meetingUri: "https://meet.google.com/new-abcd-xyz",
|
||||
checks: [
|
||||
{ id: "oauth-config", ok: true },
|
||||
{ id: "oauth-token", ok: true },
|
||||
{ id: "meet-spaces-create", ok: true },
|
||||
],
|
||||
});
|
||||
const checks = payload.checks as unknown[];
|
||||
expectFields(checks[0], { id: "oauth-config", ok: true });
|
||||
expectFields(checks[1], { id: "oauth-token", ok: true });
|
||||
expectFields(checks[2], { id: "meet-spaces-create", ok: true });
|
||||
} finally {
|
||||
stdout.restore();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user