@@ -14,13 +14,13 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- import { stubClient } from "./test-utils" ;
17+ import { advanceDateAndTime , stubClient } from "./test-utils" ;
1818import { MatrixClientPeg as peg } from "../src/MatrixClientPeg" ;
1919
2020describe ( "MatrixClientPeg" , ( ) => {
2121 afterEach ( ( ) => {
22- ( peg as any ) . registrationTime = undefined ;
23- ( peg as any ) . registrationTimeUser = undefined ;
22+ localStorage . clear ( ) ;
23+ advanceDateAndTime ( 0 ) ;
2424 } ) ;
2525
2626 it ( "setJustRegisteredUserId" , ( ) => {
@@ -32,6 +32,14 @@ describe("MatrixClientPeg", () => {
3232 expect ( peg . userRegisteredWithinLastHours ( 0 ) ) . toBe ( false ) ;
3333 expect ( peg . userRegisteredWithinLastHours ( 1 ) ) . toBe ( true ) ;
3434 expect ( peg . userRegisteredWithinLastHours ( 24 ) ) . toBe ( true ) ;
35+ advanceDateAndTime ( 1 * 60 * 60 * 1000 ) ;
36+ expect ( peg . userRegisteredWithinLastHours ( 0 ) ) . toBe ( false ) ;
37+ expect ( peg . userRegisteredWithinLastHours ( 1 ) ) . toBe ( false ) ;
38+ expect ( peg . userRegisteredWithinLastHours ( 24 ) ) . toBe ( true ) ;
39+ advanceDateAndTime ( 24 * 60 * 60 * 1000 ) ;
40+ expect ( peg . userRegisteredWithinLastHours ( 0 ) ) . toBe ( false ) ;
41+ expect ( peg . userRegisteredWithinLastHours ( 1 ) ) . toBe ( false ) ;
42+ expect ( peg . userRegisteredWithinLastHours ( 24 ) ) . toBe ( false ) ;
3543 } ) ;
3644
3745 it ( "setJustRegisteredUserId(null)" , ( ) => {
@@ -42,28 +50,9 @@ describe("MatrixClientPeg", () => {
4250 expect ( peg . userRegisteredWithinLastHours ( 0 ) ) . toBe ( false ) ;
4351 expect ( peg . userRegisteredWithinLastHours ( 1 ) ) . toBe ( false ) ;
4452 expect ( peg . userRegisteredWithinLastHours ( 24 ) ) . toBe ( false ) ;
45- } ) ;
46-
47- it ( "multiple users" , ( ) => {
48- stubClient ( ) ;
49- ( peg as any ) . matrixClient = peg . get ( ) ;
50- peg . setJustRegisteredUserId ( "@userId:matrix.rog" ) ;
51- expect ( peg . get ( ) . credentials . userId ) . toBe ( "@userId:matrix.rog" ) ;
52- expect ( peg . currentUserIsJustRegistered ( ) ) . toBe ( true ) ;
53- expect ( peg . userRegisteredWithinLastHours ( 0 ) ) . toBe ( false ) ;
54- expect ( peg . userRegisteredWithinLastHours ( 1 ) ) . toBe ( true ) ;
55- expect ( peg . userRegisteredWithinLastHours ( 24 ) ) . toBe ( true ) ;
56-
57- peg . setJustRegisteredUserId ( "@userId2:matrix.rog" ) ;
58- expect ( peg . currentUserIsJustRegistered ( ) ) . toBe ( false ) ;
53+ advanceDateAndTime ( 1 * 60 * 60 * 1000 ) ;
5954 expect ( peg . userRegisteredWithinLastHours ( 0 ) ) . toBe ( false ) ;
6055 expect ( peg . userRegisteredWithinLastHours ( 1 ) ) . toBe ( false ) ;
6156 expect ( peg . userRegisteredWithinLastHours ( 24 ) ) . toBe ( false ) ;
62-
63- peg . get ( ) . credentials . userId = "@userId2:matrix.rog" ;
64- expect ( peg . currentUserIsJustRegistered ( ) ) . toBe ( true ) ;
65- expect ( peg . userRegisteredWithinLastHours ( 0 ) ) . toBe ( false ) ;
66- expect ( peg . userRegisteredWithinLastHours ( 1 ) ) . toBe ( true ) ;
67- expect ( peg . userRegisteredWithinLastHours ( 24 ) ) . toBe ( true ) ;
6857 } ) ;
6958} ) ;
0 commit comments