Skip to content

Added timeout on POST PDF #927

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

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/network/src/api/pdf/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export interface UploadPdfOptions {
* The PDF file to upload.
*/
pdf: Blob;
/**
* The timeout in milliseconds for the request.
*
* @default 30000
*/
timeout?: number;
}

/**
Expand Down Expand Up @@ -80,7 +86,10 @@ export async function uploadPdf(
config: MonkApiConfig,
dispatch?: Dispatch<MonkGotOneInspectionPdfAction>,
): Promise<MonkApiResponse> {
const kyOptions = getDefaultOptions(config);
const kyOptions = {
...getDefaultOptions(config),
...(!!options.timeout && { timeout: options.timeout }),
};
const formData = await createPdfData(options);
await ky.post(`inspections/${options.id}/pdf`, {
...kyOptions,
Expand Down
12 changes: 12 additions & 0 deletions packages/network/test/api/pdf/requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ describe('pdf requests', () => {
{ type: filetype },
);
});

it('should properly use the timeout if defined', async () => {
const timeout = 60000;
const dispatch = jest.fn();
const options = { ...createPdfMock(), timeout };
await uploadPdf(options, apiConfig, dispatch);
await (ky.post as jest.Mock).mock.results[0].value;
expect(ky.post).toHaveBeenCalledWith(
`inspections/${options.id}/pdf`,
expect.objectContaining({ ...getDefaultOptions(apiConfig), timeout }),
);
});
});

describe('getPdf request', () => {
Expand Down
Loading