@@ -63,14 +63,17 @@ final class ConversationMemberJoinEventNotificationBuilderTests: XCTestCase {
6363 let isGroup = true
6464 let isTeam = true
6565
66- await setupMock ( isGroup: isGroup, isTeam: isTeam)
66+ await setupMock ( isGroup: isGroup, isTeam: isTeam, participants : [ ] )
6767
6868 sut = ConversationMemberJoinEventNotificationBuilder (
6969 context: . init(
7070 conversationLocalStore: conversationLocalStore,
7171 userLocalStore: userLocalStore
7272 ) ,
73- validator: . init( userLocalStore: userLocalStore)
73+ validator: . init(
74+ userLocalStore: userLocalStore,
75+ conversationLocalStore: conversationLocalStore
76+ )
7477 )
7578
7679 // When
@@ -91,14 +94,17 @@ final class ConversationMemberJoinEventNotificationBuilderTests: XCTestCase {
9194 let isGroup = true
9295 let isTeam = false
9396
94- await setupMock ( isGroup: isGroup, isTeam: isTeam)
97+ await setupMock ( isGroup: isGroup, isTeam: isTeam, participants : [ ] )
9598
9699 sut = ConversationMemberJoinEventNotificationBuilder (
97100 context: . init(
98101 conversationLocalStore: conversationLocalStore,
99102 userLocalStore: userLocalStore
100103 ) ,
101- validator: . init( userLocalStore: userLocalStore)
104+ validator: . init(
105+ userLocalStore: userLocalStore,
106+ conversationLocalStore: conversationLocalStore
107+ )
102108 )
103109
104110 // When
@@ -119,14 +125,17 @@ final class ConversationMemberJoinEventNotificationBuilderTests: XCTestCase {
119125 let isGroup = false
120126 let isTeam = true
121127
122- await setupMock ( isGroup: isGroup, isTeam: isTeam)
128+ await setupMock ( isGroup: isGroup, isTeam: isTeam, participants : [ ] )
123129
124130 sut = ConversationMemberJoinEventNotificationBuilder (
125131 context: . init(
126132 conversationLocalStore: conversationLocalStore,
127133 userLocalStore: userLocalStore
128134 ) ,
129- validator: . init( userLocalStore: userLocalStore)
135+ validator: . init(
136+ userLocalStore: userLocalStore,
137+ conversationLocalStore: conversationLocalStore
138+ )
130139 )
131140
132141 // When
@@ -142,20 +151,22 @@ final class ConversationMemberJoinEventNotificationBuilderTests: XCTestCase {
142151 }
143152
144153 func testGenerateConversationMemberJoinEventNotification_It_Should_Not_Build_Notification( ) async throws {
145-
146154 // Mock
147155
148156 let isGroup = false
149157 let isTeam = true
150158
151- await setupMock ( isGroup: isGroup, isTeam: isTeam)
159+ await setupMock ( isGroup: isGroup, isTeam: isTeam, participants : [ ] )
152160
153161 sut = ConversationMemberJoinEventNotificationBuilder (
154162 context: . init(
155163 conversationLocalStore: conversationLocalStore,
156164 userLocalStore: userLocalStore
157165 ) ,
158- validator: . init( userLocalStore: userLocalStore)
166+ validator: . init(
167+ userLocalStore: userLocalStore,
168+ conversationLocalStore: conversationLocalStore
169+ )
159170 )
160171
161172 // When
@@ -165,6 +176,33 @@ final class ConversationMemberJoinEventNotificationBuilderTests: XCTestCase {
165176 XCTAssertNil ( userNotification)
166177 }
167178
179+ func test_ItDoesNotCreateNotification_WhenSelfUserIsAlreadyParticipant( ) async throws {
180+ // Given
181+ let selfUser = await context. perform { [ modelHelper, context] in
182+ modelHelper. createSelfUser ( id: Scaffolding . selfUserID, in: context)
183+ }
184+
185+ // Mock
186+ await setupMock ( isGroup: true , isTeam: false , participants: [ selfUser] )
187+
188+ sut = ConversationMemberJoinEventNotificationBuilder (
189+ context: . init(
190+ conversationLocalStore: conversationLocalStore,
191+ userLocalStore: userLocalStore
192+ ) ,
193+ validator: . init(
194+ userLocalStore: userLocalStore,
195+ conversationLocalStore: conversationLocalStore
196+ )
197+ )
198+
199+ // When
200+ let userNotification = await sut. buildContent ( event: Scaffolding . selfUserAddedEvent)
201+
202+ // Then: should NOT create notification
203+ XCTAssertNil ( userNotification, " Should not create notification when self user is already a participant " )
204+ }
205+
168206 private func internalTest_assertNotificationContent(
169207 _ userNotification: UserNotification ,
170208 isGroup: Bool ,
@@ -219,20 +257,22 @@ final class ConversationMemberJoinEventNotificationBuilderTests: XCTestCase {
219257 XCTAssertEqual ( notificationContent. userInfo [ " conversationIDString " ] as! String , UUID . mockID2. uuidString)
220258 }
221259
222- private func setupMock( isGroup: Bool , isTeam: Bool ) async {
223- let conversation = await context. perform { [ self ] in
260+ private func setupMock( isGroup: Bool , isTeam: Bool , participants : Set < ZMUser > ) async {
261+ let conversation = await context. perform { [ modelHelper , context ] in
224262 modelHelper. createGroupConversation ( in: context)
225263 }
226264 conversationLocalStore. fetchOrCreateConversationIdDomain_MockValue = conversation
265+ conversationLocalStore. fetchConversationIdDomain_MockValue = conversation
266+ conversationLocalStore. localParticipantsIn_MockValue = participants
227267 conversationLocalStore. conversationMutedMessageTypesIncludingAvailability_MockValue = . some( . none)
228268 conversationLocalStore. lastReadServerTimestamp_MockValue = . now
229- userLocalStore. fetchOrCreateUserIdDomain_MockValue = await context. perform { [ self ] in
269+ userLocalStore. fetchOrCreateUserIdDomain_MockValue = await context. perform { [ modelHelper , context ] in
230270 modelHelper. createUser ( in: context)
231271 }
232272 userLocalStore. nameFor_MockValue = Scaffolding . senderName
233273 conversationLocalStore. nameFor_MockValue = Scaffolding . conversationName
234274 conversationLocalStore. isGroupConversation_MockValue = isGroup
235- userLocalStore. fetchSelfUser_MockValue = await context. perform { [ self ] in
275+ userLocalStore. fetchSelfUser_MockValue = await context. perform { [ modelHelper , context ] in
236276 modelHelper. createSelfUser ( id: Scaffolding . selfUserID, in: context)
237277 }
238278 conversationLocalStore. isConversationForcedReadOnly_MockValue = false
@@ -295,5 +335,4 @@ final class ConversationMemberJoinEventNotificationBuilderTests: XCTestCase {
295335 mutedReference: nil
296336 )
297337 }
298-
299338}
0 commit comments