From 4f010701aa95ce8a8a799ae140ccdac6ecb07599 Mon Sep 17 00:00:00 2001 From: Beatriz Rizental Date: Wed, 8 Feb 2023 16:32:10 +0100 Subject: [PATCH] Skip on wasm the right way --- tests/functional/testAddons.js | 132 +++++++++++++++++---------------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/tests/functional/testAddons.js b/tests/functional/testAddons.js index 60a27b6819..cc16564b50 100644 --- a/tests/functional/testAddons.js +++ b/tests/functional/testAddons.js @@ -130,74 +130,76 @@ describe('Addons', function () { exitCountryCode); }); - // This tests cannot be run in WASM due to Qt limitations. - // See: https://mozilla-hub.atlassian.net/browse/VPN-4127 - if (typeof process === "object") { - describe('test message_subscription_expiring addon condition', async () => { - const testCases = [ - ...Array.from( - { length: 7 }, - // 1 to 7 days out from expiring. - (_, i) => [Date.now() + 1000 * 60 * 60 * 24 * (i + 1), true, `is ${i + 1} day(s) away`] - ), - // Seven days out + five minutes from expiring. - [Date.now() + 1000 * 60 * 60 * 24 * 7 + 1000 * 60 * 5, false, "is 7 days and five minutes away"], - // Eight days from expiring. - [Date.now() + 1000 * 60 * 60 * 24 * 8, false, "is 8 days away"], - // One month from expiring. - [Date.now() + 1000 * 60 * 60 * 24 * 30, false, "is one month away"], - // Literally, has just expired. - [Date.now(), false, "just happened"], - // Has been expired for a day. - [Date.now() - 1000 * 60 * 60 * 24, false, "was yesterday"], - // Has been expired for 30 days. - [Date.now() - 1000 * 60 * 60 * 24 * 30, false, "was last month"], - ]; - - const getNextTestCase = testCases[Symbol.iterator](); - function setNextSubscriptionExpiry(ctx) { - const mockDetails = { ...SubscriptionDetails }; - const nextTestCase = getNextTestCase.next().value; - - if (nextTestCase) { - const [expiresOn] = nextTestCase; - // We are faking a Stripe subscription, so this value is expected to be in seconds. - mockDetails.subscription.current_period_end = expiresOn / 1000; - - ctx.guardianSubscriptionDetailsCallback = () => { - ctx.guardianOverrideEndpoints.GETs['/api/v1/vpn/subscriptionDetails'].status = 200; - ctx.guardianOverrideEndpoints - .GETs['/api/v1/vpn/subscriptionDetails'] - .body = mockDetails; - }; - } + describe('test message_subscription_expiring addon condition', async () => { + const testCases = [ + ...Array.from( + { length: 7 }, + // 1 to 7 days out from expiring. + (_, i) => [Date.now() + 1000 * 60 * 60 * 24 * (i + 1), true, `is ${i + 1} day(s) away`] + ), + // Seven days out + five minutes from expiring. + [Date.now() + 1000 * 60 * 60 * 24 * 7 + 1000 * 60 * 5, false, "is 7 days and five minutes away"], + // Eight days from expiring. + [Date.now() + 1000 * 60 * 60 * 24 * 8, false, "is 8 days away"], + // One month from expiring. + [Date.now() + 1000 * 60 * 60 * 24 * 30, false, "is one month away"], + // Literally, has just expired. + [Date.now(), false, "just happened"], + // Has been expired for a day. + [Date.now() - 1000 * 60 * 60 * 24, false, "was yesterday"], + // Has been expired for 30 days. + [Date.now() - 1000 * 60 * 60 * 24 * 30, false, "was last month"], + ]; + + const getNextTestCase = testCases[Symbol.iterator](); + function setNextSubscriptionExpiry(ctx) { + const mockDetails = { ...SubscriptionDetails }; + const nextTestCase = getNextTestCase.next().value; + + if (nextTestCase) { + const [expiresOn] = nextTestCase; + // We are faking a Stripe subscription, so this value is expected to be in seconds. + mockDetails.subscription.current_period_end = expiresOn / 1000; + + ctx.guardianSubscriptionDetailsCallback = () => { + ctx.guardianOverrideEndpoints.GETs['/api/v1/vpn/subscriptionDetails'].status = 200; + ctx.guardianOverrideEndpoints + .GETs['/api/v1/vpn/subscriptionDetails'] + .body = mockDetails; + }; } + } + + // We call this once before all tests to set up the first test, + // we can't use beforeEach because that is executed after the guardian endpoints are overriden. + // + // We need to setup for the next test before it even starts for the overrides to apply. + setNextSubscriptionExpiry(this.ctx); + afterEach(() => setNextSubscriptionExpiry(this.ctx)); + + testCases.forEach(([_, shouldBeAvailable, testCase]) => { + it(`message display is correct when subscription expiration ${testCase}`, async () => { + // This tests cannot be run in WASM due to Qt limitations. + // See: https://mozilla-hub.atlassian.net/browse/VPN-4127 + if (this.ctx.wasm) { + return; + } + + // Load all production addons. + // These are loaded all together, so we don't know the exact number of addons. + await vpn.resetAddons('prod'); + await vpn.waitForCondition(async () => ( + parseInt(await vpn.getVPNProperty('VPNAddonManager', 'count'), 10) > 0 + )); - // We call this once before all tests to set up the first test, - // we can't use beforeEach because that is executed after the guardian endpoints are overriden. - // - // We need to setup for the next test before it even starts for the overrides to apply. - setNextSubscriptionExpiry(this.ctx); - afterEach(() => setNextSubscriptionExpiry(this.ctx)); - - testCases.forEach(([_, shouldBeAvailable, testCase]) => { - it(`message display is correct when subscription expiration ${testCase}`, async () => { - // Load all production addons. - // These are loaded all together, so we don't know the exact number of addons. - await vpn.resetAddons('prod'); - await vpn.waitForCondition(async () => ( - parseInt(await vpn.getVPNProperty('VPNAddonManager', 'count'), 10) > 0 - )); - - - // Check if the message is there or not. - await vpn.waitForCondition(async () => { - const loadedMessages = await vpn.messages(); - const isSubscriptionExpiringMessageAvailable = loadedMessages.includes("message_subscription_expiring"); - return shouldBeAvailable ? isSubscriptionExpiringMessageAvailable : !isSubscriptionExpiringMessageAvailable; - }); + + // Check if the message is there or not. + await vpn.waitForCondition(async () => { + const loadedMessages = await vpn.messages(); + const isSubscriptionExpiringMessageAvailable = loadedMessages.includes("message_subscription_expiring"); + return shouldBeAvailable ? isSubscriptionExpiringMessageAvailable : !isSubscriptionExpiringMessageAvailable; }); }); }); - } + }); });