Skip to content

Commit

Permalink
create test runs for account templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Woetfin committed May 21, 2024
1 parent 82b9c82 commit da7baff
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
31 changes: 28 additions & 3 deletions lib/api/sfApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,18 @@ async function removeSharedPartFromAccountTemplate(
}
}

async function createTestRun(firmId, attributes) {
async function createTestRun(firmId, attributes, templateType) {
const instance = apiUtils.setAxiosDefaults("firm", firmId);
try {
if (templateType === "accountTemplate") {
const response = await instance.post(
"account_templates/test",
attributes
);

return response;
}

const response = await instance.post("reconciliations/test", attributes);
return response;
} catch (error) {
Expand All @@ -592,9 +601,18 @@ async function createTestRun(firmId, attributes) {
}
}

async function createPreviewRun(firmId, attributes) {
async function createPreviewRun(firmId, attributes, templateType) {
const instance = apiUtils.setAxiosDefaults("firm", firmId);
try {
if (templateType === "accountTemplate") {
const response = await instance.post(
"account_templates/render",
attributes
);

return response;
}

const response = await instance.post("reconciliations/render", attributes);
return response;
} catch (error) {
Expand All @@ -603,9 +621,16 @@ async function createPreviewRun(firmId, attributes) {
}
}

async function readTestRun(firmId, testId) {
async function readTestRun(firmId, testId, templateType) {
const instance = apiUtils.setAxiosDefaults("firm", firmId);
try {
if (templateType === "accountTemplate") {
const response = await instance.get(
`account_templates/test_runs/${testId}`
);
return response;
}

const response = await instance.get(`reconciliations/test_runs/${testId}`);
return response;
} catch (error) {
Expand Down
24 changes: 16 additions & 8 deletions lib/liquidTestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ function buildTestParams(
) {
let relativePath = `./reconciliation_texts/${handle}`;

console.log("templateType", templateType);

if (templateType === "accountTemplate") {
relativePath = `./account_templates/${handle}`;
}
Expand Down Expand Up @@ -118,7 +116,7 @@ function buildTestParams(
return testParams;
}

async function fetchResult(firmId, testRunId) {
async function fetchResult(firmId, testRunId, templateType) {
let testRun = { status: "started" };
let pollingDelay = 1000;
const waitingLimit = 500000;
Expand All @@ -129,7 +127,7 @@ async function fetchResult(firmId, testRunId) {
await new Promise((resolve) => {
setTimeout(resolve, pollingDelay);
});
const response = await SF.readTestRun(firmId, testRunId);
const response = await SF.readTestRun(firmId, testRunId, templateType);
testRun = response.data;
waitingTime += pollingDelay;
pollingDelay *= 1.05;
Expand Down Expand Up @@ -435,21 +433,31 @@ async function runTests(
testName,
renderMode
);

if (!testParams) return;

let testRun = null;
let previewRun = null;

if (renderMode !== "none") {
const previewRunResponse = await SF.createPreviewRun(firmId, testParams);
const previewRunResponse = await SF.createPreviewRun(
firmId,
testParams,
templateType
);
const previewRunId = previewRunResponse.data;
previewRun = await fetchResult(firmId, previewRunId);
previewRun = await fetchResult(firmId, previewRunId, templateType);
}

if (!previewOnly) {
const testRunResponse = await SF.createTestRun(firmId, testParams);
const testRunResponse = await SF.createTestRun(
firmId,
testParams,
templateType
);

const testRunId = testRunResponse.data;
testRun = await fetchResult(firmId, testRunId);
testRun = await fetchResult(firmId, testRunId, templateType);
}

return { testRun, previewRun };
Expand Down

0 comments on commit da7baff

Please sign in to comment.