Skip to content

Commit

Permalink
PM-17627: Reset send expiration to deletion date on edit (#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-livefront authored Jan 30, 2025
1 parent b9ffb2d commit 68314d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ extension AddEditSendItemState {
/// Returns a `SendView` based on the properties of the `AddEditSendItemState`.
///
func newSendView() -> SendView {
SendView(
let deletionDate = deletionDate.calculateDate() ?? Date()
return SendView(
id: id,
accessId: accessId,
name: name,
Expand All @@ -186,8 +187,10 @@ extension AddEditSendItemState {
disabled: isDeactivateThisSendOn,
hideEmail: isHideMyEmailOn,
revisionDate: Date(),
deletionDate: deletionDate.calculateDate() ?? Date(),
expirationDate: expirationDate
deletionDate: deletionDate,
// If the send has an expiration date, reset it to the deletion date to prevent a server
// error which disallows editing a send after it has expired.
expirationDate: expirationDate != nil ? deletionDate : nil
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,22 @@ class AddEditSendItemStateTests: BitwardenTestCase {
XCTAssertEqual(sendView.expirationDate, nil)
}

/// `newSendView()` sets the expiration date to the deletion date if the expiration date isn't
/// `nil` to allow editing an expired send.
func test_newSendView_text_expired() {
let deletionDate = Date(year: 2024, month: 1, day: 2)
let subject = AddEditSendItemState(
customDeletionDate: deletionDate,
deletionDate: .custom(deletionDate),
expirationDate: .distantPast
)
let sendView = subject.newSendView()
XCTAssertEqual(sendView.deletionDate, deletionDate)
XCTAssertEqual(sendView.expirationDate, deletionDate)
}

func init_sendView_text() {
let deletionDate = Date(year: 2023, month: 11, day: 5, hour: 9, minute: 41, second: 11)
let sendView = SendView.fixture(
id: "ID",
accessId: "ACCESS_ID",
Expand All @@ -92,7 +107,7 @@ class AddEditSendItemStateTests: BitwardenTestCase {
disabled: false,
hideEmail: false,
revisionDate: Date(year: 2023, month: 11, day: 5, hour: 9, minute: 41, second: 0),
deletionDate: Date(year: 2023, month: 11, day: 5, hour: 9, minute: 41, second: 11),
deletionDate: deletionDate,
expirationDate: Date(year: 2023, month: 11, day: 5, hour: 9, minute: 41, second: 22)
)
let subject = AddEditSendItemState(sendView: sendView, hasPremium: true)
Expand All @@ -113,14 +128,8 @@ class AddEditSendItemStateTests: BitwardenTestCase {
XCTAssertEqual(subject.currentAccessCount, 42)
XCTAssertEqual(subject.isDeactivateThisSendOn, false)
XCTAssertEqual(subject.isHideMyEmailOn, false)
XCTAssertEqual(
subject.customDeletionDate,
Date(year: 2023, month: 11, day: 5, hour: 9, minute: 41, second: 11)
)
XCTAssertEqual(
subject.expirationDate,
Date(year: 2023, month: 11, day: 5, hour: 9, minute: 41, second: 22)
)
XCTAssertEqual(subject.customDeletionDate, deletionDate)
XCTAssertEqual(subject.expirationDate, deletionDate)
}

func init_sendView_file() {
Expand Down

0 comments on commit 68314d3

Please sign in to comment.