Skip to content

Commit

Permalink
Remove-any
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedAziz-Hammami committed Feb 5, 2025
1 parent d29dcd9 commit b92acc0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
33 changes: 22 additions & 11 deletions backend/src/utils/helpers/validation.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
// eslint-disable-next-line import/prefer-default-export
export function validateType(key: string, value: any, type: string) {
export function validateType(key: string, value: unknown, type: string) {
if (value === undefined || value === null) return `${key} is required.`;
if (type === 'number' && (Number.isNaN(value) || value <= 0)) {
return `${key} must be a valid positive number.`;

if (type === 'number') {
if (typeof value !== 'number' || Number.isNaN(value) || value <= 0) {
return `${key} must be a valid positive number.`;
}
}
if (type === 'boolean' && !['true', 'false', true, false].includes(value)) {
return `${key} must be true or false.`;
if (type === 'boolean') {
if (
value !== 'true' &&
value !== 'false' &&
value !== true &&
value !== false
) {
return `${key} must be true or false.`;
}
}
if (
type === 'string[]' &&
(!Array.isArray(value) ||
value.some((v) => typeof v !== 'string' || v.trim() === ''))
) {
return `${key} must be an array of non-empty strings.`;
if (type === 'string[]') {
if (
!Array.isArray(value) ||
value.some((v) => typeof v !== 'string' || v.trim() === '')
) {
return `${key} must be an array of non-empty strings.`;
}
}
return null;
}
2 changes: 1 addition & 1 deletion backend/test/unit/enrichment-service/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('enrichFromCache', () => {
{ id: '2', user_id: 'leadminer-1', email: '[email protected]' }
];

getCache.mockResolvedValue([{} as any]);
getCache.mockResolvedValue([{} as never]);

const result = await enrichFromCache(getCache, enrichmentsDB, contacts);

Expand Down
7 changes: 4 additions & 3 deletions backend/test/unit/enrichment-service/proxycurl/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ describe('ProxycurlApi', () => {
url: 'https://api.example.com',
apiKey: 'dummy-api-key',
rateLimiter: {
requests: 10,
interval: 200,
requests: 5,
interval: 1000,
maxRetries: 3,
spaced: false
}
Expand Down Expand Up @@ -92,6 +92,7 @@ describe('ProxycurlApi', () => {
lookup_depth: 'superficial',
enrich_profile: 'skip'
};

mockAxiosInstance.get.mockReturnValue({
data: {
email,
Expand All @@ -115,7 +116,7 @@ describe('ProxycurlApi', () => {
const duration = end - start;
const tolerance = 10; // Allow a 10ms margin of error to account for slight timing variations

expect(duration).toBeGreaterThanOrEqual(2000 - tolerance);
expect(duration).toBeGreaterThanOrEqual(1000 - tolerance);
expect(mockAxiosInstance.get).toHaveBeenCalledTimes(10);
});
});
Expand Down
6 changes: 3 additions & 3 deletions backend/test/unit/enrichment-service/thedig/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe('ThedigApi', () => {
url: 'https://api.example.com',
apiToken: 'test-token',
rateLimiter: {
requests: 10,
interval: 200,
requests: 5,
interval: 1000,
spaced: false
}
},
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('ThedigApi', () => {
const duration = end - start;
const tolerance = 10; // Allow a 10ms margin of error to account for slight timing variations

expect(duration).toBeGreaterThanOrEqual(2000 - tolerance);
expect(duration).toBeGreaterThanOrEqual(1000 - tolerance);
expect(mockAxiosInstance.post).toHaveBeenCalledTimes(10);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('VoilanorbertApi', () => {
apiToken: 'testToken',
rateLimiter: {
requests: 5,
interval: 200,
interval: 1000,
spaced: false
}
};
Expand Down Expand Up @@ -96,8 +96,9 @@ describe('VoilanorbertApi', () => {
const tolerance = 10; // Allow a 10ms margin of error to account for slight timing variations

expect(duration).toBeGreaterThanOrEqual(1000 - tolerance);
expect(axios.create().post).toHaveBeenCalledTimes(5);
expect(axios.create().post).toHaveBeenCalledTimes(10);
});

it('should log an error and throw it when the request fails', async () => {
const emails = ['[email protected]'];
const webhook = 'webhook-url';
Expand Down

0 comments on commit b92acc0

Please sign in to comment.