Skip to content

Commit dfc59ce

Browse files
committed
test(functional-tests): Add functional test for the Free Access Program
Because: * The Free Access Program (PAY-3780) grants subscription capabilities to users configured in Strapi without an actual subscription, and there was no automated coverage confirming the capability is broadcast. This commit: * Adds a functional test that provisions the configured free-access account and asserts the auth-server profile returns the `123donePro` capability under `subscriptionsByClientId`. * Sources the account password from FREE_ACCESS_PROGRAM_PWD (skips when unset) and skips in production, since the feature relies on environment-specific Strapi configuration. Closes PAY-3781
1 parent f18265d commit dfc59ce

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
import { expect, test } from '../lib/fixtures/payments';
6+
7+
const FREE_ACCESS_EMAIL = '123donefreeaccess@restmail.net';
8+
const FREE_ACCESS_CAPABILITY = '123donePro';
9+
const FREE_ACCESS_PASSWORD = process.env.FREE_ACCESS_PROGRAM_PWD;
10+
11+
test.describe('severity-2 #smoke', () => {
12+
test.beforeEach(async ({}, { project }) => {
13+
test.skip(
14+
project.name.includes('production'),
15+
'Free Access Program relies on non-production Strapi configuration'
16+
);
17+
test.skip(
18+
!FREE_ACCESS_PASSWORD,
19+
'FREE_ACCESS_PROGRAM_PWD is not set; required to provision the free-access account'
20+
);
21+
});
22+
23+
test('grants the 123donePro capability via the auth-server profile', async ({
24+
target,
25+
testAccountTracker,
26+
}) => {
27+
// Guaranteed set by the beforeEach skip above.
28+
const password = FREE_ACCESS_PASSWORD as string;
29+
30+
// Self-provision the fixed free-access account: sign in if it already
31+
// exists, otherwise create it (pre-verified).
32+
const { exists } = await target.authClient.accountStatusByEmail(
33+
FREE_ACCESS_EMAIL,
34+
{},
35+
target.ciHeader
36+
);
37+
38+
const credentials = exists
39+
? await target.authClient.signIn(
40+
{ primary: FREE_ACCESS_EMAIL, original: FREE_ACCESS_EMAIL },
41+
password,
42+
{},
43+
target.ciHeader
44+
)
45+
: await target.createAccount(FREE_ACCESS_EMAIL, password);
46+
47+
// Track for automatic teardown so each run starts from a clean slate.
48+
testAccountTracker.accounts.push({
49+
email: FREE_ACCESS_EMAIL,
50+
password,
51+
});
52+
53+
const profile = await target.authClient.accountProfile(
54+
credentials.sessionToken,
55+
target.ciHeader
56+
);
57+
58+
// `subscriptionsByClientId` maps each client id to its capability slugs;
59+
// the free-access grant appears here even without a subscription.
60+
const capabilities = Object.values(
61+
profile.subscriptionsByClientId ?? {}
62+
).flat();
63+
64+
expect(capabilities).toContain(FREE_ACCESS_CAPABILITY);
65+
});
66+
});

0 commit comments

Comments
 (0)