import { APIResponse } from '@playwright/test';
import { ApiTestState } from './fixtures';

/**
 * Stores a response and its parsed body/status into apiState.
 */
export async function storeResponse(
  response: APIResponse,
  apiState: ApiTestState
): Promise<void> {
  apiState.lastResponse = response;
  apiState.lastStatus = response.status();
  try {
    apiState.lastBody = await response.json();
  } catch {
    apiState.lastBody = null;
  }
}
