summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar <oskar@mullvad.net>2025-09-10 21:10:34 +0200
committerOskar <oskar@mullvad.net>2025-10-01 13:19:43 +0200
commit74572bc7b30398fef4110e8f1ade9b37fb44ef96 (patch)
tree4a4c7c9b3bae0344e26cdae0745ecf03fb928f2f
parent7724c526337c35c5b57890459a8f74877727821e (diff)
downloadmullvadvpn-74572bc7b30398fef4110e8f1ade9b37fb44ef96.tar.xz
mullvadvpn-74572bc7b30398fef4110e8f1ade9b37fb44ef96.zip
Add expiry and add time tests
-rw-r--r--desktop/packages/mullvad-vpn/test/e2e/mocked/account-expiry.spec.ts137
1 files changed, 137 insertions, 0 deletions
diff --git a/desktop/packages/mullvad-vpn/test/e2e/mocked/account-expiry.spec.ts b/desktop/packages/mullvad-vpn/test/e2e/mocked/account-expiry.spec.ts
new file mode 100644
index 0000000000..663f122b85
--- /dev/null
+++ b/desktop/packages/mullvad-vpn/test/e2e/mocked/account-expiry.spec.ts
@@ -0,0 +1,137 @@
+import { test } from '@playwright/test';
+import { Page } from 'playwright';
+
+import { RoutesObjectModel } from '../route-object-models';
+import { MockedTestUtils, startMockedApp } from './mocked-utils';
+
+let page: Page;
+let util: MockedTestUtils;
+let routes: RoutesObjectModel;
+
+const START_DATE = new Date('2025-01-01T13:37:00');
+
+const CLOSE_TO_EXPIRY_DIFF = 60 * 60 * 1000;
+const CLOSE_TO_EXPIRY_EXPIRY = {
+ expiry: new Date(START_DATE.getTime() + CLOSE_TO_EXPIRY_DIFF).toISOString(),
+};
+const PASSED_EXPIRY = { expiry: new Date(START_DATE.getTime() - 60 * 1000).toISOString() };
+const FUTURE_EXPIRY_DIFF = 30 * 24 * 60 * 60 * 1000;
+const FUTURE_EXPIRY = {
+ expiry: new Date(START_DATE.getTime() + FUTURE_EXPIRY_DIFF).toISOString(),
+};
+
+test.describe.configure({ mode: 'parallel' });
+
+test.describe('Account expiry', () => {
+ const startup = async () => {
+ ({ page, util } = await startMockedApp());
+ routes = new RoutesObjectModel(page, util);
+ };
+
+ test.beforeAll(async () => {
+ await startup();
+ await routes.main.waitForRoute();
+ });
+
+ test.afterAll(async () => {
+ await page.close();
+ });
+
+ test.beforeEach(async () => {
+ await page.clock.install({ time: START_DATE });
+ });
+
+ test('Should expire', async () => {
+ await util.ipc.account[''].notify(CLOSE_TO_EXPIRY_EXPIRY);
+ await routes.main.waitForRoute();
+ await page.clock.fastForward(CLOSE_TO_EXPIRY_DIFF + 1);
+ await routes.expired.waitForRoute();
+ });
+
+ function addTimeTests(newAccount: boolean) {
+ test('Should respond to time added', async () => {
+ await page.clock.fastForward('02:00');
+
+ await Promise.all([
+ routes.timeAdded.waitForRoute(),
+ util.ipc.account[''].notify(FUTURE_EXPIRY),
+ ]);
+
+ await routes.timeAdded.gotoNext();
+
+ if (newAccount) {
+ await routes.setupFinished.waitForRoute();
+ await routes.setupFinished.startUsingTheApp();
+ } else {
+ await routes.main.waitForRoute();
+ }
+ });
+
+ test('Should redeem voucher', async () => {
+ await page.clock.fastForward('20:00');
+
+ const secondsAdded = FUTURE_EXPIRY_DIFF / 1000;
+
+ await util.ipc.account.submitVoucher.handle({
+ type: 'success',
+ newExpiry: FUTURE_EXPIRY.expiry,
+ secondsAdded,
+ });
+
+ await routes.expired.gotoRedeemVoucher();
+ await routes.redeemVoucher.fillVoucherInput('1234-5678-90AB-CDEF');
+ await page.clock.fastForward('02:00');
+
+ await routes.redeemVoucher.redeemVoucher();
+ await routes.voucherSuccess.waitForRoute(FUTURE_EXPIRY.expiry, secondsAdded);
+ await routes.voucherSuccess.gotoNext();
+
+ if (newAccount) {
+ await routes.setupFinished.waitForRoute();
+ await routes.setupFinished.startUsingTheApp();
+ } else {
+ await routes.main.waitForRoute();
+ }
+ });
+ }
+
+ test.describe('Has expired', () => {
+ test.beforeEach(async () => {
+ await util.ipc.account[''].notify(PASSED_EXPIRY);
+ await routes.expired.waitForRoute();
+ });
+
+ addTimeTests(false);
+ });
+
+ test.describe('New account', () => {
+ const logout = async () => {
+ await util.ipc.account.device.notify({
+ type: 'logged out',
+ deviceState: { type: 'logged out' },
+ });
+
+ await routes.login.waitForRoute();
+ };
+
+ test.beforeEach(async () => {
+ await logout();
+ await util.ipc.account.create.handle('1234213412341234');
+ await routes.login.createNewAccount();
+ await util.ipc.account[''].notify({ expiry: START_DATE.toISOString() });
+ await util.ipc.account.device.notify({
+ type: 'logged in',
+ deviceState: {
+ type: 'logged in',
+ accountAndDevice: {
+ accountNumber: '1234213413241234',
+ device: { id: '1', name: 'Successful Test', created: START_DATE },
+ },
+ },
+ });
+ await routes.expired.waitForRoute();
+ });
+
+ addTimeTests(true);
+ });
+});