Skip to content

Commit

Permalink
Merge pull request #510 from uploadcare/chore/add-conversion-poller-a…
Browse files Browse the repository at this point in the history
…bort-test

test(react-client): add test to handle CancelError from the conversion job poller
  • Loading branch information
nd0ut authored Jan 17, 2024
2 parents e289696 + 2a1ee94 commit e6df820
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/rest-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export { Problems } from './types/Problems'
export { ServerErrorResponse } from './types/ServerErrorResponse'
export { Webhook } from './types/Webhook'
export { WebhookEvent } from './types/WebhookEvent'
export { StoreValue } from '@uploadcare/api-client-utils'
export { StoreValue, CancelError } from '@uploadcare/api-client-utils'
export { Paginatable } from './types/Paginatable'
export { Md5Function } from './lib/md5/Md5Function'
export {
Expand Down
28 changes: 28 additions & 0 deletions packages/rest-client/src/tools/conversionJobPoller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { testSettings } from '../../test/helpers'
import { ConversionStatus } from '../types/ConversionStatus'
import { ConversionType } from '../types/ConversionType'
import { conversionJobPoller } from './conversionJobPoller'
import { delay } from '@uploadcare/api-client-utils'

jest.setTimeout(60 * 1000)

Expand Down Expand Up @@ -125,4 +126,31 @@ describe('conversionJobPoller', () => {
})
])
})

it('should be able to catch CancelError', async () => {
const path = `${DOCUMENT_UUID}/document/-/format/pdf/`

const abortController = new AbortController()

const promises = await conversionJobPoller(
{
type: ConversionType.DOCUMENT,
paths: [path],
store: false,
pollOptions: {
signal: abortController.signal
}
},
testSettings
)
await delay(0)
abortController.abort()

expect.assertions(3)
expect(promises.length).toBe(1)
await promises[0].catch((err) => {
expect(err.name).toBe('CancelError')
expect(err.isCancel).toBeTrue()
})
})
})

0 comments on commit e6df820

Please sign in to comment.