forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
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
315a132
commit 312bb08
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
packages/client-linkedin/__tests__/get-random-integer.test.ts
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { getRandomInteger } from '../src/helpers/get-random-integer'; | ||
|
||
describe('getRandomInteger', () => { | ||
it('should return a number between min and max inclusive', () => { | ||
const min = 1; | ||
const max = 10; | ||
const result = getRandomInteger(min, max); | ||
|
||
expect(result).toBeGreaterThanOrEqual(min); | ||
expect(result).toBeLessThanOrEqual(max); | ||
expect(Number.isInteger(result)).toBe(true); | ||
}); | ||
|
||
it('should work with same min and max values', () => { | ||
const result = getRandomInteger(5, 5); | ||
expect(result).toBe(5); | ||
}); | ||
|
||
it('should throw error when min is greater than max', () => { | ||
expect(() => getRandomInteger(10, 1)).toThrow('Min value cannot be greater than max value'); | ||
}); | ||
|
||
it('should throw error for NaN values', () => { | ||
expect(() => getRandomInteger(NaN, 10)).toThrow('Invalid range: min and max must be valid numbers'); | ||
expect(() => getRandomInteger(1, NaN)).toThrow('Invalid range: min and max must be valid numbers'); | ||
expect(() => getRandomInteger(NaN, NaN)).toThrow('Invalid range: min and max must be valid numbers'); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
packages/client-linkedin/__tests__/prepare-axios-error-message.test.ts
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { AxiosError } from 'axios'; | ||
import { prepareAxiosErrorMessage } from '../src/helpers/prepare-axios-error-message'; | ||
|
||
describe('prepareAxiosErrorMessage', () => { | ||
it('should format error with all fields', () => { | ||
const mockError = new AxiosError( | ||
'Network Error', | ||
'ERR_NETWORK', | ||
undefined, | ||
undefined, | ||
{ | ||
status: 404, | ||
data: { error: 'Not Found' }, | ||
} as any | ||
); | ||
|
||
const result = prepareAxiosErrorMessage(mockError); | ||
const parsed = JSON.parse(result); | ||
|
||
expect(parsed).toEqual({ | ||
message: 'Network Error', | ||
status: 404, | ||
data: { error: 'Not Found' }, | ||
code: 'ERR_NETWORK' | ||
}); | ||
}); | ||
|
||
it('should handle error without response data', () => { | ||
const mockError = new AxiosError( | ||
'Timeout Error', | ||
'ECONNABORTED' | ||
); | ||
|
||
const result = prepareAxiosErrorMessage(mockError); | ||
const parsed = JSON.parse(result); | ||
|
||
expect(parsed).toEqual({ | ||
message: 'Timeout Error', | ||
status: undefined, | ||
data: undefined, | ||
code: 'ECONNABORTED' | ||
}); | ||
}); | ||
}); |