Compose-ready workspace: packages/zappier (rate card, portal, Stripe), packages/verae-zapier-middleware (timestamp + NATS), packages/verae-zapier (CLI app), vendor/zapier-platform, and research/zapier vendor corpus. Gate 0 structure checks pass. Product code and research are not yet wired.
93 lines
2.2 KiB
JavaScript
93 lines
2.2 KiB
JavaScript
/**
|
|
* Shared test helpers — isolated store + seed tenants.
|
|
*/
|
|
|
|
import { mkdtempSync, rmSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { setStoreForTests, loadStore, emptyStore, persist, getStore } from '../src/store/db.js';
|
|
import { createTenant } from '../src/store/tenants.js';
|
|
import { config } from '../src/config.js';
|
|
|
|
/**
|
|
* Point store at a temp file and reset memory.
|
|
* @returns {{ dir: string, storePath: string, cleanup: () => void }}
|
|
*/
|
|
export function useTempStore() {
|
|
const dir = mkdtempSync(join(tmpdir(), 'verae-mw-'));
|
|
const storePath = join(dir, 'store.json');
|
|
config.storePath = storePath;
|
|
setStoreForTests(null);
|
|
loadStore(storePath);
|
|
// ensure empty
|
|
setStoreForTests(emptyStore());
|
|
persist(storePath);
|
|
|
|
return {
|
|
dir,
|
|
storePath,
|
|
cleanup: () => {
|
|
setStoreForTests(null);
|
|
try {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Seed a free-plan tenant with known credentials (mock Verae).
|
|
* @param {object} [overrides]
|
|
* @returns {{ tenant: object, apiKey: string }}
|
|
*/
|
|
export function seedFreeTenant(overrides = {}) {
|
|
return createTenant({
|
|
id: overrides.id ?? 'tenant-test-free',
|
|
name: overrides.name ?? 'Test Free',
|
|
plan: 'free',
|
|
veraeUsername: overrides.veraeUsername ?? 'zapuser',
|
|
veraePassword: overrides.veraePassword ?? 'zappass',
|
|
metadata: { audience: 'test' },
|
|
...overrides,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Seed a pro tenant (batch allowed).
|
|
*/
|
|
export function seedProTenant() {
|
|
return createTenant({
|
|
id: 'tenant-test-pro',
|
|
name: 'Test Pro',
|
|
plan: 'pro',
|
|
veraeUsername: 'prouser',
|
|
veraePassword: 'propass',
|
|
metadata: { audience: 'test' },
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Seed enterprise with contract.
|
|
*/
|
|
export function seedEnterpriseTenant() {
|
|
return createTenant({
|
|
id: 'tenant-test-ent',
|
|
name: 'Test Enterprise',
|
|
plan: 'enterprise',
|
|
veraeUsername: 'entuser',
|
|
veraePassword: 'entpass',
|
|
contract: {
|
|
includedTimestamps: 10,
|
|
includedVerifications: 10,
|
|
batch: true,
|
|
batchMaxItems: 5,
|
|
requestsPerMinute: 100,
|
|
allowOverage: false,
|
|
},
|
|
metadata: { audience: 'enterprise' },
|
|
});
|
|
}
|
|
|
|
export { getStore, config };
|