-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add command to generate objectid (#416)
- Loading branch information
Showing
7 changed files
with
117 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import vscode from 'vscode'; | ||
import { expect } from 'chai'; | ||
|
||
import { createIdFactory, generateId } from '../../../utils/objectIdHelper'; | ||
|
||
const CONFIG_SECTION = 'mdb'; | ||
const CONFIG_NAME = 'uniqueObjectIdPerCursor'; | ||
|
||
suite('ObjectId Test Suite', () => { | ||
test('succesfully creates an ObjectId', () => { | ||
expect(() => generateId()).not.to.throw(); | ||
}); | ||
|
||
test('should generate the same ObjectId when config is false', async () => { | ||
await vscode.workspace | ||
.getConfiguration(CONFIG_SECTION) | ||
.update(CONFIG_NAME, false); | ||
|
||
const idFactory = createIdFactory(); | ||
const ids = [ | ||
idFactory(), | ||
idFactory() | ||
]; | ||
|
||
expect(ids[0]).to.equal(ids[1]); | ||
}); | ||
|
||
test('should generate unique ObjectIds when config is true', async () => { | ||
await vscode.workspace | ||
.getConfiguration(CONFIG_SECTION) | ||
.update(CONFIG_NAME, true); | ||
|
||
const idFactory = createIdFactory(); | ||
const ids = [ | ||
idFactory(), | ||
idFactory() | ||
]; | ||
|
||
expect(ids[0]).to.not.equal(ids[1]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as vscode from 'vscode'; | ||
import { ObjectId } from 'bson'; | ||
|
||
export function createIdFactory(): () => ObjectId { | ||
const uniqueObjectIdPerCursor = vscode.workspace | ||
.getConfiguration('mdb') | ||
.get('uniqueObjectIdPerCursor', false); | ||
|
||
if (uniqueObjectIdPerCursor) { | ||
return () => new ObjectId(); | ||
} | ||
|
||
const staticObjectId = new ObjectId(); | ||
return () => staticObjectId; | ||
} | ||
|
||
export function generateId(): ObjectId { | ||
return new ObjectId(); | ||
} |