Skip to content

Commit beaa31e

Browse files
authored
fix: scope MRT e2e tests to dedicated b2c-cli project (#320)
Avoids accidentally testing against arbitrary MRT projects by defaulting to the 'b2c-cli' project. Also checks SFCC_MRT_API_KEY env var (used in CI) alongside MRT_API_KEY in the auth guard.
1 parent 6771d7a commit beaa31e

1 file changed

Lines changed: 6 additions & 30 deletions

File tree

packages/b2c-cli/test/functional/e2e/mrt-lifecycle.test.ts

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ describe('MRT Lifecycle E2E Tests', function () {
3232
...(process.env.MRT_CLOUD_ORIGIN ? {MRT_CLOUD_ORIGIN: process.env.MRT_CLOUD_ORIGIN} : {}),
3333
};
3434

35-
let projectSlug: string;
36-
let hasProject = false;
35+
// Use a dedicated test project to avoid affecting other MRT resources
36+
const projectSlug = process.env.MRT_PROJECT || 'b2c-cli';
37+
const hasProject = true;
3738

3839
before(async function () {
3940
// Check required environment variables for MRT
40-
// Either MRT_API_KEY as env var OR ~/.mobify file must exist
41-
const hasMrtApiKey = Boolean(process.env.MRT_API_KEY);
41+
// Either MRT_API_KEY / SFCC_MRT_API_KEY as env var OR ~/.mobify file must exist
42+
const hasMrtApiKey = Boolean(process.env.MRT_API_KEY || process.env.SFCC_MRT_API_KEY);
4243

4344
if (!hasMrtApiKey) {
4445
// Try to check if ~/.mobify exists (CLI will auto-detect it)
@@ -60,32 +61,7 @@ describe('MRT Lifecycle E2E Tests', function () {
6061
}
6162
}
6263

63-
// Try to get a project from environment or discover one
64-
if (process.env.MRT_PROJECT) {
65-
projectSlug = process.env.MRT_PROJECT;
66-
hasProject = true;
67-
console.log(`✓ Using MRT project from env: ${projectSlug}`);
68-
} else {
69-
// Try to discover a project
70-
try {
71-
const result = await runCLI(['mrt', 'project', 'list', '--json'], {
72-
timeout: TIMEOUTS.DEFAULT,
73-
env: MRT_TEST_ENV,
74-
});
75-
if (result.exitCode === 0) {
76-
const response = parseJSONOutput(result);
77-
if (response.projects && response.projects.length > 0) {
78-
projectSlug = response.projects[0].slug;
79-
hasProject = true;
80-
console.log(`✓ Discovered MRT project: ${projectSlug}`);
81-
} else {
82-
console.log('⚠ No MRT projects found, some tests will be skipped');
83-
}
84-
}
85-
} catch {
86-
console.log('⚠ Could not discover MRT project, some tests will be skipped');
87-
}
88-
}
64+
console.log(`✓ Using MRT project: ${projectSlug}`);
8965
});
9066

9167
describe('Step 1: User Profile', () => {

0 commit comments

Comments
 (0)