@@ -493,9 +493,12 @@ void main() {
493
493
for (final (ChannelPostPolicy policy, UserRole role, bool canPost) in testCases) {
494
494
test ('"${role .name }" user ${canPost ? 'can' : "can't" } post in channel '
495
495
'with "${policy .name }" policy' , () {
496
- final store = eg.store ();
497
- final actual = store.hasPostingPermission (
498
- inChannel: eg.stream (channelPostPolicy: policy), user: eg.user (role: role),
496
+ final selfUserWithRole = eg.user (role: role);
497
+ final store = eg.store (
498
+ selfUser: selfUserWithRole,
499
+ initialSnapshot: eg.initialSnapshot (realmUsers: [selfUserWithRole]));
500
+ final actual = store.selfCanSendMessage (
501
+ inChannel: eg.stream (channelPostPolicy: policy),
499
502
// [byDate] is not actually relevant for these test cases; for the
500
503
// ones which it is, they're practiced below.
501
504
byDate: DateTime .now ());
@@ -504,27 +507,34 @@ void main() {
504
507
}
505
508
506
509
group ('"member" user posting in a channel with "fullMembers" policy' , () {
507
- PerAccountStore localStore ({required int realmWaitingPeriodThreshold}) =>
508
- eg.store (initialSnapshot: eg.initialSnapshot (
509
- realmWaitingPeriodThreshold: realmWaitingPeriodThreshold));
510
+ PerAccountStore localStore ({
511
+ required User selfUser,
512
+ required int realmWaitingPeriodThreshold,
513
+ }) => eg.store (
514
+ selfUser: selfUser,
515
+ initialSnapshot: eg.initialSnapshot (
516
+ realmWaitingPeriodThreshold: realmWaitingPeriodThreshold,
517
+ realmUsers: [selfUser]));
510
518
511
519
User memberUser ({required String dateJoined}) => eg.user (
512
520
role: UserRole .member, dateJoined: dateJoined);
513
521
514
522
test ('a "full" member -> can post in the channel' , () {
515
- final store = localStore (realmWaitingPeriodThreshold: 3 );
516
- final hasPermission = store.hasPostingPermission (
523
+ final store = localStore (
524
+ selfUser: memberUser (dateJoined: '2024-11-25T10:00+00:00' ),
525
+ realmWaitingPeriodThreshold: 3 );
526
+ final hasPermission = store.selfCanSendMessage (
517
527
inChannel: eg.stream (channelPostPolicy: ChannelPostPolicy .fullMembers),
518
- user: memberUser (dateJoined: '2024-11-25T10:00+00:00' ),
519
528
byDate: DateTime .utc (2024 , 11 , 28 , 10 , 00 ));
520
529
check (hasPermission).isTrue ();
521
530
});
522
531
523
532
test ('not a "full" member -> cannot post in the channel' , () {
524
- final store = localStore (realmWaitingPeriodThreshold: 3 );
525
- final actual = store.hasPostingPermission (
533
+ final store = localStore (
534
+ selfUser: memberUser (dateJoined: '2024-11-25T10:00+00:00' ),
535
+ realmWaitingPeriodThreshold: 3 );
536
+ final actual = store.selfCanSendMessage (
526
537
inChannel: eg.stream (channelPostPolicy: ChannelPostPolicy .fullMembers),
527
- user: memberUser (dateJoined: '2024-11-25T10:00+00:00' ),
528
538
byDate: DateTime .utc (2024 , 11 , 28 , 09 , 59 ));
529
539
check (actual).isFalse ();
530
540
});
0 commit comments