Skip to content

Commit ba8fc52

Browse files
committed
test: add uuid coverage
1 parent 2ec6695 commit ba8fc52

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/node/uuid.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,43 @@ describe('UUID', () => {
200200
expect(deserializedUUID).to.deep.equal(expectedResult);
201201
});
202202
});
203+
204+
context('createFromHexString()', () => {
205+
context('when called with a hex sequence', () => {
206+
it('returns a UUID instance with the decoded bytes', () => {
207+
const bytes = Buffer.from(UPPERCASE_VALUES_ONLY_UUID_STRING, 'hex');
208+
209+
const uuidDashed = UUID.createFromHexString(UPPERCASE_DASH_SEPARATED_UUID_STRING);
210+
expect(uuidDashed).to.have.deep.property('buffer', bytes);
211+
expect(uuidDashed).to.be.instanceOf(UUID);
212+
213+
const uuidNoDashed = UUID.createFromHexString(UPPERCASE_VALUES_ONLY_UUID_STRING);
214+
expect(uuidNoDashed).to.have.deep.property('buffer', bytes);
215+
expect(uuidNoDashed).to.be.instanceOf(UUID);
216+
});
217+
});
218+
219+
context('when called with an incorrect length string', () => {
220+
it('throws an error indicating the expected length of 32 or 36 characters', () => {
221+
expect(() => UUID.createFromHexString('')).to.throw(/32 or 36 character/);
222+
});
223+
});
224+
});
225+
226+
context('createFromBase64()', () => {
227+
context('when called with a base64 sequence', () => {
228+
it('returns a UUID instance with the decoded bytes', () => {
229+
const bytes = Buffer.from(UPPERCASE_VALUES_ONLY_UUID_STRING, 'hex');
230+
const uuid = UUID.createFromBase64(bytes.toString('base64'));
231+
expect(uuid).to.have.deep.property('buffer', bytes);
232+
expect(uuid).to.be.instanceOf(UUID);
233+
});
234+
});
235+
236+
context('when called with an incorrect length string', () => {
237+
it('throws an error indicating the expected length of 16 byte Buffer', () => {
238+
expect(() => UUID.createFromBase64('')).to.throw(/16 byte Buffer/);
239+
});
240+
});
241+
});
203242
});

0 commit comments

Comments
 (0)