Skip to content

Commit d32428b

Browse files
authored
Fix Observer Alert list (#2925)
refs: MBL-17893 affects: Parent release note: Fixed alert list not refreshing after an alert is read or dismissed.
1 parent 8a720cc commit d32428b

23 files changed

+680
-211
lines changed

Core/Core/ObserverAlerts/APIObserverAlert.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,3 @@ extension APIObserverAlert {
6767
}
6868
}
6969
#endif
70-
71-
// Not documented
72-
public struct GetObserverAlertsRequest: APIRequestable {
73-
public typealias Response = [APIObserverAlert]
74-
75-
public let studentID: String
76-
public var path: String { "users/self/observer_alerts/\(studentID)" }
77-
public var query: [APIQueryItem] { [ .perPage(100) ] }
78-
}
79-
80-
// Not documented
81-
public struct MarkObserverAlertReadRequest: APIRequestable {
82-
public typealias Response = APIObserverAlert
83-
84-
public let alertID: String
85-
public var method: APIMethod { .put }
86-
public var path: String { "users/self/observer_alerts/\(alertID)/read" }
87-
}
88-
89-
// Not documented
90-
public struct DismissObserverAlertRequest: APIRequestable {
91-
public typealias Response = APIObserverAlert
92-
93-
public let alertID: String
94-
public var method: APIMethod { .put }
95-
public var path: String { "users/self/observer_alerts/\(alertID)/dismissed" }
96-
}

Core/Core/ObserverAlerts/GetObserverAlerts.swift

Lines changed: 0 additions & 68 deletions
This file was deleted.

Core/Core/ObserverAlerts/ObserverAlert.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public final class ObserverAlert: NSManagedObject {
4747
set { workflowStateRaw = newValue.rawValue }
4848
}
4949

50+
public var isUnread: Bool {
51+
workflowState == .unread
52+
}
53+
5054
public var courseID: String? {
5155
switch alertType {
5256
case .courseGradeHigh, .courseGradeLow:

Core/CoreTests/ObserverAlerts/ObserverAlertTests.swift

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,50 @@ import XCTest
2121
import TestsFoundation
2222

2323
class ObserverAlertTests: CoreTestCase {
24-
func testProperties() {
24+
25+
private var alert: ObserverAlert!
26+
27+
override func setUp() {
28+
super.setUp()
2529
let alert: ObserverAlert = databaseClient.insert()
30+
self.alert = alert
31+
}
32+
33+
override func tearDown() {
34+
alert = nil
35+
super.tearDown()
36+
}
37+
38+
func testAlertType() {
2639
alert.alertTypeRaw = "bogus"
2740
XCTAssertEqual(alert.alertType, .institutionAnnouncement)
28-
alert.alertType = .courseAnnouncement
41+
42+
alert.alertTypeRaw = "course_announcement"
2943
XCTAssertEqual(alert.alertType, .courseAnnouncement)
3044

45+
alert.alertType = .assignmentMissing
46+
XCTAssertEqual(alert.alertTypeRaw, "assignment_missing")
47+
}
48+
49+
func testWorkflowState() {
3150
alert.workflowStateRaw = "bogus"
3251
XCTAssertEqual(alert.workflowState, .unread)
33-
alert.workflowState = .dismissed
52+
XCTAssertEqual(alert.isUnread, true)
53+
54+
alert.workflowStateRaw = "dismissed"
3455
XCTAssertEqual(alert.workflowState, .dismissed)
56+
XCTAssertEqual(alert.isUnread, false)
57+
58+
alert.workflowState = .read
59+
XCTAssertEqual(alert.workflowStateRaw, "read")
60+
XCTAssertEqual(alert.isUnread, false)
3561
}
3662

3763
func testLockedForUserDefaultValue() {
38-
let alert: ObserverAlert = databaseClient.insert()
3964
XCTAssertEqual(alert.lockedForUser, false)
4065
}
4166

4267
func testLockedForUserAPIMapping() {
43-
let alert: ObserverAlert = databaseClient.insert()
4468
alert.id = "testId"
4569

4670
ObserverAlert.save(.make(id: "testId", locked_for_user: nil), in: databaseClient)
@@ -54,7 +78,6 @@ class ObserverAlertTests: CoreTestCase {
5478
}
5579

5680
func testCourseID() {
57-
let alert: ObserverAlert = databaseClient.insert()
5881
alert.contextID = "contextID"
5982
alert.htmlURL = URL(string: "https://test.com/courses/courseID/assignments/1434231")!
6083

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// This file is part of Canvas.
3+
// Copyright (C) 2024-present Instructure, Inc.
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as
7+
// published by the Free Software Foundation, either version 3 of the
8+
// License, or (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
//
18+
19+
import Foundation
20+
import XCTest
21+
@testable import Core
22+
23+
extension API {
24+
25+
@discardableResult
26+
public func mock<Request: APIRequestable>(
27+
_ request: Request,
28+
expectation: XCTestExpectation,
29+
value: Request.Response? = nil,
30+
response: URLResponse? = nil,
31+
error: Error? = nil
32+
) -> APIMock {
33+
mock(request) { _ in
34+
expectation.fulfill()
35+
return (value, response, error)
36+
}
37+
}
38+
39+
@discardableResult
40+
public func mock<U: APIUseCase>(
41+
_ useCase: U,
42+
expectation: XCTestExpectation,
43+
value: U.Request.Response? = nil,
44+
response: URLResponse? = nil,
45+
error: Error? = nil
46+
) -> APIMock {
47+
mock(useCase.request, expectation: expectation, value: value, response: response, error: error)
48+
}
49+
}

0 commit comments

Comments
 (0)