From 07eb16d8ec150781cd5f86a6f4251bcdf77768b8 Mon Sep 17 00:00:00 2001 From: John Harrington <84741727+harr1424@users.noreply.github.com> Date: Tue, 30 Dec 2025 16:12:02 -0700 Subject: [PATCH] respond to review comments --- .../send/commands/create.command.spec.ts | 21 +++++++++++++++++++ .../src/tools/send/commands/create.command.ts | 10 ++------- .../tools/send/commands/edit.command.spec.ts | 2 +- .../src/tools/send/commands/edit.command.ts | 6 ------ .../src/tools/send/models/view/send.view.ts | 7 +------ .../src/tools/send/services/send.service.ts | 2 ++ 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/apps/cli/src/tools/send/commands/create.command.spec.ts b/apps/cli/src/tools/send/commands/create.command.spec.ts index f7cdd58c8a0..f53c71dc345 100644 --- a/apps/cli/src/tools/send/commands/create.command.spec.ts +++ b/apps/cli/src/tools/send/commands/create.command.spec.ts @@ -84,6 +84,9 @@ describe("SendCreateCommand", () => { null, undefined, ); + const savedCall = sendApiService.save.mock.calls[0][0]; + expect(savedCall[0].authType).toBe(AuthType.Email); + expect(savedCall[0].emails).toBe("test@example.com"); }); it("should set authType to Password when password is provided via CLI", async () => { @@ -114,6 +117,8 @@ describe("SendCreateCommand", () => { null as any, "testPassword123", ); + const savedCall = sendApiService.save.mock.calls[0][0]; + expect(savedCall[0].authType).toBe(AuthType.Password); }); it("should set authType to None when neither emails nor password provided", async () => { @@ -138,6 +143,8 @@ describe("SendCreateCommand", () => { expect(response.success).toBe(true); expect(sendService.encrypt).toHaveBeenCalledWith(expect.any(Object), null, undefined); + const savedCall = sendApiService.save.mock.calls[0][0]; + expect(savedCall[0].authType).toBe(AuthType.None); }); it("should return error when both emails and password provided via CLI", async () => { @@ -184,6 +191,9 @@ describe("SendCreateCommand", () => { const response = await command.run(requestJson, {}); expect(response.success).toBe(true); + const savedCall = sendApiService.save.mock.calls[0][0]; + expect(savedCall[0].authType).toBe(AuthType.Email); + expect(savedCall[0].emails).toBe("test@example.com,another@example.com"); }); it("should set authType to Password when password provided in JSON", async () => { @@ -206,6 +216,8 @@ describe("SendCreateCommand", () => { const response = await command.run(requestJson, {}); expect(response.success).toBe(true); + const savedCall = sendApiService.save.mock.calls[0][0]; + expect(savedCall[0].authType).toBe(AuthType.Password); }); it("should return error when both emails and password provided in JSON", async () => { @@ -285,6 +297,9 @@ describe("SendCreateCommand", () => { const response = await command.run(requestJson, cmdOptions); expect(response.success).toBe(true); + const savedCall = sendApiService.save.mock.calls[0][0]; + expect(savedCall[0].authType).toBe(AuthType.Email); + expect(savedCall[0].emails).toBe("cli@example.com"); }); }); @@ -309,6 +324,8 @@ describe("SendCreateCommand", () => { const response = await command.run(requestJson, {}); expect(response.success).toBe(true); + const savedCall = sendApiService.save.mock.calls[0][0]; + expect(savedCall[0].authType).toBe(AuthType.None); }); it("should set authType to None when password is empty string", async () => { @@ -334,6 +351,8 @@ describe("SendCreateCommand", () => { const response = await command.run(requestJson, cmdOptions); expect(response.success).toBe(true); + const savedCall = sendApiService.save.mock.calls[0][0]; + expect(savedCall[0].authType).toBe(AuthType.None); }); it("should set authType to None when password is whitespace only", async () => { @@ -359,6 +378,8 @@ describe("SendCreateCommand", () => { const response = await command.run(requestJson, cmdOptions); expect(response.success).toBe(true); + const savedCall = sendApiService.save.mock.calls[0][0]; + expect(savedCall[0].authType).toBe(AuthType.None); }); }); }); diff --git a/apps/cli/src/tools/send/commands/create.command.ts b/apps/cli/src/tools/send/commands/create.command.ts index 268ff862d4f..b8e3c801310 100644 --- a/apps/cli/src/tools/send/commands/create.command.ts +++ b/apps/cli/src/tools/send/commands/create.command.ts @@ -93,9 +93,9 @@ export class SendCreateCommand { req.maxAccessCount = maxAccessCount; req.emails = emails; - if (emails != null && emails.length > 0) { + if (hasEmails) { req.authType = AuthType.Email; - } else if (password != null && password.trim().length > 0) { + } else if (hasPassword) { req.authType = AuthType.Password; } else { req.authType = AuthType.None; @@ -149,12 +149,6 @@ export class SendCreateCommand { const sendView = SendResponse.toView(req); const [encSend, fileData] = await this.sendService.encrypt(sendView, fileBuffer, password); - // Add dates from template - encSend.deletionDate = sendView.deletionDate; - encSend.expirationDate = sendView.expirationDate; - encSend.emails = emails && emails.join(","); - encSend.authType = req.authType; - await this.sendApiService.save([encSend, fileData]); const newSend = await this.sendService.getFromState(encSend.id); const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId)); diff --git a/apps/cli/src/tools/send/commands/edit.command.spec.ts b/apps/cli/src/tools/send/commands/edit.command.spec.ts index 1ccd9785b1f..b1d57517641 100644 --- a/apps/cli/src/tools/send/commands/edit.command.spec.ts +++ b/apps/cli/src/tools/send/commands/edit.command.spec.ts @@ -177,7 +177,7 @@ describe("SendEditCommand", () => { const requestJson = encodeRequest(requestData); sendService.encrypt.mockResolvedValue([ - { id: mockSendId, authType: AuthType.Password } as any, + { id: mockSendId, authType: AuthType.Email } as any, null as any, ]); sendApiService.save.mockResolvedValue(undefined as any); diff --git a/apps/cli/src/tools/send/commands/edit.command.ts b/apps/cli/src/tools/send/commands/edit.command.ts index 1d49e0ae6c2..e06cbab39b4 100644 --- a/apps/cli/src/tools/send/commands/edit.command.ts +++ b/apps/cli/src/tools/send/commands/edit.command.ts @@ -107,12 +107,6 @@ export class SendEditCommand { try { const [encSend, encFileData] = await this.sendService.encrypt(sendView, null, req.password); - // Add dates from template - encSend.deletionDate = sendView.deletionDate; - encSend.expirationDate = sendView.expirationDate; - encSend.emails = req.emails && req.emails.join(","); - encSend.authType = req.authType; - await this.sendApiService.save([encSend, encFileData]); } catch (e) { return Response.error(e); diff --git a/libs/common/src/tools/send/models/view/send.view.ts b/libs/common/src/tools/send/models/view/send.view.ts index baa2fe9f73b..4dfa21db95f 100644 --- a/libs/common/src/tools/send/models/view/send.view.ts +++ b/libs/common/src/tools/send/models/view/send.view.ts @@ -48,12 +48,7 @@ export class SendView implements View { this.password = s.password; this.hideEmail = s.hideEmail; this.authType = s.authType; - this.emails = s.emails - ? s.emails - .split(",") - .map((e) => e.trim()) - .filter((e) => e) - : []; + this.emails = s.emails ? s.emails.split(",").map((e) => e.trim()) : []; } get urlB64Key(): string { diff --git a/libs/common/src/tools/send/services/send.service.ts b/libs/common/src/tools/send/services/send.service.ts index 810dbc05a2f..4d244579271 100644 --- a/libs/common/src/tools/send/services/send.service.ts +++ b/libs/common/src/tools/send/services/send.service.ts @@ -127,6 +127,8 @@ export class SendService implements InternalSendServiceAbstraction { } } + send.authType = model.authType; + return [send, fileData]; }