{
  "info": {
    "_postman_id": "f1a2b3c4-d5e6-47a8-9b0c-wxmsocket0001",
    "name": "WXM Socket Gateway (local)",
    "description": "Test the WXM real-time Socket.IO gateway on local.\n\n## Flow\n1. Run **REST → Login (supporter)** — it stores the JWT into the `token` collection variable automatically.\n2. Open **WXM Socket Gateway** (Socket.IO request) and click **Connect**. The handshake sends `Authorization: Bearer {{token}}`.\n3. Add the listen events + send the emits documented on that request.\n\n## Prereqs (all on local)\n- Redis on 6379\n- Gateway on 6001  (`cd modules/Socket && npx ts-node src/index.ts`)\n- Laravel on 8000  (`php artisan serve`)\n\nServer accepts the token in 3 places (in order): `auth.token` → `Authorization: Bearer …` → `?token=…`.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "REST (get token)",
      "item": [
        {
          "name": "Login (supporter)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Save the JWT into the collection variable {{token}} so the",
                  "// Socket.IO request can use it in the handshake header.",
                  "const json = pm.response.json();",
                  "const token = json && json.data && json.data.token;",
                  "if (token) {",
                  "  pm.collectionVariables.set('token', token);",
                  "  if (json.data.id) pm.collectionVariables.set('userId', String(json.data.id));",
                  "  console.log('Saved token for user', json.data.id);",
                  "} else {",
                  "  console.warn('No token in response:', JSON.stringify(json));",
                  "}",
                  "pm.test('login ok', () => pm.expect(token, 'token present').to.be.a('string'));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" },
              { "key": "Accept-Language", "value": "en" },
              { "key": "user_type", "value": "{{userType}}" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"auth\": \"{{authEmail}}\",\n  \"password\": \"{{authPassword}}\"\n}"
            },
            "url": {
              "raw": "{{apiBaseUrl}}/api/v1/general/auth/login",
              "host": ["{{apiBaseUrl}}"],
              "path": ["api", "v1", "general", "auth", "login"]
            },
            "description": "Logs in a demo user and returns a JWT. The test script stores it in {{token}}.\n\nDemo creds (seeded): supporter `sup1@wxm.test`, streamer `str1@wxm.test` — password `password`. Change `userType` + `authEmail` collection variables for other users."
          },
          "response": []
        },
        {
          "name": "Profile (verify token)",
          "request": {
            "method": "GET",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Accept-Language", "value": "en" },
              { "key": "Authorization", "value": "Bearer {{token}}" }
            ],
            "url": {
              "raw": "{{apiBaseUrl}}/api/v1/general/profile",
              "host": ["{{apiBaseUrl}}"],
              "path": ["api", "v1", "general", "profile"]
            },
            "description": "Sanity check — a 200 here means the same token the gateway uses for its remote auth check is valid."
          },
          "response": []
        }
      ]
    },
    {
      "name": "WXM Socket Gateway",
      "protocolProfileBehavior": {
        "socketEnabled": true
      },
      "request": {
        "url": {
          "raw": "{{socketUrl}}",
          "host": ["{{socketUrl}}"]
        },
        "method": "GET",
        "header": [
          { "key": "Authorization", "value": "Bearer {{token}}" }
        ],
        "description": "Socket.IO connection to the WXM gateway.\n\n=== HANDSHAKE ===\nTransport: WebSocket. Auth via header `Authorization: Bearer {{token}}` (already set). Alternatively add `?token={{token}}` to the URL, or set `auth.token` in Settings.\nOn success the gateway logs `socket connected userId=...`. On failure you get a connect error with one of: AUTH_MISSING / AUTH_EXPIRED / AUTH_INVALID / AUTH_INVALID_SUB / AUTH_REVOKED / AUTH_FAILED.\n\n=== EVENTS TO LISTEN FOR (add in the Listeners panel) ===\n- message          → new DM. payload: { event:'message.created', conversation_id, message:{id,sender_id,body,media_id,created_at} }\n- presence         → { event:'user.online'|'user.offline', user_id }\n- live             → live room events (viewer_joined/left, gift, comment, like, ended, ...). payload.live_id always present.\n- support.message  → support-chat messages\n\n=== EMITS YOU CAN SEND (event name next to Send + JSON arg; enable ack to see reply) ===\n- presence.query     {\"user_ids\":[12,1]}                  → ack { ok:true, states:{\"12\":true,\"1\":false} }\n- presence.watch     {\"user_ids\":[12,1]}                  → ack snapshot + future updates on 'presence'\n- presence.unwatch   {\"user_ids\":[12,1]}\n- conversation.join  {\"conversation_id\":1}                → must be a participant, else ack { ok:false, code:'FORBIDDEN' }\n- conversation.leave {\"conversation_id\":1}\n- live.join          {\"live_id\":1}\n- live.leave         {\"live_id\":1}\n\n=== TRIGGER A 'message' WITHOUT THE APP ===\nFrom the repo root, publish straight to Redis (prefix must match APP_NAME=WXM → wxm-database-):\n  .\\.redis-portable\\redis-cli.exe publish \"wxm-database-user.{{userId}}\" \"{\\\"event\\\":\\\"message.created\\\",\\\"conversation_id\\\":1,\\\"message\\\":{\\\"id\\\":1,\\\"sender_id\\\":7,\\\"body\\\":\\\"hi\\\",\\\"media_id\\\":null,\\\"created_at\\\":\\\"2026-06-06T00:00:00+00:00\\\"}}\"\nThe connected socket (user {{userId}}) receives it on the `message` event."
      },
      "response": []
    }
  ],
  "variable": [
    { "key": "apiBaseUrl", "value": "http://127.0.0.1:8000", "type": "string" },
    { "key": "socketUrl", "value": "ws://127.0.0.1:6001", "type": "string" },
    { "key": "token", "value": "", "type": "string" },
    { "key": "userId", "value": "12", "type": "string" },
    { "key": "userType", "value": "supporter", "type": "string" },
    { "key": "authEmail", "value": "sup1@wxm.test", "type": "string" },
    { "key": "authPassword", "value": "password", "type": "string" }
  ]
}
