Skip to content

Commit

Permalink
update parameters to support multiple templateTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Woetfin committed May 17, 2024
1 parent 22d56ab commit 82b9c82
Showing 1 changed file with 47 additions and 11 deletions.
58 changes: 47 additions & 11 deletions lib/liquidTestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ const errorUtils = require("./utils/errorUtils");
const { spinner } = require("./cli/spinner");
const SF = require("./api/sfApi");
const fsUtils = require("./utils/fsUtils");
const { ReconciliationText } = require("./templates/reconciliationText");
const runTestUtils = require("./utils/runTestUtils");
const { consola } = require("consola");

const { ReconciliationText } = require("./templates/reconciliationText");
const { AccountTemplate } = require("./templates/accountTemplate");

function findTestRows(testContent) {
const options = { maxAliasCount: 10000 };
const testYAML = yaml.parse(testContent, options);
Expand All @@ -29,18 +31,30 @@ function findTestRows(testContent) {
return indexes;
}

function buildTestParams(firmId, handle, testName = "", renderMode) {
const relativePath = `./reconciliation_texts/${handle}`;
function buildTestParams(
firmId,
templateType = "reconciliationText",
handle,
testName = "",
renderMode
) {
let relativePath = `./reconciliation_texts/${handle}`;

console.log("templateType", templateType);

const configPresent = fsUtils.configExists("reconciliationText", handle);
if (templateType === "accountTemplate") {
relativePath = `./account_templates/${handle}`;
}

const configPresent = fsUtils.configExists(templateType, handle);

if (!configPresent) {
consola.error(`Config file for "${handle}" not found`);

return;
}

const config = fsUtils.readConfig("reconciliationText", handle);
const config = fsUtils.readConfig(templateType, handle);
const testPath = `${relativePath}/${config.test}`;

if (!fs.existsSync(testPath)) {
Expand All @@ -57,12 +71,19 @@ function buildTestParams(firmId, handle, testName = "", renderMode) {
return false;
}

const templateContent = ReconciliationText.read(handle);
templateContent.handle = handle;
templateContent.reconciliation_type = config.reconciliation_type;
let templateContent;

if (templateType === "accountTemplate") {
templateContent = AccountTemplate.read(handle);
} else {
templateContent = ReconciliationText.read(handle);
templateContent.handle = handle;
templateContent.reconciliation_type = config.reconciliation_type;
}

const sharedParts = fsUtils.listSharedPartsUsedInTemplate(
firmId,
"reconciliationText",
templateType,
handle
);
if (sharedParts.length !== 0) {
Expand Down Expand Up @@ -400,13 +421,20 @@ async function handleHTMLfiles(testName = "", testRun, renderMode) {
// Used by VSCode Extension
async function runTests(
firmId,
templateType = "reconciliationText",
handle,
testName = "",
previewOnly = false,
renderMode = "none"
) {
try {
const testParams = buildTestParams(firmId, handle, testName, renderMode);
const testParams = buildTestParams(
firmId,
templateType,
handle,
testName,
renderMode
);
if (!testParams) return;

let testRun = null;
Expand Down Expand Up @@ -443,6 +471,7 @@ async function runTestsWithOutput(
const renderMode = runTestUtils.checkRenderMode(htmlInput, htmlPreview);
const testsRun = await runTests(
firmId,
templateType,
handle,
testName,
previewOnly,
Expand Down Expand Up @@ -476,7 +505,14 @@ async function runTestsStatusOnly(
testName = ""
) {
let status = "FAILED";
const testResult = await runTests(firmId, handle, testName, false, "none");
const testResult = await runTests(
firmId,
templateType,
handle,
testName,
false,
"none"
);

if (!testResult) {
status = "PASSED";
Expand Down

0 comments on commit 82b9c82

Please sign in to comment.