Skip to content

Commit 40e3671

Browse files
authored
chore: use switch-exhaustiveness-check, add updatemany to fixtures (#6819)
use switch-exhaustiveness-check, add updatemanu to fixtures
1 parent 53e5363 commit 40e3671

File tree

7 files changed

+82
-26
lines changed

7 files changed

+82
-26
lines changed

packages/compass-saved-aggregations-queries/.eslintrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ module.exports = {
66
tsconfigRootDir: __dirname,
77
project: ['./tsconfig-lint.json'],
88
},
9+
overrides: [
10+
{
11+
files: ['**/*.ts'],
12+
rules: {
13+
'@typescript-eslint/switch-exhaustiveness-check': 'error',
14+
},
15+
},
16+
],
917
};

packages/compass-saved-aggregations-queries/src/hooks/use-grid-filters.spec.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('use-grid-header', function () {
8383
result.current.search
8484
)
8585
).result.current.map((x) => x.item);
86-
expect(gridItems).to.have.length(4);
86+
expect(gridItems).to.have.length(5);
8787
});
8888

8989
it('should filter items by search text - collection name', function () {
@@ -113,7 +113,7 @@ describe('use-grid-header', function () {
113113
result.current.search
114114
)
115115
).result.current.map((x) => x.item);
116-
expect(gridItems).to.have.length(4);
116+
expect(gridItems).to.have.length(5);
117117
});
118118

119119
it('should not filter items by search text - sort key (num_of_host_spaces)', function () {

packages/compass-saved-aggregations-queries/src/index.spec.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function getConnection() {
4141
};
4242
}
4343

44-
describe('AggregationsQueriesList', function () {
44+
describe('AggregationsAndQueriesAndUpdatemanyList', function () {
4545
const sandbox = Sinon.createSandbox();
4646
const query = {
4747
_id: '123',
@@ -51,6 +51,14 @@ describe('AggregationsQueriesList', function () {
5151
filter: { foo: 'bar' },
5252
sort: { bar: -1 },
5353
} as any;
54+
const updatemany = {
55+
_id: '5667',
56+
_name: 'Updatemany',
57+
_ns: 'bar.baz',
58+
_dateSaved: new Date(),
59+
filter: { foo: 'baz' },
60+
sort: { baz: -1 },
61+
} as any;
5462
const aggregation = {
5563
id: '123',
5664
name: 'Aggregation',
@@ -153,7 +161,7 @@ describe('AggregationsQueriesList', function () {
153161
});
154162

155163
it('should load queries and display them in the list', async function () {
156-
sandbox.stub(queryStorage, 'loadAll').resolves([query]);
164+
sandbox.stub(queryStorage, 'loadAll').resolves([query, updatemany]);
157165
renderPlugin();
158166
expect(await screen.findByText('Query')).to.exist;
159167
await waitFor(() => expect(screen.findByText(query._name)).to.exist);
@@ -168,7 +176,7 @@ describe('AggregationsQueriesList', function () {
168176

169177
describe('copy to clipboard', function () {
170178
it('should copy query to the clipboard', async function () {
171-
sandbox.stub(queryStorage, 'loadAll').resolves([query]);
179+
sandbox.stub(queryStorage, 'loadAll').resolves([query, updatemany]);
172180
renderPlugin();
173181
expect(await screen.findByText(query._name)).to.exist;
174182

@@ -386,7 +394,7 @@ describe('AggregationsQueriesList', function () {
386394
};
387395

388396
beforeEach(function () {
389-
sandbox.stub(queryStorage, 'loadAll').resolves([query]);
397+
sandbox.stub(queryStorage, 'loadAll').resolves([query, updatemany]);
390398
});
391399

392400
context('when not connected to any connection', function () {

packages/compass-saved-aggregations-queries/src/stores/delete-item.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ export const confirmDeleteItem = (
5555
undefined // this event is connection scoped when triggered from the aggregation or query screen
5656
);
5757

58-
if (item.type === 'aggregation') {
59-
await pipelineStorage?.delete(item.id);
60-
} else {
61-
// query or updatemany
62-
await queryStorage?.delete(item.id);
58+
switch (item.type) {
59+
case 'aggregation':
60+
await pipelineStorage?.delete(item.id);
61+
break;
62+
case 'query':
63+
case 'updatemany':
64+
await queryStorage?.delete(item.id);
65+
break;
6366
}
6467

6568
dispatch({ type: ActionTypes.DeleteItemConfirm, id: item.id });

packages/compass-saved-aggregations-queries/src/stores/edit-item.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,17 @@ export const updateItem =
8787
return;
8888
}
8989

90-
if (item.type === 'aggregation') {
91-
await pipelineStorage?.updateAttributes(id, attributes);
92-
} else {
93-
// query or updatemany
94-
await queryStorage?.updateAttributes(id, {
95-
_name: attributes.name,
96-
_dateModified: new Date(),
97-
});
90+
switch (item.type) {
91+
case 'aggregation':
92+
await pipelineStorage?.updateAttributes(id, attributes);
93+
break;
94+
case 'query':
95+
case 'updatemany':
96+
await queryStorage?.updateAttributes(id, {
97+
_name: attributes.name,
98+
_dateModified: new Date(),
99+
});
100+
break;
98101
}
99102

100103
dispatch({

packages/compass-saved-aggregations-queries/src/stores/open-item.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,16 @@ export const openSelectedItem =
568568
const id = selectedItem.id;
569569
const newNamespace = `${selectedDatabase}.${selectedCollection}`;
570570

571-
if (selectedItem.type === 'aggregation') {
572-
await pipelineStorage?.updateAttributes(id, {
573-
namespace: newNamespace,
574-
});
575-
} else {
576-
// query or updatemany
577-
await queryStorage?.updateAttributes(id, { _ns: newNamespace });
571+
switch (selectedItem.type) {
572+
case 'aggregation':
573+
await pipelineStorage?.updateAttributes(id, {
574+
namespace: newNamespace,
575+
});
576+
break;
577+
case 'query':
578+
case 'updatemany':
579+
await queryStorage?.updateAttributes(id, { _ns: newNamespace });
580+
break;
578581
}
579582
}
580583

packages/compass-saved-aggregations-queries/test/fixtures.ts

+31
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,37 @@ export const queries = [
9797
},
9898
},
9999
},
100+
{
101+
id: '9999',
102+
name: 'update some things',
103+
database: 'airbnb',
104+
collection: 'hosts',
105+
lastModified: 13,
106+
type: 'updatemany' as const,
107+
query: {
108+
_id: '9012',
109+
_name: 'update some things',
110+
_ns: 'airbnb.hosts',
111+
_dateSaved: DATE,
112+
_dateModified: DATE,
113+
_lastExecuted: DATE,
114+
filter: {
115+
host_location: RegExp('berlin'),
116+
},
117+
project: {
118+
id: 1,
119+
name: 1,
120+
},
121+
sort: {
122+
reviews: -1,
123+
},
124+
skip: 0,
125+
limit: 10,
126+
collation: {
127+
locale: 'simple',
128+
},
129+
},
130+
},
100131
];
101132

102133
export const pipelines = [

0 commit comments

Comments
 (0)