Skip to content

Commit

Permalink
rebase help
Browse files Browse the repository at this point in the history
  • Loading branch information
aditi-khare-mongoDB committed Aug 2, 2022
1 parent a5e6a37 commit 8e7bd16
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/node/uuid_tests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


'use strict';

const { Buffer } = require('buffer');
Expand All @@ -6,6 +8,8 @@ const { inspect } = require('util');
const { validate: uuidStringValidate, version: uuidStringVersion } = require('uuid');
const BSON = require('../register-bson');
const BSONTypeError = BSON.BSONTypeError;
const BSON_DATA_BINARY = BSON.BSON_DATA_BINARY;
const BSON_BINARY_SUBTYPE_UUID_NEW = BSON.BSON_BINARY_SUBTYPE_UUID_NEW;

// Test values
const UPPERCASE_DASH_SEPARATED_UUID_STRING = 'AAAAAAAA-AAAA-4AAA-AAAA-AAAAAAAAAAAA';
Expand Down Expand Up @@ -162,4 +166,31 @@ describe('UUID', () => {
const uuid = new UUID(UPPERCASE_DASH_SEPARATED_UUID_STRING);
expect(inspect(uuid)).to.equal(`new UUID("${LOWERCASE_DASH_SEPARATED_UUID_STRING}")`);
});

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 exampleUUID = new BSON.UUID();
const toBinarySerialization = BSON.serialize({ uuid: exampleUUID.toBinary() });
const plainUUIDSerialization = BSON.serialize({ uuid: exampleUUID });
expect(plainUUIDSerialization).to.deep.equal(toBinarySerialization);
});
});
});

0 comments on commit 8e7bd16

Please sign in to comment.