Skip to content

Commit 3709b00

Browse files
committed
update tests
1 parent 9da1f6b commit 3709b00

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

packages/compass-global-writes/src/services/atlas-global-writes-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type ReplicationItem = {
3737
zoneId: string;
3838
zoneName: string;
3939
};
40-
type ClusterDetailsApiResponse = {
40+
export type ClusterDetailsApiResponse = {
4141
geoSharding: GeoShardingData;
4242
replicationSpecList: ReplicationItem[];
4343
};

packages/compass-global-writes/src/store/index.spec.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@ import {
77
type CreateShardKeyData,
88
} from './reducer';
99
import sinon from 'sinon';
10+
import type { ClusterDetailsApiResponse } from '../services/atlas-global-writes-service';
1011

1112
const DB = 'test';
1213
const COLL = 'coll';
1314
const NS = `${DB}.${COLL}`;
1415

15-
function createJsonResponse(data: any) {
16+
const clusterDetails: ClusterDetailsApiResponse = {
17+
geoSharding: {
18+
customZoneMapping: {},
19+
managedNamespaces: [],
20+
selfManagedSharding: false,
21+
},
22+
replicationSpecList: [],
23+
};
24+
25+
function createClusterDetailsResponse(data: ClusterDetailsApiResponse) {
1626
return {
1727
json: () => Promise.resolve(data),
1828
};
@@ -41,13 +51,11 @@ describe('GlobalWritesStore Store', function () {
4151
it('when the namespace is not managed', async function () {
4252
const store = createStore({
4353
authenticatedFetch: () =>
44-
createJsonResponse({
45-
geoSharding: { customZoneMapping: {}, managedNamespaces: [] },
46-
}),
54+
createClusterDetailsResponse(clusterDetails),
4755
});
4856
await store.dispatch(fetchClusterShardingData());
4957
expect(store.getState().status).to.equal('UNSHARDED');
50-
expect(store.getState().isNamespaceSharded).to.equal(false);
58+
expect(store.getState().managedNamespace).to.equal(undefined);
5159
});
5260

5361
// TODO (COMPASS-8277): Add more test for fetching shard key and process errors
@@ -65,9 +73,7 @@ describe('GlobalWritesStore Store', function () {
6573
it('sets SUBMITTING_FOR_SHARDING state when starting to create shard key and sets to SHARDING on success', async function () {
6674
const store = createStore({
6775
authenticatedFetch: () =>
68-
createJsonResponse({
69-
geoSharding: { customZoneMapping: {}, managedNamespaces: [] },
70-
}),
76+
createClusterDetailsResponse(clusterDetails),
7177
});
7278

7379
const promise = store.dispatch(createShardKey(shardKeyData));
@@ -102,9 +108,10 @@ describe('GlobalWritesStore Store', function () {
102108
},
103109
];
104110

105-
const getClusterInfoApiResponse = createJsonResponse({
111+
const getClusterInfoApiResponse = createClusterDetailsResponse({
112+
...clusterDetails,
106113
geoSharding: {
107-
customZoneMapping: {},
114+
...clusterDetails.geoSharding,
108115
managedNamespaces: alreadyManagedNamespaces,
109116
},
110117
});
@@ -137,6 +144,7 @@ describe('GlobalWritesStore Store', function () {
137144
...alreadyManagedNamespaces,
138145
{ ...shardKeyData, db: DB, collection: COLL },
139146
],
147+
selfManagedSharding: false,
140148
});
141149
});
142150
});

packages/compass-global-writes/tests/create-store.tsx

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@ import { activateGlobalWritesPlugin } from '../src/store';
77
import { createActivateHelpers } from 'hadron-app-registry';
88
import { createNoopLogger } from '@mongodb-js/compass-logging/provider';
99
import { createNoopTrack } from '@mongodb-js/compass-telemetry/provider';
10-
import type {
11-
ConnectionInfo,
12-
ConnectionInfoRef,
13-
} from '@mongodb-js/compass-connections/provider';
10+
import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider';
1411
import type { AtlasService } from '@mongodb-js/atlas-service/provider';
1512
import { Provider } from 'react-redux';
1613
import { renderWithActiveConnection } from '@mongodb-js/testing-library-compass';
1714

1815
import clusterApiResponse from './cluster-api-response.json';
1916

17+
const TEST_CONNECTION_INFO = {
18+
id: 'TEST',
19+
connectionOptions: {
20+
connectionString: 'mongodb://localhost',
21+
},
22+
atlasMetadata: {
23+
clusterName: 'Cluster0',
24+
clusterType: 'UNSHARDED',
25+
projectId: 'Project0',
26+
} as unknown as ConnectionInfo['atlasMetadata'],
27+
};
28+
2029
const atlasService = {
2130
cloudEndpoint: (p: string) => {
2231
return `https://example.com/${p}`;
@@ -39,19 +48,9 @@ const atlasService = {
3948

4049
export const setupStore = (
4150
options: Partial<GlobalWritesPluginOptions> = {},
42-
services: Partial<GlobalWritesPluginServices> = {}
51+
services: Partial<GlobalWritesPluginServices> = {},
52+
connectionInfo: ConnectionInfo = TEST_CONNECTION_INFO
4353
) => {
44-
const connectionInfoRef = {
45-
current: {
46-
id: 'TEST',
47-
atlasMetadata: {
48-
clusterName: 'Cluster0',
49-
clusterType: 'GEOSHARDED',
50-
projectId: 'Project0',
51-
},
52-
},
53-
} as ConnectionInfoRef;
54-
5554
return activateGlobalWritesPlugin(
5655
{
5756
namespace: 'airbnb.listings',
@@ -60,7 +59,12 @@ export const setupStore = (
6059
{
6160
logger: createNoopLogger('TEST'),
6261
track: createNoopTrack(),
63-
connectionInfoRef,
62+
connectionInfoRef: {
63+
current: {
64+
...connectionInfo,
65+
title: 'My connection',
66+
},
67+
},
6468
...services,
6569
atlasService: {
6670
...atlasService,
@@ -76,19 +80,14 @@ export const renderWithStore = (
7680
{
7781
services = {},
7882
options = {},
79-
connectionInfo = {
80-
id: 'testConnection',
81-
connectionOptions: {
82-
connectionString: 'mongodb://localhost',
83-
},
84-
},
83+
connectionInfo = TEST_CONNECTION_INFO,
8584
}: {
8685
services?: Partial<GlobalWritesPluginServices>;
8786
options?: Partial<GlobalWritesPluginOptions>;
8887
connectionInfo?: ConnectionInfo;
8988
} = {}
9089
) => {
91-
const store = setupStore(options, services);
90+
const store = setupStore(options, services, connectionInfo);
9291
return renderWithActiveConnection(
9392
<Provider store={store}>{component}</Provider>,
9493
connectionInfo

0 commit comments

Comments
 (0)