Skip to content

Commit 8e7bd16

Browse files
rebase help
1 parent a5e6a37 commit 8e7bd16

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/node/uuid_tests.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
'use strict';
24

35
const { Buffer } = require('buffer');
@@ -6,6 +8,8 @@ const { inspect } = require('util');
68
const { validate: uuidStringValidate, version: uuidStringVersion } = require('uuid');
79
const BSON = require('../register-bson');
810
const BSONTypeError = BSON.BSONTypeError;
11+
const BSON_DATA_BINARY = BSON.BSON_DATA_BINARY;
12+
const BSON_BINARY_SUBTYPE_UUID_NEW = BSON.BSON_BINARY_SUBTYPE_UUID_NEW;
913

1014
// Test values
1115
const UPPERCASE_DASH_SEPARATED_UUID_STRING = 'AAAAAAAA-AAAA-4AAA-AAAA-AAAAAAAAAAAA';
@@ -162,4 +166,31 @@ describe('UUID', () => {
162166
const uuid = new UUID(UPPERCASE_DASH_SEPARATED_UUID_STRING);
163167
expect(inspect(uuid)).to.equal(`new UUID("${LOWERCASE_DASH_SEPARATED_UUID_STRING}")`);
164168
});
169+
170+
describe('serialize', () => {
171+
it('should have a valid UUID _bsontype with Object input without error', () => {
172+
const output = BSON.serialize({ uuid: new BSON.UUID() });
173+
expect(output[4]).to.equal(BSON_DATA_BINARY);
174+
expect(output[14]).to.equal(BSON_BINARY_SUBTYPE_UUID_NEW);
175+
});
176+
177+
it('should have a valid UUID _bsontype with Map input without error', () => {
178+
const output = BSON.serialize(new Map([['uuid', new BSON.UUID()]]));
179+
expect(output[4]).to.equal(BSON_DATA_BINARY);
180+
expect(output[14]).to.equal(BSON_BINARY_SUBTYPE_UUID_NEW);
181+
});
182+
183+
it('should have as a valid UUID _bsontype with Array input without error', () => {
184+
const output = BSON.serialize({ a: [new BSON.UUID()] });
185+
expect(output[11]).to.equal(BSON_DATA_BINARY);
186+
expect(output[18]).to.equal(BSON_BINARY_SUBTYPE_UUID_NEW);
187+
});
188+
189+
it('should serialize BSON.UUID() input the same as BSON.UUID().toBinary()', () => {
190+
const exampleUUID = new BSON.UUID();
191+
const toBinarySerialization = BSON.serialize({ uuid: exampleUUID.toBinary() });
192+
const plainUUIDSerialization = BSON.serialize({ uuid: exampleUUID });
193+
expect(plainUUIDSerialization).to.deep.equal(toBinarySerialization);
194+
});
195+
});
165196
});

0 commit comments

Comments
 (0)