{
  "info": {
    "name": "BenkoFlast API",
    "description": "Pruebas de la API puente de BenkoFlast: OAuth, cuentas, movimientos y comprobantes.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://benkoflast.somee.com",
      "description": "URL base de la API publica"
    },
    {
      "key": "clientId",
      "value": "TU_CLIENT_ID",
      "description": "Tu ClientId (lo entrega BenkoFlast al darte de alta)"
    },
    {
      "key": "clientSecret",
      "value": "TU_CLIENT_SECRET",
      "description": "Tu ClientSecret (una sola vez; no lo compartas)"
    },
    {
      "key": "accountId",
      "value": "TU_ACCOUNT_ID",
      "description": "Lo devuelve GET /api/v1/accounts (copia account_id de la respuesta)"
    },
    {
      "key": "accountId2",
      "value": "TU_ACCOUNT_ID_2"
    },
    {
      "key": "accessToken",
      "value": "",
      "description": "Se autocompleta con los tests del request Obtener Token"
    },
    {
      "key": "movimientoId",
      "value": "TU_MOVIMIENTO_ID",
      "description": "id de un movimiento, sale de la respuesta de /transactions"
    }
  ],
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{accessToken}}"
      }
    ]
  },
  "item": [
    {
      "name": "1. OAuth",
      "item": [
        {
          "name": "Obtener Token (form body)",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));",
                  "pm.test('Tiene access_token', () => pm.expect(pm.response.json().access_token).to.be.ok);",
                  "pm.test('Scope correcto', () => pm.expect(pm.response.json().scope).to.include('cuentas:read'));",
                  "pm.collectionVariables.set('accessToken', pm.response.json().access_token);"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [],
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                { "key": "grant_type", "value": "client_credentials" },
                { "key": "client_id", "value": "{{clientId}}" },
                { "key": "client_secret", "value": "{{clientSecret}}" }
              ]
            },
            "url": {
              "raw": "{{baseUrl}}/oauth2/token",
              "host": ["{{baseUrl}}"],
              "path": ["oauth2", "token"]
            }
          }
        },
        {
          "name": "Obtener Token (Basic auth)",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));",
                  "pm.collectionVariables.set('accessToken', pm.response.json().access_token);"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              { "key": "Authorization", "value": "Basic {{clientId}}:{{clientSecret}}" }
            ],
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                { "key": "grant_type", "value": "client_credentials" }
              ]
            },
            "url": {
              "raw": "{{baseUrl}}/oauth2/token",
              "host": ["{{baseUrl}}"],
              "path": ["oauth2", "token"]
            }
          }
        },
        {
          "name": "Token con scope específico",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));",
                  "pm.collectionVariables.set('accessToken', pm.response.json().access_token);"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [],
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                { "key": "grant_type", "value": "client_credentials" },
                { "key": "client_id", "value": "{{clientId}}" },
                { "key": "client_secret", "value": "{{clientSecret}}" },
                { "key": "scope", "value": "cuentas:read movimientos:read" }
              ]
            },
            "url": {
              "raw": "{{baseUrl}}/oauth2/token",
              "host": ["{{baseUrl}}"],
              "path": ["oauth2", "token"]
            }
          }
        },
        {
          "name": "Token con credenciales inválidas",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 401', () => pm.response.to.have.status(401));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [],
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                { "key": "grant_type", "value": "client_credentials" },
                { "key": "client_id", "value": "client-inexistente" },
                { "key": "client_secret", "value": "secreto-malo" }
              ]
            },
            "url": {
              "raw": "{{baseUrl}}/oauth2/token",
              "host": ["{{baseUrl}}"],
              "path": ["oauth2", "token"]
            }
          }
        }
      ]
    },
    {
      "name": "2. Cuentas",
      "item": [
        {
          "name": "Listar cuentas asignadas",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));",
                  "pm.test('Tiene cuentas', () => pm.expect(pm.response.json().data.count).to.be.above(0));",
                  "pm.test('Tiene account_id', () => pm.expect(pm.response.json().data.accounts[0].account_id).to.be.ok);"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/accounts",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "accounts"]
            }
          }
        },
        {
          "name": "Balance de cuenta",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));",
                  "pm.test('Tiene saldo', () => pm.expect(pm.response.json().data.available_balance).to.be.a('number'));",
                  "pm.test('Tiene account_id', () => pm.expect(pm.response.json().data.account_id).to.equal(pm.environment.get('accountId') || pm.collectionVariables.get('accountId')));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/accounts/{{accountId}}/balance",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "accounts", "{{accountId}}", "balance"]
            }
          }
        },
        {
          "name": "Balance sin token (401)",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 401', () => pm.response.to.have.status(401));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "auth": {
              "type": "noauth"
            },
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/accounts/{{accountId}}/balance",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "accounts", "{{accountId}}", "balance"]
            }
          }
        }
      ]
    },
    {
      "name": "3. Movimientos",
      "item": [
        {
          "name": "Movimientos (take=5)",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));",
                  "pm.test('Tiene data', () => pm.expect(pm.response.json().data).to.exist);",
                  "pm.test('Tiene rows', () => pm.expect(pm.response.json().data.data.data.rows).to.be.an('array'));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/accounts/{{accountId}}/transactions?take=5",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "accounts", "{{accountId}}", "transactions"],
              "query": [
                { "key": "take", "value": "5" }
              ]
            }
          }
        },
        {
          "name": "Movimientos con filtro DEBIT",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/accounts/{{accountId}}/transactions?type=DEBIT&take=5",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "accounts", "{{accountId}}", "transactions"],
              "query": [
                { "key": "type", "value": "DEBIT" },
                { "key": "take", "value": "5" }
              ]
            }
          }
        },
        {
          "name": "Movimientos con filtro SUCCESSFUL",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/accounts/{{accountId}}/transactions?status=SUCCESSFUL&take=5",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "accounts", "{{accountId}}", "transactions"],
              "query": [
                { "key": "status", "value": "SUCCESSFUL" },
                { "key": "take", "value": "5" }
              ]
            }
          }
        },
        {
          "name": "Movimientos con rango de fechas",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/accounts/{{accountId}}/transactions?from=2026-09-01&to=2026-10-02&take=5",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "accounts", "{{accountId}}", "transactions"],
              "query": [
                { "key": "from", "value": "2026-09-01" },
                { "key": "to", "value": "2026-10-02" },
                { "key": "take", "value": "5" }
              ]
            }
          }
        },
        {
          "name": "Movimientos paginados (skip=5, take=3)",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/accounts/{{accountId}}/transactions?skip=5&take=3",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "accounts", "{{accountId}}", "transactions"],
              "query": [
                { "key": "skip", "value": "5" },
                { "key": "take", "value": "3" }
              ]
            }
          }
        },
        {
          "name": "Cuenta no asignada (403)",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 403', () => pm.response.to.have.status(403));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/accounts/cuenta-inexistente/transactions?take=5",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "accounts", "cuenta-inexistente", "transactions"],
              "query": [
                { "key": "take", "value": "5" }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "4. Comprobantes",
      "item": [
        {
          "name": "Comprobante operación inexistente (404)",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 404', () => pm.response.to.have.status(404));",
                  "pm.test('Tiene error code', () => pm.expect(pm.response.json().error.code).to.equal('operation_not_found'));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/comprobantes/99999",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "comprobantes", "99999"]
            }
          }
        }
      ]
    },
    {
      "name": "5. Web UI (comprobante desde movimiento)",
      "item": [
        {
          "name": "Comprobante de movimiento (HTML)",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));",
                  "pm.test('Es HTML', () => pm.expect(pm.response.headers.get('Content-Type')).to.include('text/html'));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/cuenta-virtual/comprobante-movimiento/{{movimientoId}}",
              "host": ["{{baseUrl}}"],
              "path": ["api", "cuenta-virtual", "comprobante-movimiento", "{{movimientoId}}"]
            }
          }
        },
        {
          "name": "Detalle de movimiento",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test('Status 200', () => pm.response.to.have.status(200));"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/cuenta-virtual/movimientos/{{movimientoId}}",
              "host": ["{{baseUrl}}"],
              "path": ["api", "cuenta-virtual", "movimientos", "{{movimientoId}}"]
            }
          }
        }
      ]
    }
  ]
}
