Skip to content

Commit

Permalink
Added toBinary test
Browse files Browse the repository at this point in the history
  • Loading branch information
aditi-khare-mongoDB committed Jul 26, 2022
1 parent b990257 commit 933b6e6
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions test/node/uuid_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,29 @@ describe('UUID', () => {
expect(inspect(uuid)).to.equal(`new UUID("${LOWERCASE_DASH_SEPARATED_UUID_STRING}")`);
});

it(`should serialize as a valid UUID _bsontype with Object input without error`, () => {
const output = BSON.serialize({ uuid: new BSON.UUID() });
expect(output[4]).to.equal(BSON_DATA_BINARY);
expect(output[14]).to.equal(BSON_BINARY_SUBTYPE_UUID_NEW);
});

it(`should serialize as a valid UUID _bsontype with Map input without error`, () => {
const output = BSON.serialize(new Map([['uuid', new BSON.UUID()]]));
expect(output[4]).to.equal(BSON_DATA_BINARY);
expect(output[14]).to.equal(BSON_BINARY_SUBTYPE_UUID_NEW);
});

it(`should serialize as a valid UUID _bsontype with Array input without error`, () => {
const output = BSON.serialize({ a: [new BSON.UUID()] });
expect(output[11]).to.equal(BSON_DATA_BINARY);
expect(output[18]).to.equal(BSON_BINARY_SUBTYPE_UUID_NEW);
describe('serialize', () => {
it('should have a valid UUID _bsontype with Object input without error', () => {
const output = BSON.serialize({ uuid: new BSON.UUID() });
expect(output[4]).to.equal(BSON_DATA_BINARY);
expect(output[14]).to.equal(BSON_BINARY_SUBTYPE_UUID_NEW);
});

it('should have a valid UUID _bsontype with Map input without error', () => {
const output = BSON.serialize(new Map([['uuid', new BSON.UUID()]]));
expect(output[4]).to.equal(BSON_DATA_BINARY);
expect(output[14]).to.equal(BSON_BINARY_SUBTYPE_UUID_NEW);
});

it('should have as a valid UUID _bsontype with Array input without error', () => {
const output = BSON.serialize({ a: [new BSON.UUID()] });
expect(output[11]).to.equal(BSON_DATA_BINARY);
expect(output[18]).to.equal(BSON_BINARY_SUBTYPE_UUID_NEW);
});

it('should serialize BSON.UUID() input the same as BSON.UUID().toBinary()', () => {
const toBinarySerialization = BSON.serialize({ uuid: new BSON.UUID().toBinary() });
const plainUUIDSerialization = BSON.serialize({ uuid: new BSON.UUID() });
expect(plainUUIDSerialization).to.deep.equal(toBinarySerialization);
});
});
});

0 comments on commit 933b6e6

Please sign in to comment.