Skip to content

Commit 3b4f134

Browse files
cristotodevclaude
andcommitted
fix: resolve environment variable validation errors in 5 additional tests
Fixed the same Zod environment variable validation issue that was affecting proveedores.test.ts in these additional test files: - stocks.test.ts: Fixed both StocksResource and lowStockToolImplementation test sections - variantes.test.ts: Fixed VariantesResource tests - facturaproveedores.test.ts: Fixed FacturaproveedoresResource tests - totalmodeles.test.ts: Fixed TotalModelesResource tests - workeventes.test.ts: Fixed WorkEventesResource tests Changes made to each file: - Removed import of FacturaScriptsClient class - Removed vi.mock() calls for the client - Replaced new FacturaScriptsClient() with mock object { getWithPagination: vi.fn() } - Updated all vi.mocked(mockClient.getWithPagination) calls to mockClient.getWithPagination - This prevents environment variable validation during test execution All 534 unit tests now pass successfully in both local and CI environments. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e9e392f commit 3b4f134

5 files changed

Lines changed: 60 additions & 65 deletions

File tree

tests/unit/modules/core-business/stocks.test.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import { describe, it, expect, vi, beforeEach } from 'vitest';
22
import { StocksResource } from '../../../../src/modules/core-business/stocks/resource.js';
33
import { lowStockToolImplementation } from '../../../../src/modules/core-business/stocks/tool.js';
4-
import { FacturaScriptsClient } from '../../../../src/fs/client.js';
54
import type { Stock } from '../../../../src/types/facturascripts.js';
65

