Skip to content

Commit 289556e

Browse files
committed
test(branch): log in with EMAIL/PASSWORD and manage own environments in BranchAPITest
BranchAPITest used TestClient.getStack(), which sends the management token. Branch create answered 401 (error 161) with it, and the test assumed the 'development' and 'production' environments exist on the stack. The class now: - logs in with EMAIL / PASSWORD and uses the apiKey header only; - creates two environments whose names are unique to the run, and deletes them, with every created branch (force=true), and logs out in @afterall; - polls fetch until a created branch is ready (bounded, 60s, 2s steps); - treats a rejected create as no branch when fetch answers 422 with error_code 905, the same answer as a missing branch; - adds TC-23 (create without publish_config) and TC-24 (environment name in a different case gets 422). Without EMAIL, PASSWORD or apiKey in .env the class is skipped with a "not run" message. TestClient gains public EMAIL and PASSWORD constants and isApiKeyConfigured(). Refs: DX-31579 Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ef6P4M5YRs6tDbdFqkvmZc
1 parent 01ea18f commit 289556e

2 files changed

Lines changed: 281 additions & 51 deletions

File tree

‎src/test/java/com/contentstack/cms/TestClient.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public class TestClient {
3939
public static final String ENTRY_VARIANT_LOCALE =
4040
isBlank(env.get("entryVariantLocale")) ? "en-us" : env.get("entryVariantLocale").trim();
4141

42+
/** Login email for tests that log in with a real account (null when {@code EMAIL} is not set in {@code .env}). */
43+
public static final String EMAIL = env.get("EMAIL");
44+
45+
/** Login password for tests that log in with a real account (null when {@code PASSWORD} is not set in {@code .env}). */
46+
public static final String PASSWORD = env.get("PASSWORD");
47+
4248
/** {@code true} if {@code value} is null, empty, or whitespace-only. */
4349
private static boolean isBlank(String value) {
4450
return value == null || value.trim().isEmpty();
@@ -51,6 +57,11 @@ public static boolean isUsingDefaultStackCredentials() {
5157
return env.get("apiKey") == null || env.get("managementToken") == null;
5258
}
5359

60+
/** {@code true} when {@code apiKey} is set to a non-blank value in {@code .env}. */
61+
public static boolean isApiKeyConfigured() {
62+
return !isBlank(env.get("apiKey"));
63+
}
64+
5465
private static Contentstack instance;
5566
private static Stack stackInstance;
5667

0 commit comments

Comments
 (0)