Skip to content

Commit 58fb7f3

Browse files
committed
chore: update test name, refactor column processing
1 parent 67da5b5 commit 58fb7f3

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

packages/backend/src/apps/toolbox/__tests__/actions/for-each/get-data-out-metadata.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ describe('getDataOutMetadata', () => {
554554
})
555555

556556
describe('when inputSource is unrecognized', () => {
557-
it('should throw an error for unknown input source', async () => {
557+
it('should return null for unknown input source', async () => {
558558
const dataOut = {
559559
iterations: 1,
560560
inputSource: 'unknown-source',
@@ -565,7 +565,7 @@ describe('getDataOutMetadata', () => {
565565
await expect(getDataOutMetadata(executionStep)).resolves.toBeNull()
566566
})
567567

568-
it('should throw an error when inputSource is null', async () => {
568+
it('should return null when inputSource is null', async () => {
569569
const dataOut = {
570570
iterations: 1,
571571
inputSource: null as any,
@@ -577,7 +577,7 @@ describe('getDataOutMetadata', () => {
577577
})
578578

579579
describe('schema validation edge cases', () => {
580-
it('should handle dataOut that fails schema validation', async () => {
580+
it('should return null when dataOut fails schema validation', async () => {
581581
const dataOut = {
582582
// missing required fields
583583
invalidField: 'invalid',

packages/backend/src/apps/toolbox/common/get-for-each-variables.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,27 @@ function processColumns(data: MultipleRowObject): {
3131
inputSource: InputSource
3232
processedColumns: ProcessedColumn[]
3333
} {
34-
const processedColumns: ProcessedColumn[] = []
35-
let inputSource = null
36-
37-
data.columns.forEach((column: any) => {
38-
// NOTE: we can tell if its a tile column by its column id
39-
// tiles will either have uuid or ulid as column id
40-
if (ULID_REGEX.test(column.id) || UUID_REGEX.test(column.id)) {
41-
inputSource = FOR_EACH_INPUT_SOURCE.TILES
42-
} else {
43-
inputSource = FOR_EACH_INPUT_SOURCE.M365_EXCEL
34+
if (data.columns.length === 0) {
35+
return {
36+
inputSource: null,
37+
processedColumns: [],
4438
}
39+
}
4540

46-
processedColumns.push({
47-
id: column.id,
48-
name: column.name,
49-
value: `items.rows.${FOR_EACH_ITERATION_KEY}.data.${column.id}`,
50-
})
51-
})
41+
// NOTE: we can tell if its a tile column by its column id
42+
// tiles will either have uuid or ulid as column id
43+
const hasTileColumn = data.columns.every(
44+
(column: any) => ULID_REGEX.test(column.id) || UUID_REGEX.test(column.id),
45+
)
46+
const inputSource = hasTileColumn
47+
? FOR_EACH_INPUT_SOURCE.TILES
48+
: FOR_EACH_INPUT_SOURCE.M365_EXCEL
49+
50+
const processedColumns = data.columns.map((column: any) => ({
51+
id: column.id,
52+
name: column.name,
53+
value: `items.rows.${FOR_EACH_ITERATION_KEY}.data.${column.id}`,
54+
}))
5255

5356
// NOTE: only tiles will have rowId
5457
if (inputSource === FOR_EACH_INPUT_SOURCE.TILES) {

0 commit comments

Comments
 (0)