Skip to content

Commit

Permalink
fix: fix listCollections rule/improve tests (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
viladimiru authored Dec 28, 2024
1 parent 0f5f081 commit 7ba9e71
Show file tree
Hide file tree
Showing 12 changed files with 1,586 additions and 858 deletions.

Large diffs are not rendered by default.

1,715 changes: 861 additions & 854 deletions src/autocomplete/databases/mongo/generated/MongoParser.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/autocomplete/databases/mongo/grammar/MongoParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ databaseRenameCollectionArgument3

databaseListCollectionsMethod
: LIST_COLLECTIONS LPAREN (
databaseListCollectionsArgument1 (COMMA databaseListCollectionsArgument2)
databaseListCollectionsArgument1 (COMMA databaseListCollectionsArgument2)?
)? RPAREN
;

Expand Down
22 changes: 20 additions & 2 deletions src/autocomplete/databases/mongo/tests/admin/admin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test('should not report errors on admin statements', () => {

test('should not report errors on extended admin statements', () => {
const autocompleteResult = parseMongoQueryWithoutCursor(`
db.admin().command({ping: 1});
db.admin().command(
{
ping: 1
Expand Down Expand Up @@ -52,7 +53,9 @@ test('should not report errors on extended admin statements', () => {
db.admin().replSetGetStatus({
test_option: 'test_value',
});
db.admin().validateCollection('test_collection');
db.admin().validateCollection('test_collection', {
test_option: 'test_value',
});
`);

expect(autocompleteResult.errors).toHaveLength(0);
Expand All @@ -77,14 +80,17 @@ test('should suggest keywords after db.admin().', () => {
test('should extract admin commands properly', () => {
const result = extractMongoCommandsFromQuery(`
db.admin().command({ping: 1});
db.admin().command({ping: 1}, {test_option: 'test_value'});
db.admin().removeUser('test_user');
db.admin().buildInfo();
db.admin().serverInfo();
db.admin().serverStatus();
db.admin().ping();
db.admin().listDatabases();
db.admin().replSetGetStatus();
db.admin().validateCollection('test_collection');
db.admin().validateCollection('test_collection', {
test_option: 'test_value',
});
`);

const commands: Command[] = [
Expand All @@ -96,6 +102,15 @@ test('should extract admin commands properly', () => {
document: {ping: 1},
},
},
{
type: 'database',
method: 'admin',
childMethod: {
method: 'command',
document: {ping: 1},
options: {test_option: 'test_value'},
},
},
{
type: 'database',
method: 'admin',
Expand Down Expand Up @@ -152,6 +167,9 @@ test('should extract admin commands properly', () => {
childMethod: {
method: 'validateCollection',
collectionName: 'test_collection',
options: {
test_option: 'test_value',
},
},
},
];
Expand Down
Loading

0 comments on commit 7ba9e71

Please sign in to comment.