@@ -183,6 +183,117 @@ suite('DeepnoteNotebookManager', () => {
183183 } ) ;
184184 } ) ;
185185
186+ suite ( 'updateProjectIntegrations' , ( ) => {
187+ test ( 'should update integrations list for existing project and return true' , ( ) => {
188+ manager . storeOriginalProject ( 'project-123' , mockProject , 'notebook-456' ) ;
189+
190+ const integrations = [
191+ { id : 'int-1' , name : 'PostgreSQL' , type : 'pgsql' } ,
192+ { id : 'int-2' , name : 'BigQuery' , type : 'big-query' }
193+ ] ;
194+
195+ const result = manager . updateProjectIntegrations ( 'project-123' , integrations ) ;
196+
197+ assert . strictEqual ( result , true ) ;
198+
199+ const updatedProject = manager . getOriginalProject ( 'project-123' ) ;
200+ assert . deepStrictEqual ( updatedProject ?. project . integrations , integrations ) ;
201+ } ) ;
202+
203+ test ( 'should replace existing integrations list and return true' , ( ) => {
204+ const projectWithIntegrations : DeepnoteProject = {
205+ ...mockProject ,
206+ project : {
207+ ...mockProject . project ,
208+ integrations : [ { id : 'old-int' , name : 'Old Integration' , type : 'pgsql' } ]
209+ }
210+ } ;
211+
212+ manager . storeOriginalProject ( 'project-123' , projectWithIntegrations , 'notebook-456' ) ;
213+
214+ const newIntegrations = [
215+ { id : 'new-int-1' , name : 'New Integration 1' , type : 'pgsql' } ,
216+ { id : 'new-int-2' , name : 'New Integration 2' , type : 'big-query' }
217+ ] ;
218+
219+ const result = manager . updateProjectIntegrations ( 'project-123' , newIntegrations ) ;
220+
221+ assert . strictEqual ( result , true ) ;
222+
223+ const updatedProject = manager . getOriginalProject ( 'project-123' ) ;
224+ assert . deepStrictEqual ( updatedProject ?. project . integrations , newIntegrations ) ;
225+ } ) ;
226+
227+ test ( 'should handle empty integrations array and return true' , ( ) => {
228+ const projectWithIntegrations : DeepnoteProject = {
229+ ...mockProject ,
230+ project : {
231+ ...mockProject . project ,
232+ integrations : [ { id : 'int-1' , name : 'Integration 1' , type : 'pgsql' } ]
233+ }
234+ } ;
235+
236+ manager . storeOriginalProject ( 'project-123' , projectWithIntegrations , 'notebook-456' ) ;
237+
238+ const result = manager . updateProjectIntegrations ( 'project-123' , [ ] ) ;
239+
240+ assert . strictEqual ( result , true ) ;
241+
242+ const updatedProject = manager . getOriginalProject ( 'project-123' ) ;
243+ assert . deepStrictEqual ( updatedProject ?. project . integrations , [ ] ) ;
244+ } ) ;
245+
246+ test ( 'should return false for unknown project' , ( ) => {
247+ const result = manager . updateProjectIntegrations ( 'unknown-project' , [
248+ { id : 'int-1' , name : 'Integration' , type : 'pgsql' }
249+ ] ) ;
250+
251+ assert . strictEqual ( result , false ) ;
252+
253+ const project = manager . getOriginalProject ( 'unknown-project' ) ;
254+ assert . strictEqual ( project , undefined ) ;
255+ } ) ;
256+
257+ test ( 'should preserve other project properties and return true' , ( ) => {
258+ manager . storeOriginalProject ( 'project-123' , mockProject , 'notebook-456' ) ;
259+
260+ const integrations = [ { id : 'int-1' , name : 'PostgreSQL' , type : 'pgsql' } ] ;
261+
262+ const result = manager . updateProjectIntegrations ( 'project-123' , integrations ) ;
263+
264+ assert . strictEqual ( result , true ) ;
265+
266+ const updatedProject = manager . getOriginalProject ( 'project-123' ) ;
267+ assert . strictEqual ( updatedProject ?. project . id , mockProject . project . id ) ;
268+ assert . strictEqual ( updatedProject ?. project . name , mockProject . project . name ) ;
269+ assert . strictEqual ( updatedProject ?. version , mockProject . version ) ;
270+ assert . deepStrictEqual ( updatedProject ?. metadata , mockProject . metadata ) ;
271+ } ) ;
272+
273+ test ( 'should update integrations when currentNotebookId is undefined and return true' , ( ) => {
274+ // Store project with a notebook ID, then clear it to simulate the edge case
275+ manager . storeOriginalProject ( 'project-123' , mockProject , 'notebook-456' ) ;
276+ manager . updateCurrentNotebookId ( 'project-123' , undefined as any ) ;
277+
278+ const integrations = [
279+ { id : 'int-1' , name : 'PostgreSQL' , type : 'pgsql' } ,
280+ { id : 'int-2' , name : 'BigQuery' , type : 'big-query' }
281+ ] ;
282+
283+ const result = manager . updateProjectIntegrations ( 'project-123' , integrations ) ;
284+
285+ assert . strictEqual ( result , true ) ;
286+
287+ const updatedProject = manager . getOriginalProject ( 'project-123' ) ;
288+ assert . deepStrictEqual ( updatedProject ?. project . integrations , integrations ) ;
289+ // Verify other properties remain unchanged
290+ assert . strictEqual ( updatedProject ?. project . id , mockProject . project . id ) ;
291+ assert . strictEqual ( updatedProject ?. project . name , mockProject . project . name ) ;
292+ assert . strictEqual ( updatedProject ?. version , mockProject . version ) ;
293+ assert . deepStrictEqual ( updatedProject ?. metadata , mockProject . metadata ) ;
294+ } ) ;
295+ } ) ;
296+
186297 suite ( 'integration scenarios' , ( ) => {
187298 test ( 'should handle complete workflow for multiple projects' , ( ) => {
188299 manager . storeOriginalProject ( 'project-1' , mockProject , 'notebook-1' ) ;
0 commit comments