Skip to content

Commit

Permalink
add test case for toCollectionName function
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamEHRAccount committed Aug 14, 2024
1 parent 516bd88 commit c0801a8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,31 @@ describe('utils', function() {
assert.deepEqual(pojoError.metadata, { hello: 'world' });
});
});

describe('toCollectionName', function() {
it('returns the same name for system.profile', function() {
assert.equal(utils.toCollectionName('system.profile'), 'system.profile');
});

it('returns the same name for system.indexes', function() {
assert.equal(utils.toCollectionName('system.indexes'), 'system.indexes');
});

it('throws an error when name is not a string', function() {
assert.throws(() => {
utils.toCollectionName(123, () => {});
}, /Collection name must be a string/);
});

it('throws an error when name is an empty string', function() {
assert.throws(() => {
utils.toCollectionName('', () => {});
}, /Collection name cannot be empty/);
});

it('uses the pluralize function when provided', function() {
const pluralize = (name) => name + 's';
assert.equal(utils.toCollectionName('test', pluralize), 'tests');
});
});
});

0 comments on commit c0801a8

Please sign in to comment.