Initial import of verae-middleware from zapier monorepo
This commit is contained in:
commit
cc2ab54161
66 changed files with 6590 additions and 0 deletions
93
test/helpers.js
Normal file
93
test/helpers.js
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/**
|
||||
* 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 };
|
||||
Loading…
Add table
Add a link
Reference in a new issue