{
  "name": "Обновление токена, затем 503: повтор идёт с новым токеном из кэша, без запроса токена",
  "description": "Клиент с maxRetries = 2. Первый вызов получает токен T1 и кладёт его в кэш. Второй (adjustMemberPoints) берёт T1 из кэша и получает 401 — токен получен не этим вызовом: SDK забывает его, получает T2 и без паузы повторяет попытку, она получает 503. Повтор после 503 — первый повтор вызова (пауза 500 мс: повтор после обновления токена номер повтора не увеличивает) — берёт T2 из кэша без нового запроса токена: T2 получен этим вызовом. Ключ идемпотентности один во всех трёх попытках.",
  "client": {
    "api": "management",
    "credential": {
      "clientCredentials": {
        "clientId": "lc_test_4b9ac4f5d6cc6783a2044a5a",
        "clientSecret": "lcs_test__A75hCwHKWYA61AD1WKWOkjtKvU2hRnSKCx_YVFfVos"
      }
    },
    "baseUrl": "https://api.example.com",
    "maxRetries": 2,
    "merchant": "01929c1e-0020-7020-8020-000000000020"
  },
  "calls": [
    {
      "operation": "getLocation",
      "args": {"location": "01929c1e-0030-7030-8030-000000000030"},
      "expect": {
        "result": {
          "id": "01929c1e-0030-7030-8030-000000000030",
          "code": "msk-01",
          "name": "Кофейня на Тверской",
          "address": "Москва, Тверская ул., 1",
          "timezone": "Europe/Moscow",
          "brand_id": null,
          "legal_entity_id": null,
          "status": "active"
        }
      }
    },
    {
      "operation": "adjustMemberPoints",
      "args": {"member": "01929c1e-0040-7040-8040-000000000040", "body": {"amount": 500, "reason_code": "goodwill"}},
      "expect": {
        "result": {
          "transaction_id": "01929c1e-0093-7093-8093-000000000093",
          "amount": 500,
          "member_delta": 500,
          "available": 1535
        },
        "meta": {"operationId": "adjustMemberPoints", "status": 201, "requestId": "01929c20-0006-7000-8000-000000000006"}
      }
    }
  ],
  "exchanges": [
    {
      "request": {
        "method": "POST",
        "url": "https://api.example.com/api/management/v1/oauth/token",
        "headers": {
          "authorization": "Basic bGNfdGVzdF80YjlhYzRmNWQ2Y2M2NzgzYTIwNDRhNWE6bGNzX3Rlc3RfX0E3NWhDd0hLV1lBNjFBRDFXS1dPa2p0S3ZVMmhSblNLQ3hfWVZGZlZvcw==",
          "accept": "application/json",
          "content-type": "application/x-www-form-urlencoded",
          "idempotency-key": null,
          "loyal-merchant": null
        },
        "form": {"grant_type": "client_credentials"}
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json",
          "X-Request-Id": "01929c20-0001-7000-8000-000000000001",
          "Loyal-Environment": "sandbox",
          "Cache-Control": "no-store",
          "Pragma": "no-cache"
        },
        "json": {
          "access_token": "lat_test_8NfzE9KomDFUk3lfJjBaLz0-9r7ns5Uo2tYUpmVlUcE",
          "token_type": "Bearer",
          "expires_in": 3600,
          "scope": "merchants programs organization members webhooks reports"
        }
      }
    },
    {
      "request": {
        "method": "GET",
        "url": "https://api.example.com/api/management/v1/locations/01929c1e-0030-7030-8030-000000000030",
        "headers": {
          "authorization": "Bearer lat_test_8NfzE9KomDFUk3lfJjBaLz0-9r7ns5Uo2tYUpmVlUcE",
          "accept": "application/json",
          "content-type": null,
          "idempotency-key": null,
          "loyal-merchant": "01929c1e-0020-7020-8020-000000000020"
        }
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json",
          "X-Request-Id": "01929c20-0002-7000-8000-000000000002",
          "Loyal-Environment": "sandbox"
        },
        "json": {
          "id": "01929c1e-0030-7030-8030-000000000030",
          "code": "msk-01",
          "name": "Кофейня на Тверской",
          "address": "Москва, Тверская ул., 1",
          "timezone": "Europe/Moscow",
          "brand_id": null,
          "legal_entity_id": null,
          "status": "active"
        }
      }
    },
    {
      "request": {
        "method": "POST",
        "url": "https://api.example.com/api/management/v1/members/01929c1e-0040-7040-8040-000000000040/point-adjustments",
        "headers": {
          "authorization": "Bearer lat_test_8NfzE9KomDFUk3lfJjBaLz0-9r7ns5Uo2tYUpmVlUcE",
          "accept": "application/json",
          "content-type": "application/json",
          "idempotency-key": "{{idempotency-key}}",
          "loyal-merchant": "01929c1e-0020-7020-8020-000000000020"
        },
        "json": {"amount": 500, "reason_code": "goodwill"}
      },
      "response": {
        "status": 401,
        "headers": {
          "Content-Type": "application/problem+json",
          "X-Request-Id": "01929c20-0003-7000-8000-000000000003",
          "Loyal-Environment": "sandbox",
          "WWW-Authenticate": "Bearer realm=\"loyal\""
        },
        "json": {
          "type": "urn:loyal:problem:unauthenticated",
          "title": "A valid access token is required.",
          "status": 401,
          "code": "unauthenticated",
          "request_id": "01929c20-0003-7000-8000-000000000003"
        }
      }
    },
    {
      "request": {
        "method": "POST",
        "url": "https://api.example.com/api/management/v1/oauth/token",
        "headers": {
          "authorization": "Basic bGNfdGVzdF80YjlhYzRmNWQ2Y2M2NzgzYTIwNDRhNWE6bGNzX3Rlc3RfX0E3NWhDd0hLV1lBNjFBRDFXS1dPa2p0S3ZVMmhSblNLQ3hfWVZGZlZvcw==",
          "accept": "application/json",
          "content-type": "application/x-www-form-urlencoded",
          "idempotency-key": null,
          "loyal-merchant": null
        },
        "form": {"grant_type": "client_credentials"}
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json",
          "X-Request-Id": "01929c20-0004-7000-8000-000000000004",
          "Loyal-Environment": "sandbox",
          "Cache-Control": "no-store",
          "Pragma": "no-cache"
        },
        "json": {
          "access_token": "lat_test_qvV4pHbQkRVZU2JGlM8sDbPPc66wzxY0WJUD2RPnjjA",
          "token_type": "Bearer",
          "expires_in": 3600,
          "scope": "merchants programs organization members webhooks reports"
        }
      }
    },
    {
      "request": {
        "method": "POST",
        "url": "https://api.example.com/api/management/v1/members/01929c1e-0040-7040-8040-000000000040/point-adjustments",
        "headers": {
          "authorization": "Bearer lat_test_qvV4pHbQkRVZU2JGlM8sDbPPc66wzxY0WJUD2RPnjjA",
          "accept": "application/json",
          "content-type": "application/json",
          "idempotency-key": "{{idempotency-key}}",
          "loyal-merchant": "01929c1e-0020-7020-8020-000000000020"
        },
        "json": {"amount": 500, "reason_code": "goodwill"}
      },
      "response": {
        "status": 503,
        "headers": {
          "Content-Type": "application/problem+json",
          "X-Request-Id": "01929c20-0005-7000-8000-000000000005",
          "Loyal-Environment": "sandbox"
        },
        "json": {
          "type": "urn:loyal:problem:http_503",
          "title": "Service Unavailable",
          "status": 503,
          "code": "http_503",
          "request_id": "01929c20-0005-7000-8000-000000000005"
        }
      }
    },
    {
      "request": {
        "method": "POST",
        "url": "https://api.example.com/api/management/v1/members/01929c1e-0040-7040-8040-000000000040/point-adjustments",
        "headers": {
          "authorization": "Bearer lat_test_qvV4pHbQkRVZU2JGlM8sDbPPc66wzxY0WJUD2RPnjjA",
          "accept": "application/json",
          "content-type": "application/json",
          "idempotency-key": "{{idempotency-key}}",
          "loyal-merchant": "01929c1e-0020-7020-8020-000000000020"
        },
        "json": {"amount": 500, "reason_code": "goodwill"}
      },
      "response": {
        "status": 201,
        "headers": {
          "Content-Type": "application/json",
          "X-Request-Id": "01929c20-0006-7000-8000-000000000006",
          "Loyal-Environment": "sandbox"
        },
        "json": {
          "transaction_id": "01929c1e-0093-7093-8093-000000000093",
          "amount": 500,
          "member_delta": 500,
          "available": 1535
        }
      }
    }
  ],
  "sleeps": [500]
}
