Skip to content

Commit cb4ce97

Browse files
committed
chore: update test name, refactor column processing
1 parent 4256646 commit cb4ce97

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
@@ -38,24 +38,27 @@ function processColumns(data: MultipleRowObject): {
3838
inputSource: InputSource
3939
processedColumns: ProcessedColumn[]
4040
} {
41-
const processedColumns: ProcessedColumn[] = []
42-
let inputSource = null
43-
44-
data.columns.forEach((column: any) => {
45-
// NOTE: we can tell if its a tile column by its column id
46-
// tiles will either have uuid or ulid as column id
47-
if (ULID_REGEX.test(column.id) || UUID_REGEX.test(column.id)) {
48-
inputSource = FOR_EACH_INPUT_SOURCE.TILES
49-
} else {
50-
inputSource = FOR_EACH_INPUT_SOURCE.M365_EXCEL
41+
if (data.columns.length === 0) {
42+
return {
43+
inputSource: null,
44+
processedColumns: [],
5145
}
46+
}
5247

53-
processedColumns.push({
54-
id: column.id,
55-
name: column.name,
56-
value: `items.rows.${FOR_EACH_ITERATION_KEY}.data.${column.id}`,
57-
})
58-
})
48+
// NOTE: we can tell if its a tile column by its column id
49+
// tiles will either have uuid or ulid as column id
50+
const hasTileColumn = data.columns.every(
51+
(column: any) => ULID_REGEX.test(column.id) || UUID_REGEX.test(column.id),
52+
)
53+
const inputSource = hasTileColumn
54+
? FOR_EACH_INPUT_SOURCE.TILES
55+
: FOR_EACH_INPUT_SOURCE.M365_EXCEL
56+
57+
const processedColumns = data.columns.map((column: any) => ({
58+
id: column.id,
59+
name: column.name,
60+
value: `items.rows.${FOR_EACH_ITERATION_KEY}.data.${column.id}`,
61+
}))
5962

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

0 commit comments

Comments
 (0)