Skip to content

Commit 860bbae

Browse files
committed
tests
1 parent f57e87c commit 860bbae

File tree

17 files changed

+152
-80
lines changed

17 files changed

+152
-80
lines changed

packages/compass-aggregations/src/components/pipeline-toolbar/index.spec.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { expect } from 'chai';
99
import { renderWithStore } from '../../../test/configure-store';
1010
import { PipelineToolbar } from './index';
11-
import { CompassPipelineStorage } from '@mongodb-js/my-queries-storage';
11+
import { createElectronPipelineStorage } from '@mongodb-js/my-queries-storage/electron';
1212

1313
describe('PipelineToolbar', function () {
1414
describe('renders with setting row - visible', function () {
@@ -23,7 +23,12 @@ describe('PipelineToolbar', function () {
2323
/>,
2424
{ pipeline: [{ $match: { _id: 1 } }] },
2525
undefined,
26-
{ pipelineStorage: { getStorage: () => new CompassPipelineStorage() } }
26+
{
27+
pipelineStorage: {
28+
getStorage: () =>
29+
createElectronPipelineStorage({ basepath: '/tmp/test' }),
30+
},
31+
}
2732
);
2833
toolbar = screen.getByTestId('pipeline-toolbar');
2934
});

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-header/index.spec.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { spy } from 'sinon';
55
import type { SinonSpy } from 'sinon';
66
import { renderWithStore } from '../../../../test/configure-store';
77
import { PipelineHeader } from '.';
8-
import { CompassPipelineStorage } from '@mongodb-js/my-queries-storage';
8+
import { createElectronPipelineStorage } from '@mongodb-js/my-queries-storage/electron';
99

1010
describe('PipelineHeader', function () {
1111
let container: HTMLElement;
@@ -23,7 +23,12 @@ describe('PipelineHeader', function () {
2323
/>,
2424
undefined,
2525
undefined,
26-
{ pipelineStorage: { getStorage: () => new CompassPipelineStorage() } }
26+
{
27+
pipelineStorage: {
28+
getStorage: () =>
29+
createElectronPipelineStorage({ basepath: '/tmp/test' }),
30+
},
31+
}
2732
);
2833
container = screen.getByTestId('pipeline-header');
2934
});

packages/compass-aggregations/src/modules/pipeline-builder/stage-editor.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from './stage-editor';
2222
import type { StageEditorState, StoreStage, Wizard } from './stage-editor';
2323
import reducer from '../';
24-
import { CompassPipelineStorage } from '@mongodb-js/my-queries-storage';
24+
import { createElectronPipelineStorage } from '@mongodb-js/my-queries-storage/electron';
2525
import Sinon from 'sinon';
2626
import type Stage from './stage';
2727
import { mockDataService } from '../../../test/mocks/data-service';
@@ -130,7 +130,9 @@ function createStore({
130130
localAppRegistry: new AppRegistry(),
131131
atlasAiService: {} as any,
132132
pipelineBuilder,
133-
pipelineStorage: new CompassPipelineStorage(),
133+
pipelineStorage: createElectronPipelineStorage({
134+
basepath: '/tmp/test',
135+
}),
134136
instance: {} as any,
135137
workspaces: {} as any,
136138
preferences,

packages/compass-aggregations/src/modules/pipeline-builder/text-editor-pipeline.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { PipelineBuilderThunkDispatch } from '..';
1010
import reducer from '..';
1111
import Sinon from 'sinon';
1212
import { toggleAutoPreview } from '../auto-preview';
13-
import { CompassPipelineStorage } from '@mongodb-js/my-queries-storage';
13+
import { createElectronPipelineStorage } from '@mongodb-js/my-queries-storage/electron';
1414
import { mockDataService } from '../../../test/mocks/data-service';
1515

1616
function createStore(
@@ -46,7 +46,9 @@ function createStore(
4646
thunk.withExtraArgument({
4747
atlasAiService: {} as any,
4848
pipelineBuilder,
49-
pipelineStorage: new CompassPipelineStorage(),
49+
pipelineStorage: createElectronPipelineStorage({
50+
basepath: '/tmp/test',
51+
}),
5052
instance: {} as any,
5153
workspaces: {} as any,
5254
preferences: {

packages/compass-preferences-model/src/react.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,3 @@ export function withPreferences<
126126
return createElement(component, { ...prefs, ...props });
127127
};
128128
}
129-
130-
/**
131-
* Hook to check if the My Queries Data Explorer feature is enabled.
132-
* This controls access to:
133-
* - Saved queries and aggregations
134-
* - Recent queries autocomplete
135-
* - Favorite queries/aggregations
136-
*/
137-
export function useMyQueriesFeature(): boolean {
138-
const enableMyQueries = usePreference('enableMyQueries');
139-
140-
// Default to true to match the preference schema default
141-
return enableMyQueries ?? true;
142-
}

packages/compass-query-bar/src/components/query-bar.spec.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import {
2727
RecentQueryStorageProvider,
2828
} from '@mongodb-js/my-queries-storage/provider';
2929
import {
30-
compassFavoriteQueryStorageAccess,
31-
compassRecentQueryStorageAccess,
32-
} from '@mongodb-js/my-queries-storage';
30+
createElectronFavoriteQueryStorage,
31+
createElectronRecentQueryStorage,
32+
} from '@mongodb-js/my-queries-storage/electron';
3333
import { createNoopTrack } from '@mongodb-js/compass-telemetry/provider';
3434

3535
const noop = () => {
@@ -67,10 +67,19 @@ describe('QueryBar Component', function () {
6767
} as QueryBarExtraArgs);
6868
store.dispatch(toggleQueryOptions(expanded));
6969

70+
const favoriteQueryStorage = {
71+
getStorage: () =>
72+
createElectronFavoriteQueryStorage({ basepath: '/tmp/test' }),
73+
};
74+
const recentQueryStorage = {
75+
getStorage: () =>
76+
createElectronRecentQueryStorage({ basepath: '/tmp/test' }),
77+
};
78+
7079
const component = (
7180
<PreferencesProvider value={preferences}>
72-
<FavoriteQueryStorageProvider value={compassFavoriteQueryStorageAccess}>
73-
<RecentQueryStorageProvider value={compassRecentQueryStorageAccess}>
81+
<FavoriteQueryStorageProvider value={favoriteQueryStorage}>
82+
<RecentQueryStorageProvider value={recentQueryStorage}>
7483
<Provider store={store}>
7584
<QueryBar
7685
source="test"

packages/compass-query-bar/src/components/query-history/index.spec.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ import os from 'os';
1414
import path from 'path';
1515
import QueryHistory from '.';
1616
import {
17-
CompassFavoriteQueryStorage,
18-
CompassRecentQueryStorage,
17+
createElectronFavoriteQueryStorage,
18+
createElectronRecentQueryStorage,
19+
} from '@mongodb-js/my-queries-storage/electron';
20+
import {
21+
FavoriteQueryStorageProvider,
22+
RecentQueryStorageProvider,
1923
} from '@mongodb-js/my-queries-storage';
2024
import { fetchRecents, fetchFavorites } from '../../stores/query-bar-reducer';
2125
import { configureStore } from '../../stores/query-bar-store';
@@ -47,8 +51,8 @@ const FAVORITE_QUERY = {
4751
};
4852

4953
function createStore(basepath: string) {
50-
const favoriteQueryStorage = new CompassFavoriteQueryStorage({ basepath });
51-
const recentQueryStorage = new CompassRecentQueryStorage({ basepath });
54+
const favoriteQueryStorage = createElectronFavoriteQueryStorage({ basepath });
55+
const recentQueryStorage = createElectronRecentQueryStorage({ basepath });
5256

5357
const store = configureStore(
5458
{
@@ -79,13 +83,25 @@ function createStore(basepath: string) {
7983

8084
const renderQueryHistory = (basepath: string) => {
8185
const data = createStore(basepath);
86+
87+
const favoriteQueryStorage = {
88+
getStorage: () => data.favoriteQueryStorage,
89+
};
90+
const recentQueryStorage = {
91+
getStorage: () => data.recentQueryStorage,
92+
};
93+
8294
render(
83-
<Provider store={data.store}>
84-
<QueryHistory
85-
onUpdateRecentChoosen={() => {}}
86-
onUpdateFavoriteChoosen={() => {}}
87-
/>
88-
</Provider>
95+
<FavoriteQueryStorageProvider value={favoriteQueryStorage}>
96+
<RecentQueryStorageProvider value={recentQueryStorage}>
97+
<Provider store={data.store}>
98+
<QueryHistory
99+
onUpdateRecentChoosen={() => {}}
100+
onUpdateFavoriteChoosen={() => {}}
101+
/>
102+
</Provider>
103+
</RecentQueryStorageProvider>
104+
</FavoriteQueryStorageProvider>
89105
);
90106
return data;
91107
};

packages/compass-schema/src/components/field.spec.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import { BSON, Decimal128 } from 'bson';
1616
import Field, { shouldShowUnboundArrayInsight } from './field';
1717
import QueryBarPlugin from '@mongodb-js/compass-query-bar';
1818
import {
19-
compassFavoriteQueryStorageAccess,
20-
compassRecentQueryStorageAccess,
21-
} from '@mongodb-js/my-queries-storage';
19+
createElectronFavoriteQueryStorage,
20+
createElectronRecentQueryStorage,
21+
} from '@mongodb-js/my-queries-storage/electron';
2222

2323
const MockQueryBarPlugin = QueryBarPlugin.withMockServices({
2424
dataService: {
@@ -30,8 +30,14 @@ const MockQueryBarPlugin = QueryBarPlugin.withMockServices({
3030
},
3131
},
3232
instance: { on() {}, removeListener() {} } as any,
33-
favoriteQueryStorageAccess: compassFavoriteQueryStorageAccess,
34-
recentQueryStorageAccess: compassRecentQueryStorageAccess,
33+
favoriteQueryStorageAccess: {
34+
getStorage: () =>
35+
createElectronFavoriteQueryStorage({ basepath: '/tmp/test' }),
36+
},
37+
recentQueryStorageAccess: {
38+
getStorage: () =>
39+
createElectronRecentQueryStorage({ basepath: '/tmp/test' }),
40+
},
3541
atlasAiService: {} as any,
3642
});
3743

packages/compass-schema/src/components/schema-toolbar.spec.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import type { AllPreferences } from 'compass-preferences-model';
77
import { SchemaToolbar } from './schema-toolbar';
88
import QueryBarPlugin from '@mongodb-js/compass-query-bar';
99
import {
10-
compassFavoriteQueryStorageAccess,
11-
compassRecentQueryStorageAccess,
12-
} from '@mongodb-js/my-queries-storage';
10+
createElectronFavoriteQueryStorage,
11+
createElectronRecentQueryStorage,
12+
} from '@mongodb-js/my-queries-storage/electron';
1313

1414
const MockQueryBarPlugin = QueryBarPlugin.withMockServices({
1515
dataService: {
@@ -21,8 +21,14 @@ const MockQueryBarPlugin = QueryBarPlugin.withMockServices({
2121
},
2222
},
2323
instance: { on() {}, removeListener() {} } as any,
24-
favoriteQueryStorageAccess: compassFavoriteQueryStorageAccess,
25-
recentQueryStorageAccess: compassRecentQueryStorageAccess,
24+
favoriteQueryStorageAccess: {
25+
getStorage: () =>
26+
createElectronFavoriteQueryStorage({ basepath: '/tmp/test' }),
27+
},
28+
recentQueryStorageAccess: {
29+
getStorage: () =>
30+
createElectronRecentQueryStorage({ basepath: '/tmp/test' }),
31+
},
2632
atlasAiService: {} as any,
2733
});
2834

packages/compass-user-data/src/user-data.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,12 +702,16 @@ describe('AtlasUserData', function () {
702702
expect(putOptions.headers['Content-Type']).to.equal('application/json');
703703
});
704704

705-
it('returns false when authenticatedFetch does not return 200', async function () {
705+
it('returns false when authenticatedFetch throws an error', async function () {
706706
const getResponse = {
707707
data: JSON.stringify({ name: 'Original Name', hasDarkMode: true }),
708708
};
709709

710-
authenticatedFetchStub.resolves(mockResponse(getResponse, false, 400));
710+
authenticatedFetchStub
711+
.onFirstCall()
712+
.resolves(mockResponse(getResponse))
713+
.onSecondCall()
714+
.rejects(new Error('HTTP 400: Bad Request'));
711715

712716
getResourceUrlStub.returns(
713717
'cluster-connection.cloud.mongodb.com/favoriteQueries/test-org/test-proj/test-id'

0 commit comments

Comments
 (0)