Fix tests.

This commit is contained in:
Sam Rose 2024-01-30 10:23:11 +00:00
parent 669b0743ac
commit 67a848bb86
No known key found for this signature in database
3 changed files with 30 additions and 30 deletions

View File

@ -5,10 +5,10 @@ if [[ -n $CI ]]
then
# Running in ci, where resources are limited
export NODE_OPTIONS="--max-old-space-size=4096"
echo "jest --coverage --maxWorkers=2 --forceExit --workerIdleMemoryLimit=2000MB --bail"
jest --coverage --maxWorkers=2 --forceExit --workerIdleMemoryLimit=2000MB --bail
echo "jest --coverage --maxWorkers=2 --forceExit --workerIdleMemoryLimit=2000MB --bail $@"
jest --coverage --maxWorkers=2 --forceExit --workerIdleMemoryLimit=2000MB --bail $@
else
# --maxWorkers performs better in development
echo "jest --coverage --maxWorkers=2 --forceExit"
jest --coverage --maxWorkers=2 --forceExit
echo "jest --coverage --maxWorkers=2 --forceExit $@"
jest --coverage --maxWorkers=2 --forceExit $@
fi

View File

@ -1,10 +1,15 @@
const automationUtils = require("../automationUtils")
import { LoopStep, LoopStepType } from "../../definitions/automations"
import {
typecastForLooping,
cleanInputValues,
substituteLoopStep,
} from "../automationUtils"
describe("automationUtils", () => {
describe("substituteLoopStep", () => {
it("should allow multiple loop binding substitutes", () => {
expect(
automationUtils.substituteLoopStep(
substituteLoopStep(
`{{ loop.currentItem._id }} {{ loop.currentItem._id }} {{ loop.currentItem._id }}`,
"step.2"
)
@ -15,7 +20,7 @@ describe("automationUtils", () => {
it("should handle not subsituting outside of curly braces", () => {
expect(
automationUtils.substituteLoopStep(
substituteLoopStep(
`loop {{ loop.currentItem._id }}loop loop{{ loop.currentItem._id }}loop`,
"step.2"
)
@ -28,37 +33,32 @@ describe("automationUtils", () => {
describe("typeCastForLooping", () => {
it("should parse to correct type", () => {
expect(
automationUtils.typecastForLooping(
{ inputs: { option: "Array" } },
{ binding: [1, 2, 3] }
)
typecastForLooping({
inputs: { option: LoopStepType.ARRAY, binding: [1, 2, 3] },
} as LoopStep)
).toEqual([1, 2, 3])
expect(
automationUtils.typecastForLooping(
{ inputs: { option: "Array" } },
{ binding: "[1, 2, 3]" }
)
typecastForLooping({
inputs: { option: LoopStepType.ARRAY, binding: "[1,2,3]" },
} as LoopStep)
).toEqual([1, 2, 3])
expect(
automationUtils.typecastForLooping(
{ inputs: { option: "String" } },
{ binding: [1, 2, 3] }
)
typecastForLooping({
inputs: { option: LoopStepType.STRING, binding: [1, 2, 3] },
} as LoopStep)
).toEqual("1,2,3")
})
it("should handle null values", () => {
// expect it to handle where the binding is null
expect(
automationUtils.typecastForLooping(
{ inputs: { option: "Array" } },
{ binding: null }
)
typecastForLooping({
inputs: { option: LoopStepType.ARRAY },
} as LoopStep)
).toEqual(null)
expect(() =>
automationUtils.typecastForLooping(
{ inputs: { option: "Array" } },
{ binding: "test" }
)
typecastForLooping({
inputs: { option: LoopStepType.ARRAY, binding: "test" },
} as LoopStep)
).toThrow()
})
})
@ -80,7 +80,7 @@ describe("automationUtils", () => {
},
}
expect(
automationUtils.cleanInputValues(
cleanInputValues(
{
row: {
relationship: `[{"_id": "ro_ta_users_us_3"}]`,
@ -113,7 +113,7 @@ describe("automationUtils", () => {
},
}
expect(
automationUtils.cleanInputValues(
cleanInputValues(
{
row: {
relationship: `ro_ta_users_us_3`,

View File

@ -11,7 +11,7 @@ export interface LoopStep extends AutomationStep {
export interface LoopInput {
option: LoopStepType
binding: string[] | string
binding?: string[] | string | number[]
}
export interface TriggerOutput {