Skip to content

Commit b948798

Browse files
ethanndicksonstirby
authored andcommitted
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. (cherry picked from commit d2e4969)
1 parent 2fb46f4 commit b948798

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 22 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy