|
| 1 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import { MATRIX_QA_E2EE_VERIFICATION_DM_ROOM_KEY } from "./scenario-contract.js"; |
| 3 | +import type { MatrixQaScenarioContext } from "./scenario-runtime-shared.js"; |
| 4 | + |
| 5 | +const mocks = vi.hoisted(() => ({ |
| 6 | + resolveMatrixQaScenarioRoomId: vi.fn(), |
| 7 | + withMatrixQaE2eeDriverAndObserver: vi.fn(), |
| 8 | +})); |
| 9 | + |
| 10 | +vi.mock("./scenario-contract.js", async (importOriginal) => ({ |
| 11 | + ...(await importOriginal()), |
| 12 | + resolveMatrixQaScenarioRoomId: mocks.resolveMatrixQaScenarioRoomId, |
| 13 | +})); |
| 14 | + |
| 15 | +vi.mock("./scenario-runtime-e2ee-shared.js", async (importOriginal) => ({ |
| 16 | + ...(await importOriginal()), |
| 17 | + withMatrixQaE2eeDriverAndObserver: mocks.withMatrixQaE2eeDriverAndObserver, |
| 18 | +})); |
| 19 | + |
| 20 | +import { runMatrixQaE2eeDmSasVerificationScenario } from "./scenario-runtime-e2ee-verification.js"; |
| 21 | + |
| 22 | +function createContext(): MatrixQaScenarioContext { |
| 23 | + return { |
| 24 | + driverPassword: "driver-password", |
| 25 | + observerPassword: "observer-password", |
| 26 | + } as MatrixQaScenarioContext; |
| 27 | +} |
| 28 | + |
| 29 | +beforeEach(() => { |
| 30 | + mocks.resolveMatrixQaScenarioRoomId.mockReset(); |
| 31 | + mocks.withMatrixQaE2eeDriverAndObserver.mockReset(); |
| 32 | +}); |
| 33 | + |
| 34 | +describe("runMatrixQaE2eeDmSasVerificationScenario", () => { |
| 35 | + it("requires authoritative readiness for the resolved verification DM", async () => { |
| 36 | + const roomId = "!verification:matrix-qa.test"; |
| 37 | + const context = createContext(); |
| 38 | + const execution = { artifacts: {}, details: "verification not started" }; |
| 39 | + mocks.resolveMatrixQaScenarioRoomId.mockReturnValue(roomId); |
| 40 | + mocks.withMatrixQaE2eeDriverAndObserver.mockResolvedValue(execution); |
| 41 | + |
| 42 | + await expect(runMatrixQaE2eeDmSasVerificationScenario(context)).resolves.toBe(execution); |
| 43 | + |
| 44 | + expect(mocks.resolveMatrixQaScenarioRoomId).toHaveBeenCalledWith( |
| 45 | + context, |
| 46 | + MATRIX_QA_E2EE_VERIFICATION_DM_ROOM_KEY, |
| 47 | + ); |
| 48 | + expect(mocks.withMatrixQaE2eeDriverAndObserver).toHaveBeenCalledOnce(); |
| 49 | + const [forwardedContext, scenarioId, run, options] = |
| 50 | + mocks.withMatrixQaE2eeDriverAndObserver.mock.calls[0]!; |
| 51 | + expect(forwardedContext).toBe(context); |
| 52 | + expect(scenarioId).toBe("matrix-e2ee-dm-sas-verification"); |
| 53 | + expect(run).toEqual(expect.any(Function)); |
| 54 | + expect(options).toEqual({ readyRoomIds: [roomId] }); |
| 55 | + }); |
| 56 | +}); |
0 commit comments