7-
// Mock the FacturaScriptsClient
8-
vi.mock('../../../../src/fs/client.js');
9-
106
describe('StocksResource', () => {
11-
let mockClient: FacturaScriptsClient;
7+
let mockClient: any;
128
let stocksResource: StocksResource;
139

1410
beforeEach(() => {
15-
mockClient = new FacturaScriptsClient();
16-
stocksResource = new StocksResource(mockClient);
1711
vi.clearAllMocks();
12+
mockClient = {
13+
getWithPagination: vi.fn()
14+
};
15+
stocksResource = new StocksResource(mockClient);
1816
});
1917

2018
describe('matchesUri', () => {
@@ -72,7 +70,7 @@ describe('StocksResource', () => {
7270
};
7371

7472
it('should return stocks data with default pagination', async () => {
75-
vi.mocked(mockClient.getWithPagination).mockResolvedValue(mockPaginatedResponse);
73+
mockClient.getWithPagination.mockResolvedValue(mockPaginatedResponse);
7674

7775
const result = await stocksResource.getResource('facturascripts://stocks');
7876

@@ -92,7 +90,7 @@ describe('StocksResource', () => {
9290
});
9391

9492
it('should parse and use limit and offset from URI', async () => {
95-
vi.mocked(mockClient.getWithPagination).mockResolvedValue({
93+
mockClient.getWithPagination.mockResolvedValue({
9694
...mockPaginatedResponse,
9795
meta: { ...mockPaginatedResponse.meta, limit: 25, offset: 10 },
9896
});
@@ -106,7 +104,7 @@ describe('StocksResource', () => {
106104

107105
it('should handle API errors gracefully', async () => {
108106
const errorMessage = 'Stock API connection failed';
109-
vi.mocked(mockClient.getWithPagination).mockRejectedValue(new Error(errorMessage));
107+
mockClient.getWithPagination.mockRejectedValue(new Error(errorMessage));
110108

111109
const result = await stocksResource.getResource('facturascripts://stocks');
112110

@@ -118,11 +116,13 @@ describe('StocksResource', () => {
118116
});
119117

120118
describe('lowStockToolImplementation', () => {
121-
let mockClient: FacturaScriptsClient;
119+
let mockClient: any;
122120

123121
beforeEach(() => {
124-
mockClient = new FacturaScriptsClient();
125122
vi.clearAllMocks();
123+
mockClient = {
124+
getWithPagination: vi.fn()
125+
};
126126
});
127127

128128
const mockStocksWithLowStock: Stock[] = [
@@ -169,7 +169,7 @@ describe('lowStockToolImplementation', () => {
169169
describe('successful scenarios', () => {
170170
it('should return products with stock below or equal to minimum by default', async () => {
171171
// Mock stocks response
172-
vi.mocked(mockClient.getWithPagination)
172+
mockClient.getWithPagination
173173
.mockResolvedValueOnce({
174174
meta: { total: 4, limit: 1000, offset: 0, hasMore: false },
175175
data: mockStocksWithLowStock,
@@ -206,7 +206,7 @@ describe('lowStockToolImplementation', () => {
206206
});
207207

208208
it('should exclude products with stock equal to minimum when explicitly requested', async () => {
209-
vi.mocked(mockClient.getWithPagination)
209+
mockClient.getWithPagination
210210
.mockResolvedValueOnce({
211211
meta: { total: 4, limit: 1000, offset: 0, hasMore: false },
212212
data: mockStocksWithLowStock,
@@ -232,7 +232,7 @@ describe('lowStockToolImplementation', () => {
232232
});
233233

234234
it('should include products with stock equal to minimum when explicitly requested', async () => {
235-
vi.mocked(mockClient.getWithPagination)
235+
mockClient.getWithPagination
236236
.mockResolvedValueOnce({
237237
meta: { total: 4, limit: 1000, offset: 0, hasMore: false },
238238
data: mockStocksWithLowStock,
@@ -263,7 +263,7 @@ describe('lowStockToolImplementation', () => {
263263
it('should filter by warehouse when codalmacen is provided', async () => {
264264
const filteredStocks = mockStocksWithLowStock.filter(s => s.codalmacen === 'ALM002');
265265

266-
vi.mocked(mockClient.getWithPagination)
266+
mockClient.getWithPagination
267267
.mockResolvedValueOnce({
268268
meta: { total: 1, limit: 1000, offset: 0, hasMore: false },
269269
data: filteredStocks,
@@ -292,7 +292,7 @@ describe('lowStockToolImplementation', () => {
292292
});
293293

294294
it('should handle pagination correctly - middle page', async () => {
295-
vi.mocked(mockClient.getWithPagination)
295+
mockClient.getWithPagination
296296
.mockResolvedValueOnce({
297297
meta: { total: 4, limit: 1000, offset: 0, hasMore: false },
298298
data: mockStocksWithLowStock,
@@ -322,7 +322,7 @@ describe('lowStockToolImplementation', () => {
322322
});
323323

324324
it('should handle pagination correctly - first page with more data', async () => {
325-
vi.mocked(mockClient.getWithPagination)
325+
mockClient.getWithPagination
326326
.mockResolvedValueOnce({
327327
meta: { total: 4, limit: 1000, offset: 0, hasMore: false },
328328
data: mockStocksWithLowStock,
@@ -348,7 +348,7 @@ describe('lowStockToolImplementation', () => {
348348
});
349349

350350
it('should sort results by cantidad ascending', async () => {
351-
vi.mocked(mockClient.getWithPagination)
351+
mockClient.getWithPagination
352352
.mockResolvedValueOnce({
353353
meta: { total: 4, limit: 1000, offset: 0, hasMore: false },
354354
data: mockStocksWithLowStock,
@@ -369,7 +369,7 @@ describe('lowStockToolImplementation', () => {
369369

370370
describe('edge cases and error handling', () => {
371371
it('should return empty result when no stocks exist', async () => {
372-
vi.mocked(mockClient.getWithPagination).mockResolvedValue({
372+
mockClient.getWithPagination.mockResolvedValue({
373373
meta: { total: 0, limit: 1000, offset: 0, hasMore: false },
374374
data: [],
375375
});
@@ -385,7 +385,7 @@ describe('lowStockToolImplementation', () => {
385385
it('should return empty result when no products are below or equal minimum stock', async () => {
386386
const stocksAboveMin = mockStocksWithLowStock.map(s => ({ ...s, cantidad: s.stockmin! + 10 }));
387387

388-
vi.mocked(mockClient.getWithPagination).mockResolvedValue({
388+
mockClient.getWithPagination.mockResolvedValue({
389389
meta: { total: 4, limit: 1000, offset: 0, hasMore: false },
390390
data: stocksAboveMin,
391391
});
@@ -401,7 +401,7 @@ describe('lowStockToolImplementation', () => {
401401
it('should skip items without stockmin defined', async () => {
402402
const stocksWithoutMin = mockStocksWithLowStock.map(s => ({ ...s, stockmin: undefined }));
403403

404-
vi.mocked(mockClient.getWithPagination).mockResolvedValue({
404+
mockClient.getWithPagination.mockResolvedValue({
405405
meta: { total: 4, limit: 1000, offset: 0, hasMore: false },
406406
data: stocksWithoutMin,
407407
});
@@ -414,7 +414,7 @@ describe('lowStockToolImplementation', () => {
414414
});
415415

416416
it('should handle parameter validation', async () => {
417-
vi.mocked(mockClient.getWithPagination)
417+
mockClient.getWithPagination
418418
.mockResolvedValueOnce({
419419
meta: { total: 4, limit: 1000, offset: 0, hasMore: false },
420420
data: mockStocksWithLowStock,
@@ -435,7 +435,7 @@ describe('lowStockToolImplementation', () => {
435435
});
436436

437437
it('should handle API errors gracefully', async () => {
438-
vi.mocked(mockClient.getWithPagination).mockRejectedValue(
438+
mockClient.getWithPagination.mockRejectedValue(
439439
new Error('API connection failed')
440440
);
441441

@@ -448,7 +448,7 @@ describe('lowStockToolImplementation', () => {
448448
});
449449

450450
it('should fallback to stock description when product details fail', async () => {
451-
vi.mocked(mockClient.getWithPagination)
451+
mockClient.getWithPagination
452452
.mockResolvedValueOnce({
453453
meta: { total: 1, limit: 1000, offset: 0, hasMore: false },
454454
data: [mockStocksWithLowStock[0]],

tests/unit/modules/core-business/variantes.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { describe, it, expect, beforeEach, vi } from 'vitest';
2-
import { FacturaScriptsClient } from '../../../../src/fs/client.js';
32
import { VariantesResource } from '../../../../src/modules/core-business/variantes/resource.js';
43
import type { Variante } from '../../../../src/types/facturascripts.js';
54

6-
vi.mock('../../../../src/fs/client.js');
7-
85
describe('VariantesResource', () => {
9-
let mockClient: FacturaScriptsClient;
6+
let mockClient: any;
107
let variantesResource: VariantesResource;
118

129
beforeEach(() => {
13-
mockClient = new FacturaScriptsClient();
14-
variantesResource = new VariantesResource(mockClient);
1510
vi.clearAllMocks();
11+
mockClient = {
12+
getWithPagination: vi.fn()
13+
};
14+
variantesResource = new VariantesResource(mockClient);
1615
});
1716

1817
describe('getResource', () => {
@@ -52,7 +51,7 @@ describe('VariantesResource', () => {
5251
data: mockData,
5352
};
5453

55-
vi.mocked(mockClient.getWithPagination).mockResolvedValue(mockResponse);
54+
mockClient.getWithPagination.mockResolvedValue(mockResponse);
5655

5756
const result = await variantesResource.getResource('facturascripts://variantes?limit=50&offset=0');
5857

@@ -80,7 +79,7 @@ describe('VariantesResource', () => {
8079

8180
it('should handle API errors gracefully', async () => {
8281
const mockError = new Error('Database connection failed');
83-
vi.mocked(mockClient.getWithPagination).mockRejectedValue(mockError);
82+
mockClient.getWithPagination.mockRejectedValue(mockError);
8483

8584
const result = await variantesResource.getResource('facturascripts://variantes');
8685

@@ -101,7 +100,7 @@ describe('VariantesResource', () => {
101100
data: [],
102101
};
103102

104-
vi.mocked(mockClient.getWithPagination).mockResolvedValue(mockResponse);
103+
mockClient.getWithPagination.mockResolvedValue(mockResponse);
105104

106105
await variantesResource.getResource('facturascripts://variantes?limit=25&offset=10&filter=idproducto:100,precio_gte:20.00&order=precio:desc');
107106

@@ -123,7 +122,7 @@ describe('VariantesResource', () => {
123122
data: [],
124123
};
125124

126-
vi.mocked(mockClient.getWithPagination).mockResolvedValue(mockResponse);
125+
mockClient.getWithPagination.mockResolvedValue(mockResponse);
127126

128127
const result = await variantesResource.getResource('facturascripts://variantes?filter=nonexistent:value');
129128

tests/unit/modules/purchasing/facturaproveedores.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import { describe, it, expect, vi, beforeEach } from 'vitest';
22
import { FacturaproveedoresResource } from '../../../../src/modules/purchasing/facturaproveedores/resource.js';
3-
import { FacturaScriptsClient } from '../../../../src/fs/client.js';
43
import type { FacturaProveedor } from '../../../../src/types/facturascripts.js';
54

6-
// Mock the FacturaScriptsClient
7-
vi.mock('../../../../src/fs/client.js');
8-
95
describe('FacturaproveedoresResource', () => {
10-
let mockClient: FacturaScriptsClient;
6+
let mockClient: any;
117
let facturaproveedoresResource: FacturaproveedoresResource;
128

139
beforeEach(() => {
14-
mockClient = new FacturaScriptsClient();
15-
facturaproveedoresResource = new FacturaproveedoresResource(mockClient);
1610
vi.clearAllMocks();
11+
mockClient = {
12+
getWithPagination: vi.fn()
13+
};
14+
facturaproveedoresResource = new FacturaproveedoresResource(mockClient);
1715
});
1816

1917
describe('matchesUri', () => {
@@ -93,7 +91,7 @@ describe('FacturaproveedoresResource', () => {
9391
};
9492

9593
it('should return factura proveedores data with default pagination', async () => {
96-
vi.mocked(mockClient.getWithPagination).mockResolvedValue(mockPaginatedResponse);
94+
mockClient.getWithPagination.mockResolvedValue(mockPaginatedResponse);
9795

9896
const result = await facturaproveedoresResource.getResource('facturascripts://facturaproveedores');
9997

@@ -113,7 +111,7 @@ describe('FacturaproveedoresResource', () => {
113111
});
114112

115113
it('should parse and use limit and offset from URI', async () => {
116-
vi.mocked(mockClient.getWithPagination).mockResolvedValue({
114+
mockClient.getWithPagination.mockResolvedValue({
117115
...mockPaginatedResponse,
118116
meta: { ...mockPaginatedResponse.meta, limit: 20, offset: 5 },
119117
});
@@ -127,7 +125,7 @@ describe('FacturaproveedoresResource', () => {
127125

128126
it('should handle API errors gracefully', async () => {
129127
const errorMessage = 'FacturaProveedores API connection failed';
130-
vi.mocked(mockClient.getWithPagination).mockRejectedValue(new Error(errorMessage));
128+
mockClient.getWithPagination.mockRejectedValue(new Error(errorMessage));
131129

132130
const result = await facturaproveedoresResource.getResource('facturascripts://facturaproveedores');
133131

tests/unit/modules/system/totalmodeles.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { describe, it, expect, beforeEach, vi } from 'vitest';
2-
import { FacturaScriptsClient } from '../../../../src/fs/client.js';
32
import { TotalModelesResource } from '../../../../src/modules/system/totalmodeles/resource.js';
43
import type { TotalModel } from '../../../../src/types/facturascripts.js';
54

6-
vi.mock('../../../../src/fs/client.js');
7-
85
describe('TotalModelesResource', () => {
9-
let mockClient: FacturaScriptsClient;
6+
let mockClient: any;
107
let totalModelesResource: TotalModelesResource;
118

129
beforeEach(() => {
13-
mockClient = new FacturaScriptsClient();
14-
totalModelesResource = new TotalModelesResource(mockClient);
1510
vi.clearAllMocks();
11+
mockClient = {
12+
getWithPagination: vi.fn()
13+
};
14+
totalModelesResource = new TotalModelesResource(mockClient);
1615
});
1716

1817
describe('getResource', () => {
@@ -32,7 +31,7 @@ describe('TotalModelesResource', () => {
3231
data: mockData,
3332
};
3433

35-
vi.mocked(mockClient.getWithPagination).mockResolvedValue(mockResponse);
34+
mockClient.getWithPagination.mockResolvedValue(mockResponse);
3635

3736
const result = await totalModelesResource.getResource('facturascripts://totalmodeles?limit=50&offset=0');
3837

@@ -58,7 +57,7 @@ describe('TotalModelesResource', () => {
5857

5958
it('should handle API errors gracefully', async () => {
6059
const mockError = new Error('API connection failed');
61-
vi.mocked(mockClient.getWithPagination).mockRejectedValue(mockError);
60+
mockClient.getWithPagination.mockRejectedValue(mockError);
6261

6362
const result = await totalModelesResource.getResource('facturascripts://totalmodeles');
6463

@@ -79,7 +78,7 @@ describe('TotalModelesResource', () => {
7978
data: [],
8079
};
8180

82-
vi.mocked(mockClient.getWithPagination).mockResolvedValue(mockResponse);
81+
mockClient.getWithPagination.mockResolvedValue(mockResponse);
8382

8483
await totalModelesResource.getResource('facturascripts://totalmodeles?limit=25&offset=10&filter=active:1&order=name:asc');
8584

0 commit comments

Comments
 (0)