uuid-by-string 3.0.2 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/tests/test.js DELETED
@@ -1,113 +0,0 @@
1
- const generateUuid = require('..');
2
- const { uint8ToHex, md5Hash, stringToCharBuffer, sha1Hash, hashToUuid, uint8ArrayToHex } = require('../src/lib');
3
- const { longText } = require('./__mock__/longText');
4
- const { samples } = require('./__mock__/samples');
5
-
6
- const UUID_REGEXP = /^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;
7
-
8
- const hex = [[255, 'ff'], [0, '00'], [8, '08'], [11, '0b'], [111, '6f']];
9
-
10
- describe('unit tests', () => {
11
- test('should convert byte number to hex representation', () => {
12
- for (const item of hex) {
13
- expect(uint8ToHex(item[0])).toBe(item[1]);
14
- }
15
- });
16
-
17
- test('should convert byte array to hex string', () => {
18
- for (let i = 0; i < samples.length; i++) {
19
- const hex = Buffer.from(samples[i].md5Hash).toString('hex');
20
- expect(uint8ArrayToHex(samples[i].md5Hash)).toBe(hex);
21
- }
22
- });
23
-
24
- test('should convert string to char buffer', () => {
25
- for (let i = 0; i < samples.length; i++) {
26
- expect(stringToCharBuffer(samples[i].string)).toMatchSnapshot();
27
- }
28
- });
29
-
30
- test('should generate valid md5 hash', () => {
31
- for (let i = 0; i < samples.length; i++) {
32
- expect(md5Hash(stringToCharBuffer(samples[i].string))).toEqual(samples[i].md5Hash);
33
- }
34
- });
35
-
36
- test('should generate valid sha-1 hash', () => {
37
- for (let i = 0; i < samples.length; i++) {
38
- expect(sha1Hash(stringToCharBuffer(samples[i].string))).toEqual(samples[i].sha1Hash);
39
- }
40
- });
41
-
42
- test('should convert hash to uuid v3', () => {
43
- for (let i = 0; i < samples.length; i++) {
44
- const uuid = hashToUuid(samples[i].md5Hash, 3);
45
- expect(uuid).toEqual(samples[i].uuidV3);
46
- expect(uuid).toMatch(UUID_REGEXP);
47
- }
48
- });
49
-
50
- test('should convert hash to uuid v5', () => {
51
- for (let i = 0; i < samples.length; i++) {
52
- const uuid = hashToUuid(samples[i].sha1Hash, 5);
53
- expect(uuid).toEqual(samples[i].uuidV5);
54
- expect(uuid).toMatch(UUID_REGEXP);
55
- }
56
- });
57
- });
58
-
59
- describe('func tests', () => {
60
- test('should throw error because of the wrong value', () => {
61
- expect(() => generateUuid()).toThrowError();
62
- });
63
-
64
- test('should throw error because of the wrong version', () => {
65
- expect(() => generateUuid('Hello', 'world', 1)).toThrowError();
66
- });
67
-
68
- test('should generate uuid v3 from string', () => {
69
- for (let i = 0; i < samples.length; i++) {
70
- const uuid = generateUuid(samples[i].string, 3);
71
-
72
- expect(uuid).toMatch(UUID_REGEXP);
73
- expect(uuid).toEqual(samples[i].uuidV3);
74
- }
75
- });
76
-
77
- test('should generate uuid v3 from string with namespace', () => {
78
- for (let i = 0; i < samples.length; i++) {
79
- const uuid = generateUuid(samples[i].string, 'namespace');
80
-
81
- expect(uuid).toMatch(UUID_REGEXP);
82
- expect(uuid).not.toEqual(samples[i].uuidV3);
83
- }
84
- });
85
-
86
- test('should generate uuid v5 from string', () => {
87
- for (let i = 0; i < samples.length; i++) {
88
- const uuid = generateUuid(samples[i].string);
89
-
90
- expect(uuid).toMatch(UUID_REGEXP);
91
- expect(uuid).toEqual(samples[i].uuidV5);
92
- }
93
- });
94
-
95
- test('should generate uuid v5 from string with namespace', () => {
96
- for (let i = 0; i < samples.length; i++) {
97
- const uuid = generateUuid(samples[i].string, 'namespace', 5);
98
-
99
- expect(uuid).toMatch(UUID_REGEXP);
100
- expect(uuid).not.toEqual(samples[i].uuidV5);
101
- }
102
- });
103
-
104
- test('should generate platform compatible uuid', () => {
105
- expect(generateUuid('9239107d-259f-4cf8-b62d-0964b680ab08', 3)).toBe('12f01aa4-5090-3f83-b823-7e7cb43246e7');
106
- });
107
- });
108
-
109
- describe('checker of speed of one generation', () => {
110
- it('100k chars', () => {
111
- generateUuid(longText);
112
- });
113
- });