Files
printerCentral/scripts/tests/common.js

20 lines
505 B
JavaScript

const axios = require('axios');
const baseURL = process.env.TEST_BASE_URL || 'http://localhost:3000';
const client = axios.create({ baseURL, timeout: 120000 });
async function post(path, body) {
const res = await client.post(path, body);
return res.data;
}
function ensureOk(data, stepName) {
if (!data || data.ok !== true) {
const msg = `Printer did not confirm success on step: ${stepName} -> ${JSON.stringify(data)}`;
throw new Error(msg);
}
}
module.exports = { post, ensureOk };