Skip to content

Commit

Permalink
Skip on wasm the right way
Browse files Browse the repository at this point in the history
  • Loading branch information
brizental committed Feb 8, 2023
1 parent 3db7454 commit 4f01070
Showing 1 changed file with 67 additions and 65 deletions.
132 changes: 67 additions & 65 deletions tests/functional/testAddons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
});
}
});
});

0 comments on commit 4f01070

Please sign in to comment.