From 1771066b2cb7dc8936c68a062a96075edae0aaf0 Mon Sep 17 00:00:00 2001 From: "anatoly.shipitz" Date: Wed, 6 Aug 2025 14:46:19 +0200 Subject: [PATCH 1/2] Add axios configuration and tests - Introduced `axios.ts` to define the axios configuration with timeout, maxRetries, and headers. - Added `axios.test.ts` to validate the properties and values of the axios configuration, ensuring it meets the expected structure and values. These changes enhance the application's HTTP client configuration and ensure proper testing of the axios setup. --- workers/main/src/configs/axios.test.ts | 34 ++++++++++++++++++++++++++ workers/main/src/configs/axios.ts | 8 ++++++ workers/main/src/configs/qbo.ts | 23 ++++++++++------- 3 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 workers/main/src/configs/axios.test.ts create mode 100644 workers/main/src/configs/axios.ts diff --git a/workers/main/src/configs/axios.test.ts b/workers/main/src/configs/axios.test.ts new file mode 100644 index 00000000..c8779fbe --- /dev/null +++ b/workers/main/src/configs/axios.test.ts @@ -0,0 +1,34 @@ +import { describe, expect, it } from 'vitest'; + +import { axiosConfig } from './axios'; + +describe('axiosConfig', () => { + it('should have required properties', () => { + expect(axiosConfig).toHaveProperty('timeout'); + expect(axiosConfig).toHaveProperty('maxRetries'); + expect(axiosConfig).toHaveProperty('headers'); + }); + + it('should have correct timeout value', () => { + expect(axiosConfig.timeout).toBe(30000); + }); + + it('should have correct maxRetries value', () => { + expect(axiosConfig.maxRetries).toBe(3); + }); + + it('should have correct headers', () => { + expect(axiosConfig.headers).toEqual({ + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }); + }); + + it('should have Content-Type header', () => { + expect(axiosConfig.headers['Content-Type']).toBe('application/json'); + }); + + it('should have Accept header', () => { + expect(axiosConfig.headers['Accept']).toBe('application/json'); + }); +}); diff --git a/workers/main/src/configs/axios.ts b/workers/main/src/configs/axios.ts new file mode 100644 index 00000000..6f29145d --- /dev/null +++ b/workers/main/src/configs/axios.ts @@ -0,0 +1,8 @@ +export const axiosConfig = { + timeout: 30000, + maxRetries: 3, + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }, +}; diff --git a/workers/main/src/configs/qbo.ts b/workers/main/src/configs/qbo.ts index c2c2cd30..06418f5b 100644 --- a/workers/main/src/configs/qbo.ts +++ b/workers/main/src/configs/qbo.ts @@ -1,22 +1,27 @@ import { z } from 'zod'; export const qboConfig = { - apiUrl: process.env.QBO_API_URL, + apiUrl: process.env.QBO_API_URL!, bearerToken: process.env.QBO_BEARER_TOKEN, // OAuth2 configuration - clientId: process.env.QBO_CLIENT_ID, - clientSecret: process.env.QBO_CLIENT_SECRET, - companyId: process.env.QBO_COMPANY_ID, - refreshToken: process.env.QBO_REFRESH_TOKEN, - tokenEndpoint: - process.env.QBO_TOKEN_ENDPOINT || - 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', + clientId: process.env.QBO_CLIENT_ID!, + clientSecret: process.env.QBO_CLIENT_SECRET!, + companyId: process.env.QBO_COMPANY_ID!, + refreshToken: process.env.QBO_REFRESH_TOKEN!, + tokenHost: 'https://oauth.platform.intuit.com', + tokenPath: '/oauth2/v1/tokens/bearer', + tokenExpirationWindowSeconds: 300, + effectiveRevenueMonths: parseInt( + process.env.QBO_EFFECTIVE_REVENUE_MONTHS || '3', + ), }; export const qboSchema = z.object({ QBO_API_URL: z.string().url().min(1, 'QBO_API_URL is required'), + QBO_BEARER_TOKEN: z.string().optional(), QBO_CLIENT_ID: z.string().min(1, 'QBO_CLIENT_ID is required'), QBO_CLIENT_SECRET: z.string().min(1, 'QBO_CLIENT_SECRET is required'), QBO_COMPANY_ID: z.string().min(1, 'QBO_COMPANY_ID is required'), - QBO_REFRESH_TOKEN: z.string().optional(), + QBO_REFRESH_TOKEN: z.string(), + QBO_EFFECTIVE_REVENUE_MONTHS: z.string().optional(), }); From 3cb660c5990fb85e1d623529bb48f544f396b6f2 Mon Sep 17 00:00:00 2001 From: "anatoly.shipitz" Date: Thu, 7 Aug 2025 16:39:03 +0200 Subject: [PATCH 2/2] Refactor QBO configuration to remove non-null assertions - Updated the QBO configuration in `qbo.ts` to remove non-null assertions for environment variables, allowing for more flexible handling of undefined values. - This change improves the robustness of the configuration by ensuring that the application can handle cases where environment variables may not be set. These modifications enhance the overall stability of the QBO integration. --- workers/main/src/configs/qbo.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/workers/main/src/configs/qbo.ts b/workers/main/src/configs/qbo.ts index 06418f5b..3dd24144 100644 --- a/workers/main/src/configs/qbo.ts +++ b/workers/main/src/configs/qbo.ts @@ -1,13 +1,13 @@ import { z } from 'zod'; export const qboConfig = { - apiUrl: process.env.QBO_API_URL!, + apiUrl: process.env.QBO_API_URL, bearerToken: process.env.QBO_BEARER_TOKEN, // OAuth2 configuration - clientId: process.env.QBO_CLIENT_ID!, - clientSecret: process.env.QBO_CLIENT_SECRET!, - companyId: process.env.QBO_COMPANY_ID!, - refreshToken: process.env.QBO_REFRESH_TOKEN!, + clientId: process.env.QBO_CLIENT_ID, + clientSecret: process.env.QBO_CLIENT_SECRET, + companyId: process.env.QBO_COMPANY_ID, + refreshToken: process.env.QBO_REFRESH_TOKEN, tokenHost: 'https://oauth.platform.intuit.com', tokenPath: '/oauth2/v1/tokens/bearer', tokenExpirationWindowSeconds: 300,