@@ -2,6 +2,7 @@ import 'dart:async';
2
2
import 'dart:io' ;
3
3
4
4
import 'package:checks/checks.dart' ;
5
+ import 'package:clock/clock.dart' ;
5
6
import 'package:fake_async/fake_async.dart' ;
6
7
import 'package:flutter/foundation.dart' ;
7
8
import 'package:http/http.dart' as http;
@@ -480,9 +481,11 @@ void main() {
480
481
for (final (String dateJoined, DateTime currentDate, bool hasPassedWaitingPeriod) in testCases) {
481
482
test ('user joined at $dateJoined ${hasPassedWaitingPeriod ? 'has' : "hasn't" } '
482
483
'passed waiting period by $currentDate ' , () {
483
- final user = eg.user (dateJoined: dateJoined);
484
- check (store.hasPassedWaitingPeriod (user, byDate: currentDate))
485
- .equals (hasPassedWaitingPeriod);
484
+ withClock (Clock .fixed (currentDate), () {
485
+ final user = eg.user (dateJoined: dateJoined);
486
+ check (store.hasPassedWaitingPeriod (user))
487
+ .equals (hasPassedWaitingPeriod);
488
+ });
486
489
});
487
490
}
488
491
});
@@ -526,11 +529,10 @@ void main() {
526
529
test ('"${role .name }" user ${canPost ? 'can' : "can't" } post in channel '
527
530
'with "${policy .name }" policy' , () {
528
531
final store = eg.store ();
532
+ // we don't use `withClock` because current time is not actually relevant for
533
+ // these test cases; for the ones which it is, they're practiced below.
529
534
final actual = store.hasPostingPermission (
530
- inChannel: eg.stream (channelPostPolicy: policy), user: eg.user (role: role),
531
- // [byDate] is not actually relevant for these test cases; for the
532
- // ones which it is, they're practiced below.
533
- byDate: DateTime .now ());
535
+ inChannel: eg.stream (channelPostPolicy: policy), user: eg.user (role: role));
534
536
check (actual).equals (canPost);
535
537
});
536
538
}
@@ -544,21 +546,23 @@ void main() {
544
546
role: UserRole .member, dateJoined: dateJoined);
545
547
546
548
test ('a "full" member -> can post in the channel' , () {
547
- final store = localStore (realmWaitingPeriodThreshold: 3 );
548
- final hasPermission = store.hasPostingPermission (
549
- inChannel: eg.stream (channelPostPolicy: ChannelPostPolicy .fullMembers),
550
- user: memberUser (dateJoined: '2024-11-25T10:00+00:00' ),
551
- byDate: DateTime .utc (2024 , 11 , 28 , 10 , 00 ));
552
- check (hasPermission).isTrue ();
549
+ withClock (Clock .fixed (DateTime .utc (2024 , 11 , 28 , 10 , 00 )), () {
550
+ final store = localStore (realmWaitingPeriodThreshold: 3 );
551
+ final hasPermission = store.hasPostingPermission (
552
+ inChannel: eg.stream (channelPostPolicy: ChannelPostPolicy .fullMembers),
553
+ user: memberUser (dateJoined: '2024-11-25T10:00+00:00' ));
554
+ check (hasPermission).isTrue ();
555
+ });
553
556
});
554
557
555
558
test ('not a "full" member -> cannot post in the channel' , () {
556
- final store = localStore (realmWaitingPeriodThreshold: 3 );
557
- final actual = store.hasPostingPermission (
558
- inChannel: eg.stream (channelPostPolicy: ChannelPostPolicy .fullMembers),
559
- user: memberUser (dateJoined: '2024-11-25T10:00+00:00' ),
560
- byDate: DateTime .utc (2024 , 11 , 28 , 09 , 59 ));
561
- check (actual).isFalse ();
559
+ withClock (Clock .fixed (DateTime .utc (2024 , 11 , 28 , 09 , 59 )), () {
560
+ final store = localStore (realmWaitingPeriodThreshold: 3 );
561
+ final actual = store.hasPostingPermission (
562
+ inChannel: eg.stream (channelPostPolicy: ChannelPostPolicy .fullMembers),
563
+ user: memberUser (dateJoined: '2024-11-25T10:00+00:00' ));
564
+ check (actual).isFalse ();
565
+ });
562
566
});
563
567
});
564
568
});
0 commit comments