scenarios:
  - id: unit-test-tdd
    title: "Red-Green-Refactor with Unit Tests"
    difficulty: beginner
    xp: 30
    setup:
      - "mkdir -p workshop && cd workshop"
      - "npm init -y"
      - "npm install --save-dev vitest"
    files:
      - name: calculator.js
        content: |
          function add(a, b) { return 0; }
          function subtract(a, b) { return 0; }
          function multiply(a, b) { return 0; }
          function divide(a, b) { return 0; }
          module.exports = { add, subtract, multiply, divide };
        language: javascript
        readonly: false
      - name: calculator.test.js
        content: |
          const { add, subtract, multiply, divide } = require('./calculator');
          const assert = require('assert');
          assert.strictEqual(add(2, 3), 5, 'add(2,3) should be 5');
          assert.strictEqual(subtract(5, 2), 3, 'subtract(5,2) should be 3');
          assert.strictEqual(multiply(4, 3), 12, 'multiply(4,3) should be 12');
          assert.strictEqual(divide(10, 2), 5, 'divide(10,2) should be 5');
          console.log('All tests passed');
        language: javascript
        readonly: true
    task: "Implement add, subtract, multiply, and divide in calculator.js so that node calculator.test.js prints 'All tests passed'. No test runner—the test file runs directly with node."
    validations:
      - label: "All tests passed"
        check: output-contains
        pattern: "All tests passed"
    hints:
      - "The test file requires add, subtract, multiply, divide from calculator.js. Export them."
      - "add(a,b) returns a+b. subtract returns a-b, multiply returns a*b, divide returns a/b."
      - "module.exports = { add, subtract, multiply, divide };"
    agent_prompts:
      on_start: "What do the failing tests tell you about what's missing? How would you add the smallest code to make one test pass?"

  - id: integration-test
    title: "Write Integration Tests for a Service"
    difficulty: intermediate
    xp: 40
    setup:
      - "mkdir -p workshop && cd workshop"
      - "npm init -y"
    files:
      - name: userService.js
        content: |
          const users = new Map([
            [1, { id: 1, name: 'Alice', email: 'alice@example.com' }],
            [2, { id: 2, name: 'Bob', email: 'bob@example.com' }],
          ]);
          function getUserById(id) {
            return users.get(id) ?? null;
          }
          function getAllUsers() {
            return Array.from(users.values());
          }
          function createUser({ name, email }) {
            const id = users.size + 1;
            users.set(id, { id, name, email });
            return users.get(id);
          }
          module.exports = { getUserById, getAllUsers, createUser };
        language: javascript
        readonly: true
      - name: userService.test.js
        content: |
          // TODO: Write tests that verify:
          // 1. getUserById(1) returns a user with name 'Alice'
          // 2. getAllUsers() returns at least 2 users
          // 3. createUser({ name: 'Carol', email: 'carol@example.com' }) adds a new user and returns it
          const { getUserById, getAllUsers, createUser } = require('./userService');
          const assert = require('assert');
          // Add your test code here
          console.log('Tests not yet implemented');
        language: javascript
        readonly: false
    task: "Implement the tests in userService.test.js. Use assert.strictEqual (or similar) to verify getUserById, getAllUsers, and createUser. Run node userService.test.js—it should print that tests passed."
    validations:
      - label: "Tests pass and userService.test.js was modified"
        check: file-changed
        pattern: "userService.test.js"
      - label: "Output indicates passing tests"
        check: output-contains
        pattern: "pass"
    hints:
      - "Call getUserById(1) and assert the returned object has name 'Alice'."
      - "getAllUsers() returns an array. Assert its length is >= 2."
      - "createUser returns the new user. Assert it has name and email. Run tests with node userService.test.js."
    agent_prompts:
      on_start: "What does the service do? If you were a developer integrating with it, what would you want to verify works?"
