{
  "info": {
    "name": "Helix AI - Orchestration & JWT Channels",
    "description": "Covers: erp-api login/logout/forgot-password (JWT issuance + revocation), the new v1/ai/ping JWT-guarded endpoint, and helixta-api's cross-service /ping health check. Login and Forgot-Password-Update automatically populate the collection variables used by every other request in this collection — run them first.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    { "key": "erp_base_url", "value": "http://127.0.0.1:8000" },
    { "key": "helixta_base_url", "value": "http://127.0.0.1:8001" },
    { "key": "email", "value": "naveen.qatest@rhysley.com" },
    { "key": "password", "value": "TestPass123!" },
    { "key": "browser_id", "value": "postman-test-browser" },
    { "key": "sanctum_token", "value": "" },
    { "key": "ai_assist_jwt_token", "value": "" },
    { "key": "reset_token", "value": "" },
    { "key": "new_password", "value": "NewTestPass123!" }
  ],
  "item": [
    {
      "name": "erp-api - Auth",
      "item": [
        {
          "name": "1. Login",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const body = pm.response.json();",
                  "if (body.data && body.data.token) {",
                  "    pm.collectionVariables.set('sanctum_token', body.data.token);",
                  "}",
                  "if (body.data && body.data.ai_assist_jwt_token) {",
                  "    pm.collectionVariables.set('ai_assist_jwt_token', body.data.ai_assist_jwt_token);",
                  "}",
                  "pm.test('Login succeeded', () => pm.response.to.have.status(200));",
                  "pm.test('ai_assist_jwt_token captured', () => {",
                  "    pm.expect(pm.collectionVariables.get('ai_assist_jwt_token')).to.not.be.empty;",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"{{email}}\",\n  \"password\": \"{{password}}\",\n  \"browser_id\": \"{{browser_id}}\"\n}"
            },
            "url": "{{erp_base_url}}/api/v1/login"
          }
        },
        {
          "name": "2. Refresh JWT Token (from Sanctum token)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const body = pm.response.json();",
                  "if (body.data && body.data.ai_assist_jwt_token) {",
                  "    pm.collectionVariables.set('ai_assist_jwt_token', body.data.ai_assist_jwt_token);",
                  "}",
                  "pm.test('Refresh succeeded', () => pm.response.to.have.status(200));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [{ "key": "Authorization", "value": "Bearer {{sanctum_token}}" }],
            "url": "{{erp_base_url}}/api/v1/refreshJWTToken"
          }
        },
        {
          "name": "3. Logout (revokes ai_assist_jwt_token)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Logout succeeded', () => pm.response.to.have.status(200));",
                  "pm.test('Response indicates success', () => {",
                  "    pm.expect(pm.response.json().success).to.be.true;",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              { "key": "Authorization", "value": "Bearer {{sanctum_token}}" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"browser_id\": \"{{browser_id}}\",\n  \"ai_assist_jwt_token\": \"{{ai_assist_jwt_token}}\"\n}"
            },
            "url": "{{erp_base_url}}/api/v1/logout"
          }
        },
        {
          "name": "4. Forgot Password (request reset link)",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"{{email}}\",\n  \"browser_id\": \"{{browser_id}}\"\n}"
            },
            "url": "{{erp_base_url}}/api/v1/forgotpassword"
          },
          "description": "Generates the reset token server-side and saves it to the user's reset_password_token column, then queues an email containing it — but SEND_MAIL is unset in this environment's .env, so no email actually goes out here, and the endpoint never returns the token in its response body by design. For local testing, pull it straight from the DB after calling this: `php artisan tinker --execute=\"echo App\\Models\\User::where('email','{{email}}')->value('reset_password_token');\"` — then paste that value into the 'reset_token' collection variable before running the next request."
        },
        {
          "name": "5. Forgot Password - Update (revokes ALL prior sessions)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Password reset succeeded', () => pm.response.to.have.status(200));",
                  "if (pm.response.code === 200) {",
                  "    pm.collectionVariables.set('password', pm.collectionVariables.get('new_password'));",
                  "    pm.collectionVariables.set('sanctum_token', '');",
                  "    pm.collectionVariables.set('ai_assist_jwt_token', '');",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"token\": \"{{reset_token}}\",\n  \"password\": \"{{new_password}}\",\n  \"c_password\": \"{{new_password}}\",\n  \"browser_id\": \"{{browser_id}}\"\n}"
            },
            "url": "{{erp_base_url}}/api/v1/forgotpassword/update"
          },
          "description": "Requires 'reset_token' to be set manually first (see previous request). On success this invalidates every ai_assist_jwt_token issued before this moment, and deletes all Sanctum tokens — log in again (request 1) afterward to get fresh tokens."
        }
      ]
    },
    {
      "name": "erp-api - AI Assist (JWT-guarded)",
      "item": [
        {
          "name": "1. Ping (valid token expected: 200)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Status is 200', () => pm.response.to.have.status(200));",
                  "pm.test('Body has erp-api identity', () => {",
                  "    const body = pm.response.json();",
                  "    pm.expect(body.data.service).to.eql('erp-api');",
                  "    pm.expect(body.data.status).to.eql('ok');",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [{ "key": "Authorization", "value": "Bearer {{ai_assist_jwt_token}}" }],
            "url": "{{erp_base_url}}/api/v1/ai/ping"
          }
        },
        {
          "name": "2. Ping - No Token (expected: 401)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": ["pm.test('Status is 401', () => pm.response.to.have.status(401));"]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{erp_base_url}}/api/v1/ai/ping"
          }
        },
        {
          "name": "3. Ping - Garbage Token (expected: 401)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": ["pm.test('Status is 401', () => pm.response.to.have.status(401));"]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [{ "key": "Authorization", "value": "Bearer not-a-real-jwt" }],
            "url": "{{erp_base_url}}/api/v1/ai/ping"
          }
        },
        {
          "name": "4. Ping - After Logout, Same Token (expected: 401)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Status is 401 (blacklisted)', () => pm.response.to.have.status(401));",
                  "pm.test('Message is Invalid token', () => {",
                  "    pm.expect(pm.response.json().message).to.eql('Invalid token');",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [{ "key": "Authorization", "value": "Bearer {{ai_assist_jwt_token}}" }],
            "url": "{{erp_base_url}}/api/v1/ai/ping"
          },
          "description": "Run 'Logout' under erp-api - Auth first, then run this with the SAME (now-stale) ai_assist_jwt_token value — expect 401, proving the token was actually blacklisted, not just that the Sanctum token was deleted."
        },
        {
          "name": "5. Leave - Apply",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Status is 200 or a validation/business-rule 400', () => {",
                  "    pm.expect([200, 400]).to.include(pm.response.code);",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              { "key": "Authorization", "value": "Bearer {{ai_assist_jwt_token}}" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"leave_type_slug\": \"casual_leave\",\n  \"session_type_slug\": \"full_day\",\n  \"from_date\": \"2026-08-20\",\n  \"to_date\": \"2026-08-20\",\n  \"reason\": \"Personal work\"\n}"
            },
            "url": "{{erp_base_url}}/api/v1/ai/leave/apply"
          },
          "description": "Mirrors LeaveController::applyleaves()'s validation chain. session_type_slug is required only when leave_type_slug is casual_leave/sick_leave/earned_leave. 400 is expected (not a failure) when balance/notice-period/back-date/lock-attendance business rules reject the request — see AiAssistLeaveController::apply()."
        },
        {
          "name": "6. Leave - Status",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Status is 200', () => pm.response.to.have.status(200));",
                  "pm.test('Body has leaves array', () => {",
                  "    pm.expect(pm.response.json().data).to.have.property('leaves');",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [{ "key": "Authorization", "value": "Bearer {{ai_assist_jwt_token}}" }],
            "url": "{{erp_base_url}}/api/v1/ai/leave/status"
          },
          "description": "Self-only recent leave applications (AiAssistLeaveController::status()), flattened for conversational display."
        }
      ]
    },
    {
      "name": "helixta-api - Health",
      "item": [
        {
          "name": "1. Cross-Service Ping",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Status is 200 or a graceful degradation code', () => {",
                  "    pm.expect([200, 503, 504]).to.include(pm.response.code);",
                  "});",
                  "pm.test('Response has structured schema', () => {",
                  "    const body = pm.response.code === 200 ? pm.response.json() : pm.response.json().detail;",
                  "    pm.expect(body).to.have.property('status');",
                  "    pm.expect(body).to.have.property('timestamp');",
                  "    pm.expect(body).to.have.property('dependencies');",
                  "    pm.expect(body.dependencies).to.have.property('postgres');",
                  "    pm.expect(body.dependencies).to.have.property('redis');",
                  "    pm.expect(body.dependencies).to.have.property('erp_api');",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [{ "key": "Authorization", "value": "Bearer {{ai_assist_jwt_token}}" }],
            "url": "{{helixta_base_url}}/ping"
          },
          "description": "200 = all dependencies healthy. 503 = erp-api unreachable. 504 = erp-api timed out. Redis/Postgres issues never change the status code, only dependencies.<name>.status/error_code in the body."
        },
        {
          "name": "2. Cross-Service Ping - No Token (expected: 401)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": ["pm.test('Status is 401', () => pm.response.to.have.status(401));"]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{helixta_base_url}}/ping"
          }
        },
        {
          "name": "3. Server Info",
          "request": {
            "method": "GET",
            "header": [{ "key": "Authorization", "value": "Bearer {{ai_assist_jwt_token}}" }],
            "url": "{{helixta_base_url}}/server-info"
          }
        }
      ]
    },
    {
      "name": "helixta-api - Chat (pre-existing, for regression sanity)",
      "item": [
        {
          "name": "1. HR Assist Stream",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Authorization", "value": "Bearer {{ai_assist_jwt_token}}" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"query\": \"What is the annual leave policy?\"}"
            },
            "url": "{{helixta_base_url}}/hr-assist-stream"
          },
          "description": "SSE endpoint — Postman will show the raw event stream in the response body rather than parsed JSON. Included only to confirm the pre-existing chat flow still works after this story's changes."
        },
        {
          "name": "2. Attendance Explain",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Authorization", "value": "Bearer {{ai_assist_jwt_token}}" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"query\": \"Why was I marked late today?\"}"
            },
            "url": "{{helixta_base_url}}/hr-assist-stream"
          },
          "description": "SSE endpoint — exercises the attendance_explain intent/node. Expect 'fetching_attendance' and 'attendance_explanation' events in the stream, sourced entirely from erp-api's Attendance Rule Engine (GET /api/v1/ai/attendance/explain) — the assistant renders that payload verbatim, it never computes the explanation itself."
        }
      ]
    }
  ]
}
