@@ -4326,6 +4326,86 @@ final class ChannelController_Tests: XCTestCase {
43264326 XCTAssertEqual ( updater. markUnread_lastReadMessageId, previousMessageId)
43274327 XCTAssertEqual ( updater. markUnread_criteria, MarkUnreadCriteria . messageId ( messageId) )
43284328 }
4329+
4330+ func test_markUnread_whenChannelDoesNotExist_messageTimestamp( ) {
4331+ var receivedError : Error ?
4332+ let expectation = self . expectation ( description: " Mark Unread completes " )
4333+ controller. markUnread ( from: Date ( ) ) { result in
4334+ receivedError = result. error
4335+ expectation. fulfill ( )
4336+ }
4337+
4338+ waitForExpectations ( timeout: defaultTimeout)
4339+
4340+ XCTAssertTrue ( receivedError is ClientError . ChannelNotCreatedYet )
4341+ }
4342+
4343+ func test_markUnread_whenReadEventsAreNotEnabled_messageTimestamp( ) throws {
4344+ let channel : ChannelPayload = . dummy(
4345+ channel: . dummy( cid: channelId, ownCapabilities: [ ] )
4346+ )
4347+
4348+ writeAndWaitForMessageUpdates ( count: 0 , channelChanges: true ) { session in
4349+ try session. saveChannel ( payload: channel)
4350+ }
4351+
4352+ var receivedError : Error ?
4353+ let expectation = self . expectation ( description: " Mark Unread completes " )
4354+ controller. markUnread ( from: Date ( ) ) { result in
4355+ receivedError = result. error
4356+ expectation. fulfill ( )
4357+ }
4358+
4359+ waitForExpectations ( timeout: defaultTimeout)
4360+
4361+ XCTAssertTrue ( receivedError is ClientError . ChannelFeatureDisabled )
4362+ }
4363+
4364+ func test_markUnread_whenIsMarkingAsRead_andCurrentUserIdIsPresent_messageTimestamp( ) throws {
4365+ let channel : ChannelPayload = . dummy(
4366+ channel: . dummy( cid: channelId, ownCapabilities: [ ChannelCapability . readEvents. rawValue] )
4367+ )
4368+
4369+ try client. databaseContainer. writeSynchronously { session in
4370+ try session. saveChannel ( payload: channel)
4371+ }
4372+
4373+ let currentUserId = UserId . unique
4374+ client. setToken ( token: . unique( userId: currentUserId) )
4375+ try simulateMarkingAsRead ( userId: currentUserId)
4376+
4377+ var receivedError : Error ?
4378+ let expectation = self . expectation ( description: " Mark Unread completes " )
4379+ controller. markUnread ( from: Date ( ) ) { result in
4380+ receivedError = result. error
4381+ expectation. fulfill ( )
4382+ }
4383+
4384+ waitForExpectations ( timeout: defaultTimeout)
4385+
4386+ XCTAssertNil ( receivedError)
4387+ }
4388+
4389+ func test_markUnread_whenIsNotMarkingAsRead_andCurrentUserIdIsNotPresent_messageTimestamp( ) throws {
4390+ let channel : ChannelPayload = . dummy(
4391+ channel: . dummy( cid: channelId, ownCapabilities: [ ChannelCapability . readEvents. rawValue] )
4392+ )
4393+
4394+ writeAndWaitForMessageUpdates ( count: 0 , channelChanges: true ) { session in
4395+ try session. saveChannel ( payload: channel)
4396+ }
4397+
4398+ var receivedError : Error ?
4399+ let expectation = self . expectation ( description: " Mark Unread completes " )
4400+ controller. markUnread ( from: Date ( ) ) { result in
4401+ receivedError = result. error
4402+ expectation. fulfill ( )
4403+ }
4404+
4405+ waitForExpectations ( timeout: defaultTimeout)
4406+
4407+ XCTAssertNil ( receivedError)
4408+ }
43294409
43304410 // MARK: - Load more channel reads
43314411
0 commit comments