Initial import of verae-middleware from zapier monorepo
This commit is contained in:
commit
3390a9a8c0
67 changed files with 6630 additions and 0 deletions
72
test/integration/receipt.test.js
Normal file
72
test/integration/receipt.test.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import { describe, it, before, after } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import http from 'node:http';
|
||||
import { createApp } from '../../src/app.js';
|
||||
import { useTempStore, seedProTenant } from '../helpers.js';
|
||||
import { clearMockJobs } from '../../src/clients/veraeClient.js';
|
||||
import { config } from '../../src/config.js';
|
||||
|
||||
describe('retrieval receipt JSON', () => {
|
||||
let ctx;
|
||||
let server;
|
||||
let port;
|
||||
let apiKey;
|
||||
|
||||
before(async () => {
|
||||
config.mockVerae = true;
|
||||
config.natsEnabled = false;
|
||||
config.mockJobCompleteMs = 50;
|
||||
clearMockJobs();
|
||||
ctx = useTempStore();
|
||||
apiKey = seedProTenant().apiKey;
|
||||
const app = createApp();
|
||||
await new Promise((resolve) => {
|
||||
server = app.listen(0, '127.0.0.1', () => {
|
||||
port = server.address().port;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await new Promise((r) => server.close(r));
|
||||
ctx.cleanup();
|
||||
});
|
||||
|
||||
it('issues a JSON extra-seal receipt for a completed job', async () => {
|
||||
const created = await call(port, 'POST', '/zapier/v1/timestamp/wait', apiKey, { data: 'receipt-me' });
|
||||
assert.equal(created.body.status, 'completed');
|
||||
const jobId = created.body.id;
|
||||
const rec = await call(port, 'GET', `/zapier/v1/receipts/${jobId}?format=json`, apiKey);
|
||||
assert.equal(rec.status, 200);
|
||||
assert.equal(rec.body.type, 'verae.retrieval-receipt');
|
||||
assert.equal(rec.body.extraSeal.event, 'document.retrieved');
|
||||
assert.equal(rec.body.jobId, jobId);
|
||||
});
|
||||
});
|
||||
|
||||
function call(port, method, path, apiKey, body) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = http.request(
|
||||
{
|
||||
hostname: '127.0.0.1',
|
||||
port,
|
||||
path,
|
||||
method,
|
||||
headers: { authorization: `Bearer ${apiKey}`, 'content-type': 'application/json' },
|
||||
},
|
||||
(res) => {
|
||||
let data = '';
|
||||
res.on('data', (c) => {
|
||||
data += c;
|
||||
});
|
||||
res.on('end', () => {
|
||||
resolve({ status: res.statusCode, body: data ? JSON.parse(data) : {} });
|
||||
});
|
||||
},
|
||||
);
|
||||
req.on('error', reject);
|
||||
if (body) req.write(JSON.stringify(body));
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue