isahaq-barcode 1.0.0 → 1.2.0

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.
@@ -1,187 +1,187 @@
1
- /**
2
- * Tests for BarcodeGenerator
3
- */
4
-
5
- const BarcodeGenerator = require('../index');
6
-
7
- describe('BarcodeGenerator', () => {
8
- describe('PNG Generation', () => {
9
- test('should generate PNG barcode', () => {
10
- const result = BarcodeGenerator.png('1234567890', 'code128');
11
- expect(Buffer.isBuffer(result)).toBe(true);
12
- });
13
-
14
- test('should generate PNG barcode with options', () => {
15
- const options = {
16
- width: 3,
17
- height: 150,
18
- displayValue: false,
19
- };
20
- const result = BarcodeGenerator.png('1234567890', 'code128', options);
21
- expect(Buffer.isBuffer(result)).toBe(true);
22
- });
23
-
24
- test('should throw error for invalid data', () => {
25
- expect(() => {
26
- BarcodeGenerator.png('', 'code128');
27
- }).toThrow('Data must be a non-empty string');
28
- });
29
-
30
- test('should throw error for invalid barcode type', () => {
31
- expect(() => {
32
- BarcodeGenerator.png('1234567890', 'invalid-type');
33
- }).toThrow('Invalid barcode type');
34
- });
35
- });
36
-
37
- describe('SVG Generation', () => {
38
- test('should generate SVG barcode', () => {
39
- const result = BarcodeGenerator.svg('1234567890', 'code128');
40
- expect(typeof result).toBe('string');
41
- expect(result).toContain('<svg');
42
- });
43
-
44
- test('should generate SVG barcode with options', () => {
45
- const options = {
46
- width: 3,
47
- height: 150,
48
- displayValue: false,
49
- };
50
- const result = BarcodeGenerator.svg('1234567890', 'code128', options);
51
- expect(typeof result).toBe('string');
52
- });
53
- });
54
-
55
- describe('HTML Generation', () => {
56
- test('should generate HTML barcode', () => {
57
- const result = BarcodeGenerator.html('1234567890', 'code128');
58
- expect(typeof result).toBe('string');
59
- expect(result).toContain('<div');
60
- });
61
-
62
- test('should generate HTML barcode with options', () => {
63
- const options = {
64
- width: 3,
65
- height: 150,
66
- displayValue: false,
67
- };
68
- const result = BarcodeGenerator.html('1234567890', 'code128', options);
69
- expect(typeof result).toBe('string');
70
- });
71
- });
72
-
73
- describe('PDF Generation', () => {
74
- test('should generate PDF barcode', async () => {
75
- const result = await BarcodeGenerator.pdf('1234567890', 'code128');
76
- expect(Buffer.isBuffer(result)).toBe(true);
77
- });
78
-
79
- test('should generate PDF barcode with options', async () => {
80
- const options = {
81
- width: 3,
82
- height: 150,
83
- displayValue: false,
84
- };
85
- const result = await BarcodeGenerator.pdf(
86
- '1234567890',
87
- 'code128',
88
- options
89
- );
90
- expect(Buffer.isBuffer(result)).toBe(true);
91
- });
92
- });
93
-
94
- describe('QR Code Generation', () => {
95
- test('should generate QR code', () => {
96
- const result = BarcodeGenerator.modernQr({
97
- data: 'https://example.com',
98
- size: 300,
99
- });
100
- expect(result).toBeDefined();
101
- expect(typeof result.generate).toBe('function');
102
- });
103
-
104
- test('should generate QR code with logo', () => {
105
- const result = BarcodeGenerator.modernQr({
106
- data: 'https://example.com',
107
- size: 300,
108
- logoPath: 'path/to/logo.png',
109
- logoSize: 60,
110
- });
111
- expect(result).toBeDefined();
112
- });
113
-
114
- test('should generate QR code with watermark', () => {
115
- const result = BarcodeGenerator.modernQr({
116
- data: 'https://example.com',
117
- size: 300,
118
- watermark: 'Watermark Text',
119
- watermarkPosition: 'center',
120
- });
121
- expect(result).toBeDefined();
122
- });
123
- });
124
-
125
- describe('Validation', () => {
126
- test('should validate data for Code 128', () => {
127
- const validation = BarcodeGenerator.validate('1234567890', 'code128');
128
- expect(validation.valid).toBe(true);
129
- });
130
-
131
- test('should validate data for EAN-13', () => {
132
- const validation = BarcodeGenerator.validate('1234567890123', 'ean13');
133
- expect(validation.valid).toBe(true);
134
- });
135
-
136
- test('should reject invalid data for EAN-13', () => {
137
- const validation = BarcodeGenerator.validate('123', 'ean13');
138
- expect(validation.valid).toBe(false);
139
- expect(validation.error).toContain('too short');
140
- });
141
- });
142
-
143
- describe('Batch Generation', () => {
144
- test('should generate multiple barcodes', () => {
145
- const items = [
146
- { data: '1234567890', type: 'code128', format: 'png' },
147
- { data: '9876543210', type: 'code39', format: 'svg' },
148
- ];
149
- const results = BarcodeGenerator.batch(items);
150
- expect(Array.isArray(results)).toBe(true);
151
- expect(results.length).toBe(2);
152
- });
153
-
154
- test('should handle batch generation errors', () => {
155
- const items = [
156
- { data: '1234567890', type: 'code128', format: 'png' },
157
- { data: '', type: 'code128', format: 'png' }, // Invalid data
158
- ];
159
- const results = BarcodeGenerator.batch(items);
160
- expect(results[0].success).toBe(true);
161
- expect(results[1].success).toBe(false);
162
- });
163
- });
164
-
165
- describe('Utility Methods', () => {
166
- test('should get barcode types', () => {
167
- const types = BarcodeGenerator.getBarcodeTypes();
168
- expect(Array.isArray(types)).toBe(true);
169
- expect(types).toContain('code128');
170
- expect(types).toContain('ean13');
171
- });
172
-
173
- test('should get render formats', () => {
174
- const formats = BarcodeGenerator.getRenderFormats();
175
- expect(Array.isArray(formats)).toBe(true);
176
- expect(formats).toContain('png');
177
- expect(formats).toContain('svg');
178
- });
179
-
180
- test('should get watermark positions', () => {
181
- const positions = BarcodeGenerator.getWatermarkPositions();
182
- expect(Array.isArray(positions)).toBe(true);
183
- expect(positions).toContain('center');
184
- expect(positions).toContain('top-left');
185
- });
186
- });
187
- });
1
+ /**
2
+ * Tests for BarcodeGenerator
3
+ */
4
+
5
+ const BarcodeGenerator = require('../index');
6
+
7
+ describe('BarcodeGenerator', () => {
8
+ describe('PNG Generation', () => {
9
+ test('should generate PNG barcode', () => {
10
+ const result = BarcodeGenerator.png('1234567890', 'code128');
11
+ expect(Buffer.isBuffer(result)).toBe(true);
12
+ });
13
+
14
+ test('should generate PNG barcode with options', () => {
15
+ const options = {
16
+ width: 3,
17
+ height: 150,
18
+ displayValue: false,
19
+ };
20
+ const result = BarcodeGenerator.png('1234567890', 'code128', options);
21
+ expect(Buffer.isBuffer(result)).toBe(true);
22
+ });
23
+
24
+ test('should throw error for invalid data', () => {
25
+ expect(() => {
26
+ BarcodeGenerator.png('', 'code128');
27
+ }).toThrow('Data must be a non-empty string');
28
+ });
29
+
30
+ test('should throw error for invalid barcode type', () => {
31
+ expect(() => {
32
+ BarcodeGenerator.png('1234567890', 'invalid-type');
33
+ }).toThrow('Invalid barcode type');
34
+ });
35
+ });
36
+
37
+ describe('SVG Generation', () => {
38
+ test('should generate SVG barcode', () => {
39
+ const result = BarcodeGenerator.svg('1234567890', 'code128');
40
+ expect(typeof result).toBe('string');
41
+ expect(result).toContain('<svg');
42
+ });
43
+
44
+ test('should generate SVG barcode with options', () => {
45
+ const options = {
46
+ width: 3,
47
+ height: 150,
48
+ displayValue: false,
49
+ };
50
+ const result = BarcodeGenerator.svg('1234567890', 'code128', options);
51
+ expect(typeof result).toBe('string');
52
+ });
53
+ });
54
+
55
+ describe('HTML Generation', () => {
56
+ test('should generate HTML barcode', () => {
57
+ const result = BarcodeGenerator.html('1234567890', 'code128');
58
+ expect(typeof result).toBe('string');
59
+ expect(result).toContain('<div');
60
+ });
61
+
62
+ test('should generate HTML barcode with options', () => {
63
+ const options = {
64
+ width: 3,
65
+ height: 150,
66
+ displayValue: false,
67
+ };
68
+ const result = BarcodeGenerator.html('1234567890', 'code128', options);
69
+ expect(typeof result).toBe('string');
70
+ });
71
+ });
72
+
73
+ describe('PDF Generation', () => {
74
+ test('should generate PDF barcode', async () => {
75
+ const result = await BarcodeGenerator.pdf('1234567890', 'code128');
76
+ expect(Buffer.isBuffer(result)).toBe(true);
77
+ });
78
+
79
+ test('should generate PDF barcode with options', async () => {
80
+ const options = {
81
+ width: 3,
82
+ height: 150,
83
+ displayValue: false,
84
+ };
85
+ const result = await BarcodeGenerator.pdf(
86
+ '1234567890',
87
+ 'code128',
88
+ options
89
+ );
90
+ expect(Buffer.isBuffer(result)).toBe(true);
91
+ });
92
+ });
93
+
94
+ describe('QR Code Generation', () => {
95
+ test('should generate QR code', () => {
96
+ const result = BarcodeGenerator.modernQr({
97
+ data: 'https://example.com',
98
+ size: 300,
99
+ });
100
+ expect(result).toBeDefined();
101
+ expect(typeof result.generate).toBe('function');
102
+ });
103
+
104
+ test('should generate QR code with logo', () => {
105
+ const result = BarcodeGenerator.modernQr({
106
+ data: 'https://example.com',
107
+ size: 300,
108
+ logoPath: 'path/to/logo.png',
109
+ logoSize: 60,
110
+ });
111
+ expect(result).toBeDefined();
112
+ });
113
+
114
+ test('should generate QR code with watermark', () => {
115
+ const result = BarcodeGenerator.modernQr({
116
+ data: 'https://example.com',
117
+ size: 300,
118
+ watermark: 'Watermark Text',
119
+ watermarkPosition: 'center',
120
+ });
121
+ expect(result).toBeDefined();
122
+ });
123
+ });
124
+
125
+ describe('Validation', () => {
126
+ test('should validate data for Code 128', () => {
127
+ const validation = BarcodeGenerator.validate('1234567890', 'code128');
128
+ expect(validation.valid).toBe(true);
129
+ });
130
+
131
+ test('should validate data for EAN-13', () => {
132
+ const validation = BarcodeGenerator.validate('1234567890123', 'ean13');
133
+ expect(validation.valid).toBe(true);
134
+ });
135
+
136
+ test('should reject invalid data for EAN-13', () => {
137
+ const validation = BarcodeGenerator.validate('123', 'ean13');
138
+ expect(validation.valid).toBe(false);
139
+ expect(validation.error).toContain('too short');
140
+ });
141
+ });
142
+
143
+ describe('Batch Generation', () => {
144
+ test('should generate multiple barcodes', () => {
145
+ const items = [
146
+ { data: '1234567890', type: 'code128', format: 'png' },
147
+ { data: '9876543210', type: 'code39', format: 'svg' },
148
+ ];
149
+ const results = BarcodeGenerator.batch(items);
150
+ expect(Array.isArray(results)).toBe(true);
151
+ expect(results.length).toBe(2);
152
+ });
153
+
154
+ test('should handle batch generation errors', () => {
155
+ const items = [
156
+ { data: '1234567890', type: 'code128', format: 'png' },
157
+ { data: '', type: 'code128', format: 'png' }, // Invalid data
158
+ ];
159
+ const results = BarcodeGenerator.batch(items);
160
+ expect(results[0].success).toBe(true);
161
+ expect(results[1].success).toBe(false);
162
+ });
163
+ });
164
+
165
+ describe('Utility Methods', () => {
166
+ test('should get barcode types', () => {
167
+ const types = BarcodeGenerator.getBarcodeTypes();
168
+ expect(Array.isArray(types)).toBe(true);
169
+ expect(types).toContain('code128');
170
+ expect(types).toContain('ean13');
171
+ });
172
+
173
+ test('should get render formats', () => {
174
+ const formats = BarcodeGenerator.getRenderFormats();
175
+ expect(Array.isArray(formats)).toBe(true);
176
+ expect(formats).toContain('png');
177
+ expect(formats).toContain('svg');
178
+ });
179
+
180
+ test('should get watermark positions', () => {
181
+ const positions = BarcodeGenerator.getWatermarkPositions();
182
+ expect(Array.isArray(positions)).toBe(true);
183
+ expect(positions).toContain('center');
184
+ expect(positions).toContain('top-left');
185
+ });
186
+ });
187
+ });
@@ -1,76 +1,76 @@
1
- /**
2
- * Tests for BarcodeService
3
- */
4
-
5
- const BarcodeService = require('../src/services/BarcodeService');
6
-
7
- describe('BarcodeService', () => {
8
- let service;
9
-
10
- beforeEach(() => {
11
- service = new BarcodeService();
12
- });
13
-
14
- describe('PNG Generation', () => {
15
- test('should generate PNG barcode', () => {
16
- const result = service.png('1234567890', 'code128');
17
- expect(Buffer.isBuffer(result)).toBe(true);
18
- });
19
-
20
- test('should generate PNG barcode with options', () => {
21
- const options = {
22
- width: 3,
23
- height: 150,
24
- displayValue: false,
25
- };
26
- const result = service.png('1234567890', 'code128', options);
27
- expect(Buffer.isBuffer(result)).toBe(true);
28
- });
29
- });
30
-
31
- describe('SVG Generation', () => {
32
- test('should generate SVG barcode', () => {
33
- const result = service.svg('1234567890', 'code128');
34
- expect(typeof result).toBe('string');
35
- });
36
- });
37
-
38
- describe('HTML Generation', () => {
39
- test('should generate HTML barcode', () => {
40
- const result = service.html('1234567890', 'code128');
41
- expect(typeof result).toBe('string');
42
- expect(result).toContain('<div');
43
- });
44
- });
45
-
46
- describe('PDF Generation', () => {
47
- test('should generate PDF barcode', async () => {
48
- const result = await service.pdf('1234567890', 'code128');
49
- expect(Buffer.isBuffer(result)).toBe(true);
50
- });
51
- });
52
-
53
- describe('Validation', () => {
54
- test('should validate data', () => {
55
- const validation = service.validate('1234567890', 'code128');
56
- expect(validation.valid).toBe(true);
57
- });
58
-
59
- test('should reject invalid data', () => {
60
- const validation = service.validate('', 'code128');
61
- expect(validation.valid).toBe(false);
62
- });
63
- });
64
-
65
- describe('Batch Generation', () => {
66
- test('should generate multiple barcodes', () => {
67
- const items = [
68
- { data: '1234567890', type: 'code128', format: 'png' },
69
- { data: '9876543210', type: 'code39', format: 'svg' },
70
- ];
71
- const results = service.batch(items);
72
- expect(Array.isArray(results)).toBe(true);
73
- expect(results.length).toBe(2);
74
- });
75
- });
76
- });
1
+ /**
2
+ * Tests for BarcodeService
3
+ */
4
+
5
+ const BarcodeService = require('../src/services/BarcodeService');
6
+
7
+ describe('BarcodeService', () => {
8
+ let service;
9
+
10
+ beforeEach(() => {
11
+ service = new BarcodeService();
12
+ });
13
+
14
+ describe('PNG Generation', () => {
15
+ test('should generate PNG barcode', () => {
16
+ const result = service.png('1234567890', 'code128');
17
+ expect(Buffer.isBuffer(result)).toBe(true);
18
+ });
19
+
20
+ test('should generate PNG barcode with options', () => {
21
+ const options = {
22
+ width: 3,
23
+ height: 150,
24
+ displayValue: false,
25
+ };
26
+ const result = service.png('1234567890', 'code128', options);
27
+ expect(Buffer.isBuffer(result)).toBe(true);
28
+ });
29
+ });
30
+
31
+ describe('SVG Generation', () => {
32
+ test('should generate SVG barcode', () => {
33
+ const result = service.svg('1234567890', 'code128');
34
+ expect(typeof result).toBe('string');
35
+ });
36
+ });
37
+
38
+ describe('HTML Generation', () => {
39
+ test('should generate HTML barcode', () => {
40
+ const result = service.html('1234567890', 'code128');
41
+ expect(typeof result).toBe('string');
42
+ expect(result).toContain('<div');
43
+ });
44
+ });
45
+
46
+ describe('PDF Generation', () => {
47
+ test('should generate PDF barcode', async () => {
48
+ const result = await service.pdf('1234567890', 'code128');
49
+ expect(Buffer.isBuffer(result)).toBe(true);
50
+ });
51
+ });
52
+
53
+ describe('Validation', () => {
54
+ test('should validate data', () => {
55
+ const validation = service.validate('1234567890', 'code128');
56
+ expect(validation.valid).toBe(true);
57
+ });
58
+
59
+ test('should reject invalid data', () => {
60
+ const validation = service.validate('', 'code128');
61
+ expect(validation.valid).toBe(false);
62
+ });
63
+ });
64
+
65
+ describe('Batch Generation', () => {
66
+ test('should generate multiple barcodes', () => {
67
+ const items = [
68
+ { data: '1234567890', type: 'code128', format: 'png' },
69
+ { data: '9876543210', type: 'code39', format: 'svg' },
70
+ ];
71
+ const results = service.batch(items);
72
+ expect(Array.isArray(results)).toBe(true);
73
+ expect(results.length).toBe(2);
74
+ });
75
+ });
76
+ });