2022-04-13 21:05:08 +03:00
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { advanceDateAndTime, stubClient } from "./test-utils";
|
|
|
|
import { MatrixClientPeg as peg } from "../src/MatrixClientPeg";
|
|
|
|
|
2022-04-19 15:44:15 +03:00
|
|
|
jest.useFakeTimers();
|
|
|
|
|
2022-04-13 21:05:08 +03:00
|
|
|
describe("MatrixClientPeg", () => {
|
|
|
|
afterEach(() => {
|
|
|
|
localStorage.clear();
|
2022-04-19 15:44:15 +03:00
|
|
|
jest.restoreAllMocks();
|
2022-04-13 21:05:08 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("setJustRegisteredUserId", () => {
|
|
|
|
stubClient();
|
|
|
|
(peg as any).matrixClient = peg.get();
|
|
|
|
peg.setJustRegisteredUserId("@userId:matrix.rog");
|
|
|
|
expect(peg.get().credentials.userId).toBe("@userId:matrix.rog");
|
|
|
|
expect(peg.currentUserIsJustRegistered()).toBe(true);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(1)).toBe(true);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(24)).toBe(true);
|
2022-04-19 15:44:15 +03:00
|
|
|
advanceDateAndTime(1 * 60 * 60 * 1000 + 1);
|
2022-04-13 21:05:08 +03:00
|
|
|
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(24)).toBe(true);
|
|
|
|
advanceDateAndTime(24 * 60 * 60 * 1000);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(24)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("setJustRegisteredUserId(null)", () => {
|
|
|
|
stubClient();
|
|
|
|
(peg as any).matrixClient = peg.get();
|
|
|
|
peg.setJustRegisteredUserId(null);
|
|
|
|
expect(peg.currentUserIsJustRegistered()).toBe(false);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(24)).toBe(false);
|
2022-04-19 15:44:15 +03:00
|
|
|
advanceDateAndTime(1 * 60 * 60 * 1000 + 1);
|
2022-04-13 21:05:08 +03:00
|
|
|
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
|
|
|
|
expect(peg.userRegisteredWithinLastHours(24)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|