# Tests for `create-business-logic` Skill

7 acceptance tests. All run against the output produced by the skill in a simulator-ready branch.

---

## Test 1 — Skill activation

**Trigger:** User says "add a beforeLoadAsync to BoMyVisit"
**Expected:** Skill identifies the phrase "beforeLoadAsync" and activates `create-business-logic`.
**Pass criteria:** Skill is invoked (not `create-business-object` or a generic JS edit); plan
starts with the prerequisite check for `<Method name="beforeLoadAsync">` in the parent BO XML.

---

## Test 2 — Before-load lifecycle file created correctly

**Setup:** A BO `BoMyVisit` exists with `<Method name="beforeLoadAsync"/>` in its XML.
**Action:** Apply `templates/before-load-async.bl.js.template` substituting `ParentClass=MyVisit`.
**Expected output file:** `src/MyModule/BO/BoMyVisit/Mv2/LoadAsync/BoMyVisit.BeforeLoadAsync.bl.js`

**Assertions:**

-   [ ] Line 1 is exactly `"use strict";`
-   [ ] Auto-generated banner block (19 lines starting with `///...IMPORTANT...`) is present
-   [ ] JSDoc contains `@function beforeLoadAsync`
-   [ ] JSDoc contains `@this BoMyVisit`
-   [ ] JSDoc contains `@kind businessobject`
-   [ ] JSDoc contains `@async`
-   [ ] JSDoc contains `@namespace CUSTOM`
-   [ ] JSDoc contains `@module CUSTOM`
-   [ ] JSDoc contains `@param {Object} context`
-   [ ] JSDoc contains `@returns promise`
-   [ ] Function declaration is `function beforeLoadAsync(context){`
-   [ ] Both insertion markers are present (3-line form each)
-   [ ] `sf mdl build` exits 0 after the file is placed

---

## Test 3 — After-save lifecycle file created correctly

**Setup:** A BO `BoMyVisit` exists with `<Method name="afterSaveAsync"/>` in its XML.
**Action:** Apply `templates/after-save-async.bl.js.template` substituting `ParentClass=MyVisit`.
**Expected output file:** `src/MyModule/BO/BoMyVisit/Mv2/SaveAsync/BoMyVisit.AfterSaveAsync.bl.js`

**Assertions:**

-   [ ] Line 1 is exactly `"use strict";`
-   [ ] JSDoc contains `@function afterSaveAsync`
-   [ ] JSDoc contains `@namespace CUSTOM`
-   [ ] Function declaration is `function afterSaveAsync(result, context){`
-   [ ] Both `@param {Object} result` and `@param {Object} context` are present
-   [ ] Both insertion markers present
-   [ ] `sf mdl build` exits 0

---

## Test 4 — Custom method file created correctly

**Setup:** A BO `BoMyVisit` exists with `<Method name="startVisit"/>` in its XML.
**Action:** Apply `templates/custom-method.bl.js.template` substituting `ParentClass=MyVisit`,
`methodName=startVisit`.
**Expected output file:** `src/MyModule/BO/BoMyVisit/Mv2/BoMyVisit.StartVisit.bl.js`

**Assertions:**

-   [ ] Line 1 is exactly `"use strict";`
-   [ ] JSDoc contains `@function startVisit`
-   [ ] JSDoc contains `@this BoMyVisit`
-   [ ] JSDoc contains `@namespace CUSTOM`
-   [ ] Function declaration is `function startVisit(context){`
-   [ ] Both insertion markers present
-   [ ] `sf mdl build` exits 0

---

## Test 5 — CUSTOM vs CORE namespace enforced

**Setup:** A new `.bl.js` file is generated from any template.
**Action:** Search the output file for `@namespace`.

**Assertions:**

-   [ ] `grep "@namespace" <file>` returns exactly one line
-   [ ] That line reads `@namespace CUSTOM`
-   [ ] No line reads `@namespace CORE`
-   [ ] `grep -c "@namespace CUSTOM" <file>` returns `1`

Rationale: CORE is reserved for shipped Salesforce framework files. A customer file declaring
`@namespace CORE` compiles into the framework namespace and can silently override platform
behavior. See `_shared/namespace.md`.

---

## Test 6 — Missing `<Method>` declaration caught before file creation

**Setup:** A BO `BoMyVisit` exists but has NO `<Method name="startVisit"/>` in its XML.
**Action:** Skill is asked to create `BoMyVisit.StartVisit.bl.js`.

**Expected:** Skill pauses and reports the prerequisite gap before writing the file. It either:
(a) prompts the user to add the declaration to the BO XML first, or
(b) invokes `create-business-object` to update the XML, then proceeds.

**Pass criteria:** The `.bl.js` file is NOT written until the XML `<Method>` declaration exists.
If the file were written first, `sf mdl build` would fail with "method not found" or similar
validation error.

---

## Test 7 — MFG absence

**Action:** Run the following from the repo root:

```bash
grep -rni "mfg" .claude/skills/create-business-logic/ \
    --include="*.md" --include="*.template" | grep -iv "forbidden\|MFG check"
```

**Pass criteria:** Output is empty (exit 0 with no matches). No MFG-specific content must appear
in the skill — it is a general-purpose BL skill, not domain-specific.
