@@ -269,6 +269,79 @@ void main() {
269
269
}
270
270
});
271
271
272
+ group ('PerAccountStore.hasPostingPermission' , () {
273
+ final testCases = [
274
+ (ChannelPostPolicy .unknown, UserRole .unknown, true ),
275
+ (ChannelPostPolicy .unknown, UserRole .guest, true ),
276
+ (ChannelPostPolicy .unknown, UserRole .member, true ),
277
+ (ChannelPostPolicy .unknown, UserRole .moderator, true ),
278
+ (ChannelPostPolicy .unknown, UserRole .administrator, true ),
279
+ (ChannelPostPolicy .unknown, UserRole .owner, true ),
280
+ (ChannelPostPolicy .any, UserRole .unknown, true ),
281
+ (ChannelPostPolicy .any, UserRole .guest, true ),
282
+ (ChannelPostPolicy .any, UserRole .member, true ),
283
+ (ChannelPostPolicy .any, UserRole .moderator, true ),
284
+ (ChannelPostPolicy .any, UserRole .administrator, true ),
285
+ (ChannelPostPolicy .any, UserRole .owner, true ),
286
+ (ChannelPostPolicy .fullMembers, UserRole .unknown, true ),
287
+ (ChannelPostPolicy .fullMembers, UserRole .guest, false ),
288
+ (ChannelPostPolicy .fullMembers, UserRole .member, true ),
289
+ (ChannelPostPolicy .fullMembers, UserRole .moderator, true ),
290
+ (ChannelPostPolicy .fullMembers, UserRole .administrator, true ),
291
+ (ChannelPostPolicy .fullMembers, UserRole .owner, true ),
292
+ (ChannelPostPolicy .moderators, UserRole .unknown, true ),
293
+ (ChannelPostPolicy .moderators, UserRole .guest, false ),
294
+ (ChannelPostPolicy .moderators, UserRole .member, false ),
295
+ (ChannelPostPolicy .moderators, UserRole .moderator, true ),
296
+ (ChannelPostPolicy .moderators, UserRole .administrator, true ),
297
+ (ChannelPostPolicy .moderators, UserRole .owner, true ),
298
+ (ChannelPostPolicy .administrators, UserRole .unknown, true ),
299
+ (ChannelPostPolicy .administrators, UserRole .guest, false ),
300
+ (ChannelPostPolicy .administrators, UserRole .member, false ),
301
+ (ChannelPostPolicy .administrators, UserRole .moderator, false ),
302
+ (ChannelPostPolicy .administrators, UserRole .administrator, true ),
303
+ (ChannelPostPolicy .administrators, UserRole .owner, true ),
304
+ ];
305
+
306
+ for (final (ChannelPostPolicy policy, UserRole role, bool canPost) in testCases) {
307
+ test ('"${role .name }" user ${canPost ? 'can' : "can't" } post in channel '
308
+ 'with "${policy .name }" policy' , () {
309
+ final store = eg.store ();
310
+ final actual = store.hasPostingPermission (
311
+ inChannel: eg.stream (channelPostPolicy: policy),
312
+ user: eg.user (role: role), byDate: DateTime .now ());
313
+ check (actual).equals (canPost);
314
+ });
315
+ }
316
+
317
+ group ('"member" user posting in a channel with "fullMembers" policy' , () {
318
+ PerAccountStore localStore ({required int realmWaitingPeriodThreshold}) =>
319
+ eg.store (initialSnapshot: eg.initialSnapshot (
320
+ realmWaitingPeriodThreshold: realmWaitingPeriodThreshold));
321
+
322
+ User memberUser ({required String dateJoined}) => eg.user (
323
+ role: UserRole .member, dateJoined: dateJoined);
324
+
325
+ test ('a "full" member -> can post in the channel' , () {
326
+ final store = localStore (realmWaitingPeriodThreshold: 3 );
327
+ final hasPermission = store.hasPostingPermission (
328
+ inChannel: eg.stream (channelPostPolicy: ChannelPostPolicy .fullMembers),
329
+ user: memberUser (dateJoined: '2024-11-25T10:00+00:00' ),
330
+ byDate: DateTime .utc (2024 , 11 , 28 , 10 , 00 ));
331
+ check (hasPermission).isTrue ();
332
+ });
333
+
334
+ test ('not a "full" member -> cannot post in the channel' , () {
335
+ final store = localStore (realmWaitingPeriodThreshold: 3 );
336
+ final actual = store.hasPostingPermission (
337
+ inChannel: eg.stream (channelPostPolicy: ChannelPostPolicy .fullMembers),
338
+ user: memberUser (dateJoined: '2024-11-25T10:00+00:00' ),
339
+ byDate: DateTime .utc (2024 , 11 , 28 , 09 , 59 ));
340
+ check (actual).isFalse ();
341
+ });
342
+ });
343
+ });
344
+
272
345
group ('PerAccountStore.handleEvent' , () {
273
346
// Mostly this method just dispatches to ChannelStore and MessageStore etc.,
274
347
// and so most of the tests live in the test files for those
0 commit comments