From 19fad93d040a80c1046481b233935522a31197a0 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Fri, 8 Nov 2024 05:45:53 +0000 Subject: [PATCH] fix: set content type when uploading edited template --- .../TemplateVersionEditorPage.test.tsx | 22 +++++++++++++++++++ .../TemplateVersionEditorPage.tsx | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx b/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx index 2cb97396a2f60..07b1485eef770 100644 --- a/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx +++ b/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx @@ -226,6 +226,28 @@ test("Patch request is not send when there are no changes", async () => { expect(patchTemplateVersion).toBeCalledTimes(0); }); +test("The file is uploaded with the correct content type", async () => { + const user = userEvent.setup(); + renderTemplateEditorPage(); + const topbar = await screen.findByTestId("topbar"); + + const newTemplateVersion = { + ...MockTemplateVersion, + id: "new-version-id", + name: "new-version", + }; + + await typeOnEditor("new content", user); + await buildTemplateVersion(newTemplateVersion, user, topbar); + + expect(API.uploadFile).toHaveBeenCalledWith( + expect.objectContaining({ + name: "template.tar", + type: "application/x-tar", + }), + ); +}); + describe.each([ { testName: "Do not ask when template version has no errors", diff --git a/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx b/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx index cf74c0b099ecf..b3090eb6d3f47 100644 --- a/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx +++ b/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx @@ -329,7 +329,7 @@ const generateVersionFiles = async ( tar.addFolder(fullPath, baseFileInfo); }); const blob = (await tar.write()) as Blob; - return new File([blob], "template.tar"); + return new File([blob], "template.tar", { type: "application/x-tar" }); }; const publishVersion = async (options: {