-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: unit tests for polling #1353
base: main
Are you sure you want to change the base?
Conversation
accountId: number, | ||
taskId: number | string | ||
) => HubSpotPromise<T>; | ||
type PollingCallback<T extends GenericPollingResponse> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the signature of the callback so we could simplify the arguments in poll
. This makes the polling function more generic so it can be more easily leveraged in other places.
FAILURE: 'FAILURE', | ||
} as const; | ||
|
||
const DEFAULT_POLLING_STATUS_LOOKUP = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lookup will enable this polling func to be used for other apis, even if their status enums are slightly different from the default ones here. The only requirement in the polling util now is that the callback response needs to include a status
field.
import { POLLING_DELAY, POLLING_STATUS } from './constants'; | ||
import { DEFAULT_POLLING_DELAY } from './constants'; | ||
|
||
export const DEFAULT_POLLING_STATES = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this here because it's only relevant to this file
const pollPromise = poll(mockCallback); | ||
|
||
// Fast-forward through two polling intervals | ||
jest.advanceTimersByTime(DEFAULT_POLLING_DELAY * 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor came up with the idea to use advanceTimersByTime
, but it's a cool way to test utils that leverage setTimeout. This gives us control over each execution of the setTimeout in poll(). So we can iterate over the mock responses one at a time.
Description and Context
Adding tests for lib/polling. I also made some changes to make the polling function more generic and easier to test. I'll add more context inline.
Screenshots
TODO
Who to Notify