Skip to content

Commit 9e86485

Browse files
committed
test: cover new logic
1 parent a7b7fd5 commit 9e86485

File tree

3 files changed

+155
-14
lines changed

3 files changed

+155
-14
lines changed

src/notebooks/deepnote/deepnoteNotebookManager.unit.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,83 @@ suite('DeepnoteNotebookManager', () => {
183183
});
184184
});
185185

186+
suite('updateProjectIntegrations', () => {
187+
test('should update integrations list for existing project', () => {
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+
manager.updateProjectIntegrations('project-123', integrations);
196+
197+
const updatedProject = manager.getOriginalProject('project-123');
198+
assert.deepStrictEqual(updatedProject?.project.integrations, integrations);
199+
});
200+
201+
test('should replace existing integrations list', () => {
202+
const projectWithIntegrations: DeepnoteProject = {
203+
...mockProject,
204+
project: {
205+
...mockProject.project,
206+
integrations: [{ id: 'old-int', name: 'Old Integration', type: 'pgsql' }]
207+
}
208+
};
209+
210+
manager.storeOriginalProject('project-123', projectWithIntegrations, 'notebook-456');
211+
212+
const newIntegrations = [
213+
{ id: 'new-int-1', name: 'New Integration 1', type: 'pgsql' },
214+
{ id: 'new-int-2', name: 'New Integration 2', type: 'big-query' }
215+
];
216+
217+
manager.updateProjectIntegrations('project-123', newIntegrations);
218+
219+
const updatedProject = manager.getOriginalProject('project-123');
220+
assert.deepStrictEqual(updatedProject?.project.integrations, newIntegrations);
221+
});
222+
223+
test('should handle empty integrations array', () => {
224+
const projectWithIntegrations: DeepnoteProject = {
225+
...mockProject,
226+
project: {
227+
...mockProject.project,
228+
integrations: [{ id: 'int-1', name: 'Integration 1', type: 'pgsql' }]
229+
}
230+
};
231+
232+
manager.storeOriginalProject('project-123', projectWithIntegrations, 'notebook-456');
233+
234+
manager.updateProjectIntegrations('project-123', []);
235+
236+
const updatedProject = manager.getOriginalProject('project-123');
237+
assert.deepStrictEqual(updatedProject?.project.integrations, []);
238+
});
239+
240+
test('should do nothing for unknown project', () => {
241+
// Should not throw an error
242+
manager.updateProjectIntegrations('unknown-project', [{ id: 'int-1', name: 'Integration', type: 'pgsql' }]);
243+
244+
const project = manager.getOriginalProject('unknown-project');
245+
assert.strictEqual(project, undefined);
246+
});
247+
248+
test('should preserve other project properties', () => {
249+
manager.storeOriginalProject('project-123', mockProject, 'notebook-456');
250+
251+
const integrations = [{ id: 'int-1', name: 'PostgreSQL', type: 'pgsql' }];
252+
253+
manager.updateProjectIntegrations('project-123', integrations);
254+
255+
const updatedProject = manager.getOriginalProject('project-123');
256+
assert.strictEqual(updatedProject?.project.id, mockProject.project.id);
257+
assert.strictEqual(updatedProject?.project.name, mockProject.project.name);
258+
assert.strictEqual(updatedProject?.version, mockProject.version);
259+
assert.deepStrictEqual(updatedProject?.metadata, mockProject.metadata);
260+
});
261+
});
262+
186263
suite('integration scenarios', () => {
187264
test('should handle complete workflow for multiple projects', () => {
188265
manager.storeOriginalProject('project-1', mockProject, 'notebook-1');

src/notebooks/deepnote/sqlCellStatusBarProvider.unit.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,72 @@ suite('SqlCellStatusBarProvider', () => {
701701
assert.isDefined(currentItem, 'Current integration should be in quick pick items');
702702
assert.strictEqual(currentItem.detail, 'Currently selected');
703703
});
704+
705+
test('shows error message when project ID is missing', async () => {
706+
const cell = createMockCell('sql', {}, {}); // No notebook metadata
707+
708+
await switchIntegrationHandler(cell);
709+
710+
verify(mockedVSCodeNamespaces.window.showErrorMessage(anything())).once();
711+
verify(mockedVSCodeNamespaces.window.showQuickPick(anything(), anything())).never();
712+
});
713+
714+
test('shows error message when project is not found', async () => {
715+
const notebookMetadata = { deepnoteProjectId: 'missing-project' };
716+
const cell = createMockCell('sql', {}, notebookMetadata);
717+
718+
when(commandNotebookManager.getOriginalProject('missing-project')).thenReturn(undefined);
719+
720+
await switchIntegrationHandler(cell);
721+
722+
verify(mockedVSCodeNamespaces.window.showErrorMessage(anything())).once();
723+
verify(mockedVSCodeNamespaces.window.showQuickPick(anything(), anything())).never();
724+
});
725+
726+
test('skips DATAFRAME_SQL_INTEGRATION_ID from project integrations list', async () => {
727+
const notebookMetadata = { deepnoteProjectId: 'project-1' };
728+
const cell = createMockCell('sql', {}, notebookMetadata);
729+
let quickPickItems: any[] = [];
730+
731+
when(commandNotebookManager.getOriginalProject('project-1')).thenReturn({
732+
project: {
733+
integrations: [
734+
{
735+
id: DATAFRAME_SQL_INTEGRATION_ID,
736+
name: 'Should be skipped',
737+
type: 'duckdb'
738+
},
739+
{
740+
id: 'postgres-integration',
741+
name: 'PostgreSQL',
742+
type: 'pgsql'
743+
}
744+
]
745+
}
746+
} as any);
747+
when(mockedVSCodeNamespaces.window.showErrorMessage(anything())).thenReturn(Promise.resolve(undefined));
748+
when(mockedVSCodeNamespaces.window.showQuickPick(anything(), anything())).thenCall((items) => {
749+
quickPickItems = items;
750+
return Promise.resolve(undefined);
751+
});
752+
753+
await switchIntegrationHandler(cell);
754+
755+
// Should have 2 items: postgres-integration and DuckDB (added separately)
756+
const projectIntegrationItems = quickPickItems.filter(
757+
(item) => item.id && item.id !== DATAFRAME_SQL_INTEGRATION_ID
758+
);
759+
assert.strictEqual(
760+
projectIntegrationItems.length,
761+
1,
762+
'Should have only 1 project integration (DATAFRAME_SQL_INTEGRATION_ID should be skipped)'
763+
);
764+
assert.strictEqual(projectIntegrationItems[0].id, 'postgres-integration');
765+
766+
// DuckDB should still be in the list (added separately)
767+
const duckDbItem = quickPickItems.find((item) => item.id === DATAFRAME_SQL_INTEGRATION_ID);
768+
assert.isDefined(duckDbItem, 'DuckDB should still be in the list');
769+
});
704770
});
705771

706772
function createMockCell(

src/platform/notebooks/deepnote/integrationTypes.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,25 @@ export enum IntegrationType {
1515
/**
1616
* Map Deepnote integration type strings to our IntegrationType enum
1717
*/
18+
const DEEPNOTE_TO_INTEGRATION_TYPE: Record<string, IntegrationType> = {
19+
pgsql: IntegrationType.Postgres,
20+
'big-query': IntegrationType.BigQuery
21+
};
22+
1823
export function mapDeepnoteIntegrationType(deepnoteType: string): IntegrationType | undefined {
19-
switch (deepnoteType) {
20-
case 'pgsql':
21-
return IntegrationType.Postgres;
22-
case 'big-query':
23-
return IntegrationType.BigQuery;
24-
default:
25-
return undefined;
26-
}
24+
return DEEPNOTE_TO_INTEGRATION_TYPE[deepnoteType];
2725
}
2826

2927
/**
3028
* Map our IntegrationType enum to Deepnote integration type strings
3129
*/
30+
const INTEGRATION_TYPE_TO_DEEPNOTE: Record<IntegrationType, string> = {
31+
[IntegrationType.Postgres]: 'pgsql',
32+
[IntegrationType.BigQuery]: 'big-query'
33+
};
34+
3235
export function mapToDeepnoteIntegrationType(type: IntegrationType): string {
33-
switch (type) {
34-
case IntegrationType.Postgres:
35-
return 'pgsql';
36-
case IntegrationType.BigQuery:
37-
return 'big-query';
38-
}
36+
return INTEGRATION_TYPE_TO_DEEPNOTE[type];
3937
}
4038

4139
/**

0 commit comments

Comments
 (0)