Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2e4969

Browse files
fix: set content type when uploading edited template (#15440)
Fixes a bug where a file produced by `generateVersionFiles` (as used when uploading a web UI edited template) produced a file where the `type` field was unset. This meant the change in #15410 used the unset type value as the content header when uploading, causing it to always fail.
1 parent f769456 commit d2e4969

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,28 @@ test("Patch request is not send when there are no changes", async () => {
226226
expect(patchTemplateVersion).toBeCalledTimes(0);
227227
});
228228

229+
test("The file is uploaded with the correct content type", async () => {
230+
const user = userEvent.setup();
231+
renderTemplateEditorPage();
232+
const topbar = await screen.findByTestId("topbar");
233+
234+
const newTemplateVersion = {
235+
...MockTemplateVersion,
236+
id: "new-version-id",
237+
name: "new-version",
238+
};
239+
240+
await typeOnEditor("new content", user);
241+
await buildTemplateVersion(newTemplateVersion, user, topbar);
242+
243+
expect(API.uploadFile).toHaveBeenCalledWith(
244+
expect.objectContaining({
245+
name: "template.tar",
246+
type: "application/x-tar",
247+
}),
248+
);
249+
});
250+
229251
describe.each([
230252
{
231253
testName: "Do not ask when template version has no errors",

site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ const generateVersionFiles = async (
329329
tar.addFolder(fullPath, baseFileInfo);
330330
});
331331
const blob = (await tar.write()) as Blob;
332-
return new File([blob], "template.tar");
332+
return new File([blob], "template.tar", { type: "application/x-tar" });
333333
};
334334

335335
const publishVersion = async (options: {

0 commit comments

Comments
 (0)