Skip to content

Commit

Permalink
Enhance CompleteError in SessionMonitor to include completion date an…
Browse files Browse the repository at this point in the history
…d update related tests
  • Loading branch information
kasianov-mikhail committed Dec 22, 2024
1 parent 4bd5cc4 commit e81d176
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions Sources/Scout/Core/SessionMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,27 @@ extension SessionMonitor {
/// - sessionNotFound: The session to be completed was not found.
/// - alreadyCompleted: The session has already been completed.
///
enum CompleteError: LocalizedError {
enum CompleteError: LocalizedError, Equatable {
case sessionNotFound
case alreadyCompleted
case alreadyCompleted(Date)

var errorDescription: String? {
switch self {
case .sessionNotFound:
return "Session not found"
case .alreadyCompleted:
return "Session already completed"
case .alreadyCompleted(let date):
return "Session already completed on \(date)"
}
}

static func == (lhs: CompleteError, rhs: CompleteError) -> Bool {
switch (lhs, rhs) {
case (.sessionNotFound, .sessionNotFound):
return true
case (.alreadyCompleted, .alreadyCompleted):
return true
default:
return false
}
}
}
Expand All @@ -58,8 +69,8 @@ extension SessionMonitor {
throw CompleteError.sessionNotFound
}

if let _ = session.endDate {
throw CompleteError.alreadyCompleted
if let endDate = session.endDate {
throw CompleteError.alreadyCompleted(endDate)
}

session.endDate = Date()
Expand Down
2 changes: 1 addition & 1 deletion Tests/ScoutTests/Core/SessionMonitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct SessionMonitorTests {
// Then, complete the session
try SessionMonitor.complete(in: context)

#expect(throws: SessionMonitor.CompleteError.alreadyCompleted) {
#expect(throws: SessionMonitor.CompleteError.alreadyCompleted(Date())) {
try SessionMonitor.complete(in: context)
}
}
Expand Down

0 comments on commit e81d176

Please sign in to comment.