mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
[PM-24229] Preserve existing cipher date fields when using CipherExport.toView (#15993)
* [PM-24229] Ensure existing dates are persisted when using CipherExport.toView * [PM-24229] Test both null and undefined * [PM-24229] Add test for copied date values
This commit is contained in:
44
libs/common/src/models/export/cipher.export.spec.ts
Normal file
44
libs/common/src/models/export/cipher.export.spec.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { CipherExport } from "@bitwarden/common/models/export/cipher.export";
|
||||
import { SecureNoteExport } from "@bitwarden/common/models/export/secure-note.export";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
|
||||
describe("Cipher Export", () => {
|
||||
describe("toView", () => {
|
||||
it.each([[null], [undefined]])(
|
||||
"should preserve existing date values when request dates are nullish (=%p)",
|
||||
(nullishDate) => {
|
||||
const existingView = new CipherView();
|
||||
existingView.creationDate = new Date("2023-01-01T00:00:00Z");
|
||||
existingView.revisionDate = new Date("2023-01-02T00:00:00Z");
|
||||
existingView.deletedDate = new Date("2023-01-03T00:00:00Z");
|
||||
|
||||
const request = CipherExport.template();
|
||||
request.type = CipherType.SecureNote;
|
||||
request.secureNote = SecureNoteExport.template();
|
||||
request.creationDate = nullishDate as any;
|
||||
request.revisionDate = nullishDate as any;
|
||||
request.deletedDate = nullishDate as any;
|
||||
|
||||
const resultView = CipherExport.toView(request, existingView);
|
||||
expect(resultView.creationDate).toEqual(existingView.creationDate);
|
||||
expect(resultView.revisionDate).toEqual(existingView.revisionDate);
|
||||
expect(resultView.deletedDate).toEqual(existingView.deletedDate);
|
||||
},
|
||||
);
|
||||
|
||||
it("should set date values when request dates are provided", () => {
|
||||
const request = CipherExport.template();
|
||||
request.type = CipherType.SecureNote;
|
||||
request.secureNote = SecureNoteExport.template();
|
||||
request.creationDate = new Date("2023-01-01T00:00:00Z");
|
||||
request.revisionDate = new Date("2023-01-02T00:00:00Z");
|
||||
request.deletedDate = new Date("2023-01-03T00:00:00Z");
|
||||
|
||||
const resultView = CipherExport.toView(request);
|
||||
expect(resultView.creationDate).toEqual(request.creationDate);
|
||||
expect(resultView.revisionDate).toEqual(request.revisionDate);
|
||||
expect(resultView.deletedDate).toEqual(request.deletedDate);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -81,9 +81,9 @@ export class CipherExport {
|
||||
view.passwordHistory = req.passwordHistory.map((ph) => PasswordHistoryExport.toView(ph));
|
||||
}
|
||||
|
||||
view.creationDate = req.creationDate ? new Date(req.creationDate) : null;
|
||||
view.revisionDate = req.revisionDate ? new Date(req.revisionDate) : null;
|
||||
view.deletedDate = req.deletedDate ? new Date(req.deletedDate) : null;
|
||||
view.creationDate = req.creationDate ? new Date(req.creationDate) : view.creationDate;
|
||||
view.revisionDate = req.revisionDate ? new Date(req.revisionDate) : view.revisionDate;
|
||||
view.deletedDate = req.deletedDate ? new Date(req.deletedDate) : view.deletedDate;
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user