Skip to content
OpenVireoDeveloper
GitHub

Testing your app

Test your app against in-memory servers.

@openvireo/sdk/testing has an in-memory account server and sync server that speak the real protocol (OPAQUE, sealed keys, conditional uploads), so tests run the SDK end to end without a network. They are for tests only: they keep everything in memory and skip checks a real server makes.

import { Account } from "@openvireo/sdk";
import { FakeAuthServer, FakeSyncServer, ISSUER } from "@openvireo/sdk/testing";
const auth = new FakeAuthServer();
const sync = new FakeSyncServer();
auth.onToken = (token) => sync.tokens.add(token); // the sync server accepts the auth server's tokens
// The fake servers live at https://auth.example and https://sync.example
const fetch = (url: string, init?: RequestInit) =>
new URL(url).host === "sync.example" ? sync.fetch(url, init) : auth.fetch(url, init);
const alice = await Account.connect({ issuer: ISSUER, fetch, device: { name: "test", platform: "web" } });
const { secretKey } = await alice.register({ email: "alice@example.com", password: "correct horse" });
const vault = await alice.createVault("Personal");
await vault.write("ov://Personal/GitHub/password", "hunter2", { create: true });
const bob = await Account.connect({ issuer: ISSUER, fetch, device: { name: "test", platform: "web" } });
await bob.login({ email: "alice@example.com", password: "correct horse", secretKey });
const copy = await bob.openVault(vault.id);
expect(copy.read("ov://Personal/GitHub/password")).toBe("hunter2");

Every Account, ServiceAccount and SelfHostedSync takes a fetch option, which is how the fakes plug in.

sync.afterGet = async (key) => { … } Runs after a download and before the upload: write another version here (sync.store(key, bytes)) to test a conflict
sync.blobs Every stored version, by key (vaults/<id> or a database path)
sync.pairing Pairing codes for SelfHostedSync.pair (ABCD-EFGH is there by default)
auth.totp.set(email, code) Turns on two-factor authentication for a user
auth.addMember(orgId, email, role) Adds an accepted org member without the invitation email
auth.approveReset(email, { delaySeconds }) Approves an account recovery and returns the ov_rc_ token
auth.calls, sync.calls Every request the fakes received, to assert on

MockServer, json and bytes build small fakes of your own for other routes.

The fake sync server doesn’t check vault roles from the token. The SDK’s own tests wrap it to do so (see packages/sdk/test/helpers/world.ts); do the same if your test depends on a 403.