Skip to content

Commit ddf19aa

Browse files
committed
main reverted _synced_at
1 parent 8e93f7b commit ddf19aa

3 files changed

Lines changed: 24 additions & 16 deletions

File tree

packages/destination-google-sheets/__tests__/integration.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ describeWithEnv(
2525
}
2626

2727
function stripUpdatedAt(rows: unknown[][]): unknown[][] {
28-
const idx = rows[0]?.indexOf('_updated_at') ?? -1
29-
return idx < 0 ? rows : rows.map((row) => row.filter((_, i) => i !== idx))
28+
const header = rows[0] ?? []
29+
const indexes = new Set(
30+
['_updated_at', '_synced_at'].map((name) => header.indexOf(name)).filter((idx) => idx >= 0)
31+
)
32+
if (indexes.size === 0) return rows
33+
return rows.map((row) => row.filter((_, i) => !indexes.has(i)))
3034
}
3135

3236
it.skip('writes records to an existing spreadsheet and reads them back', async () => {

packages/destination-google-sheets/src/index.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,19 @@ import {
1818
import { createMemorySheets } from '../__tests__/memory-sheets.js'
1919

2020
/**
21-
* Strip the source-provided `_updated_at` column from a 2D rows array.
21+
* Strip metadata timestamp columns from a 2D rows array.
2222
*
23-
* The source stamps every record with `_updated_at` (unix seconds, from
24-
* `event.created` for webhooks or the HTTP `Date` header for backfill);
25-
* the destination passes the value through verbatim. Most tests don't
26-
* care about its exact value and just want to assert on source data;
27-
* use this helper at the assertion site to drop the column before
28-
* comparing. Tests that exercise the column itself stay in the
29-
* `_updated_at column` describe block at the bottom of this file.
23+
* The destination stamps `_synced_at`; the source may stamp `_updated_at`.
24+
* Most tests only care about source data, so drop both at assertion sites.
3025
*/
3126
function stripUpdatedAt(rows: unknown[][] | undefined): unknown[][] {
3227
if (!rows || rows.length === 0) return rows ?? []
3328
const header = rows[0] as unknown[]
34-
const idx = header.indexOf('_updated_at')
35-
if (idx < 0) return rows
36-
return rows.map((row) => row.filter((_, i) => i !== idx))
29+
const indexes = new Set(
30+
['_updated_at', '_synced_at'].map((name) => header.indexOf(name)).filter((idx) => idx >= 0)
31+
)
32+
if (indexes.size === 0) return rows
33+
return rows.map((row) => row.filter((_, i) => !indexes.has(i)))
3734
}
3835

3936
/** Collect all output from the destination's write() generator. */
@@ -1789,8 +1786,11 @@ describe('_updated_at column (source-owned, passthrough)', () => {
17891786
)
17901787

17911788
const rows = getData(getSpreadsheetIds()[0], 'users')!
1792-
expect(rows[0]).toEqual(['id', 'name'])
1789+
expect(rows[0]).toEqual(['id', 'name', '_synced_at'])
17931790
expect(rows[0]).not.toContain('_updated_at')
1791+
const syncedAtIdx = (rows[0] as string[]).indexOf('_synced_at')
1792+
expect(syncedAtIdx).toBeGreaterThanOrEqual(0)
1793+
expect(Date.parse(String(rows[1][syncedAtIdx]))).not.toBeNaN()
17941794
})
17951795

17961796
it('passes the source-provided _updated_at through verbatim', async () => {

packages/destination-google-sheets/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,12 @@ export function createDestination(
793793
}
794794
}
795795

796-
const headers = await ensureHeadersForRecord(stream, cleanData)
797-
const row = headers.map((header) => stringify(cleanData[header]))
796+
const syncedData: Record<string, unknown> = {
797+
...cleanData,
798+
_synced_at: new Date().toISOString(),
799+
}
800+
const headers = await ensureHeadersForRecord(stream, syncedData)
801+
const row = headers.map((header) => stringify(syncedData[header]))
798802
const rowNumber =
799803
typeof data[ROW_NUMBER_FIELD] === 'number' ? data[ROW_NUMBER_FIELD] : undefined
800804
const primaryKey = primaryKeys.get(stream)

0 commit comments

Comments
 (0)