-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d29dcd9
commit b92acc0
Showing
5 changed files
with
33 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ describe('VoilanorbertApi', () => { | |
apiToken: 'testToken', | ||
rateLimiter: { | ||
requests: 5, | ||
interval: 200, | ||
interval: 1000, | ||
spaced: false | ||
} | ||
}; | ||
|
@@ -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'; | ||
|