GET /zapier/v1/receipts/{jobId}?format=json returns a retrieval receipt
with extraSeal.event=document.retrieved. PDF format is 501 until legal
copy exists. OPEN.md lists work that needs Zapier login or live Verae.
72 lines
2.1 KiB
JavaScript
72 lines
2.1 KiB
JavaScript
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();
|
|
});
|
|
}
|