This is Playwright API test file using OpenAPI generator. Can I optimize the tests?

tests:

import { test, expect } from '@playwright/test';
import { DetailsQuery } from '../../generated';
import { detailsApi } from '../../utils/apiClient';

test.describe('Details API Tests', () => {
  let responseBody: DetailsQuery;

  test.beforeAll(async () => {
    const response = await detailsApi.getDetailsRaw({});
    expect(response.raw.status).toBe(200);
    responseBody = await response.value();
  });

  test('should contain the defined range values', () => {
    const results = responseBody.results;
    expect(results.length).toBe(3);
    expect(results[0]).toEqual(expect.objectContaining({ fromRange: 0, toRange: 499 }));
    expect(results[1]).toEqual(expect.objectContaining({ fromRange: 500, toRange: 2000 }));
    expect(results[2]).toEqual(expect.objectContaining({ fromRange: 2001, toRange: 30000 }));
  });

  test('should have the proper structure and static query values', () => {
    expect(responseBody.query).toEqual({ fromDate: null, toDate: null });

    for (const result of responseBody.results) {
      for (const stat of [result.topAirlines!, result.topDestinations!, result.topAircrafts!]) {
        expect(stat.content).toEqual(expect.any(Array));
        expect(typeof stat.totalCount).toBe('number');
      }

      expect(result.busiestWeekdays).toBeDefined();
      for (const day of result.busiestWeekdays!) {
        expect(typeof day.label).toBe('string');
        expect(typeof day.value).toBe('number');
      }
    }
  });

  test('should filter details by specific airline ICAO', async () => {
    const response = await detailsApi.getDetailsRaw({
      filter: {
        fromDate: '2025-03-01T00:00:00.000Z',
        toDate: '2025-04-01T00:00:00.000Z',
        airlineIcao: 'BAW',
      },
    });

    expect(response.raw.status).toBe(200);
    const body = await response.value();

    expect(body.query).toEqual({
      fromDate: '2025-03-01T00:00:00.000Z',
      toDate: '2025-04-01T00:00:00.000Z',
    });

    expect(body.results.length).toBeGreaterThan(0);
  });

  test('should return empty stats when only date range is provided', async () => {
    const response = await detailsApi.getDetailsRaw({
      filter: {
        fromDate: '2025-03-01T00:00:00.000Z',
        toDate: '2025-04-01T00:00:00.000Z',
      },
    });

    expect(response.raw.status).toBe(200);
    const body = await response.value();

    expect(body.query).toEqual({
      fromDate: '2025-03-01T00:00:00.000Z',
      toDate: '2025-04-01T00:00:00.000Z',
    });

    expect(body.results.length).toBe(3);

    for (const result of body.results) {
      expect(result.fleetSize ?? null).toBeNull();
      expect(result.yearEstablished ?? null).toBeNull();
      expect(result.averageFleetAge ?? null).toBeNull();

      expect(result.topAirlines).toEqual({ content: [], totalCount: 0 });
      expect(result.topDestinations).toEqual({ content: [], totalCount: 0 });
      expect(result.topAircrafts).toEqual({ content: [], totalCount: 0 });

      expect(result.busiestWeekdays).toHaveLength(7);
      for (const day of result.busiestWeekdays!) {
        expect(typeof day.label).toBe('string');
        expect(day.value).toBe(0);
      }
    }
  });
});


apiClient.ts:

import { Configuration, DetailsApi, SummariesApi } from '../generated';

const config = new Configuration({ basePath: 'http://localhost:8080' });

export const detailsApi = new DetailsApi(config);
export const summariesApi = new SummariesApi(config);


DetailsQuery.ts:

/* tslint:disable */
/* eslint-disable */
/**
 * Flights Tracker
 * API for Flights Tracker
 *
 * The version of the OpenAPI document: 1.0.0
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

import { mapValues } from '../runtime';
import type { Details } from './Details';
import {
    DetailsFromJSON,
    DetailsFromJSONTyped,
    DetailsToJSON,
    DetailsToJSONTyped,
} from './Details';
import type { Query } from './Query';
import {
    QueryFromJSON,
    QueryFromJSONTyped,
    QueryToJSON,
    QueryToJSONTyped,
} from './Query';

/**
 * 
 * @export
 * @interface DetailsQuery
 */
export interface DetailsQuery {
    /**
     * 
     * @type {Query}
     * @memberof DetailsQuery
     */
    query: Query;
    /**
     * 
     * @type {Array<Details>}
     * @memberof DetailsQuery
     */
    results: Array<Details>;
}

/**
 * Check if a given object implements the DetailsQuery interface.
 */
export function instanceOfDetailsQuery(value: object): value is DetailsQuery {
    if (!('query' in value) || value['query'] === undefined) return false;
    if (!('results' in value) || value['results'] === undefined) return false;
    return true;
}

export function DetailsQueryFromJSON(json: any): DetailsQuery {
    return DetailsQueryFromJSONTyped(json, false);
}

export function DetailsQueryFromJSONTyped(json: any, ignoreDiscriminator: boolean): DetailsQuery {
    if (json == null) {
        return json;
    }
    return {
        
        'query': QueryFromJSON(json['query']),
        'results': ((json['results'] as Array<any>).map(DetailsFromJSON)),
    };
}

export function DetailsQueryToJSON(json: any): DetailsQuery {
    return DetailsQueryToJSONTyped(json, false);
}

export function DetailsQueryToJSONTyped(value?: DetailsQuery | null, ignoreDiscriminator: boolean = false): any {
    if (value == null) {
        return value;
    }

    return {
        
        'query': QueryToJSON(value['query']),
        'results': ((value['results'] as Array<any>).map(DetailsToJSON)),
    };
}