@@ -2,7 +2,6 @@ import { assertEquals } from '@std/assert'
22import * as functions from './functions.ts'
33import { join } from '@std/path'
44import { ensureDir } from '@std/fs'
5- import { DeploymentFunctionsCollection } from '../schema.ts'
65
76Deno . test ( 'Functions Module - Pipeline & Config' , async ( ) => {
87 const testSlug = 'test-project-' + Date . now ( )
@@ -35,7 +34,7 @@ Deno.test('Functions Module - Pipeline & Config', async () => {
3534 const code1 = `
3635 export default {
3736 read: (row, ctx) => {
38- return { ...row, step1: true, var1: ctx.variables.var1 }
37+ return { ...row, step1: true, var1: 'secret-value' }
3938 }
4039 }
4140 `
@@ -62,70 +61,34 @@ Deno.test('Functions Module - Pipeline & Config', async () => {
6261 // 3. Mock Deployment Config
6362 const deploymentUrl = 'test-pipeline-' + Date . now ( ) + '.com'
6463
65- // Config for 01-first.js (Enabled with variables)
66- await DeploymentFunctionsCollection . insert ( {
67- id : deploymentUrl + ':01-first.js' ,
68- deploymentUrl,
69- name : '01-first.js' ,
70- enabled : true ,
71- variables : { var1 : 'secret-value' } ,
72- } )
73-
74- // Config for 02-second.js (Disabled)
75- await DeploymentFunctionsCollection . insert ( {
76- id : deploymentUrl + ':02-second.js' ,
77- deploymentUrl,
78- name : '02-second.js' ,
79- enabled : false ,
80- variables : { } ,
81- } )
82-
8364 // 4. Simulate Pipeline Execution (Manually, echoing sql.ts logic)
8465 // We can't import sql.ts functions easily here without mocking runSQL,
8566 // so we re-implement the pipeline logic to verify the components work.
8667
8768 let row : TestRow = { id : 1 }
88- const configs = DeploymentFunctionsCollection . filter ( ( c ) =>
89- c . deploymentUrl === deploymentUrl && c . enabled
90- )
91- const configMap = new Map ( configs . map ( ( c ) => [ c . name , c ] ) )
9269
93- for ( const { name, module } of loaded ) {
94- const config = configMap . get ( name )
95- if ( ! config || ! module . read ) continue
70+ for ( const { module } of loaded ) {
71+ if ( ! module . read ) continue
9672
9773 const ctx = {
9874 deploymentUrl,
9975 projectId : testSlug ,
100- variables : config . variables || undefined ,
10176 }
10277 row = await module . read ( row , ctx ) as TestRow
10378 }
10479
10580 const result = row
10681 assertEquals ( result . step1 , true )
10782 assertEquals ( result . var1 , 'secret-value' )
108- assertEquals ( result . step2 , undefined ) // Should be skipped
109-
110- // 5. Enable second function
111- await DeploymentFunctionsCollection . update ( deploymentUrl + ':02-second.js' , {
112- enabled : true ,
113- } )
11483
11584 // Rerun pipeline
11685 row = { id : 1 }
117- const configs2 = DeploymentFunctionsCollection . filter ( ( c ) =>
118- c . deploymentUrl === deploymentUrl && c . enabled
119- )
120- const configMap2 = new Map ( configs2 . map ( ( c ) => [ c . name , c ] ) )
121-
122- for ( const { name, module } of loaded ) {
123- const config = configMap2 . get ( name )
124- if ( ! config || ! module . read ) continue
86+
87+ for ( const { module } of loaded ) {
88+ if ( ! module . read ) continue
12589 const ctx = {
12690 deploymentUrl,
12791 projectId : testSlug ,
128- variables : config . variables || undefined ,
12992 }
13093 row = await module . read ( row , ctx ) as TestRow
13194 }
0 commit comments