@@ -18,22 +18,19 @@ import {
1818import { 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 */
3126function 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 ( ) => {
0 commit comments