test: deflake livechat business-hours and room.forward queue tests

Merged
GG
3mo ago
+23-6

Proposed changes (including videos or screenshots)

Two unrelated flakes in the API Livechat (EE) suite, both surfaced in the merge queue (run 1, run 2) on a PR that only touches thread rendering — i.e. pre-existing flakes, not caused by that PR.

1. 19-business-hours.ts — agent status race

[CE][BH] On Agent created/removed › ... default business hour which is closed:

AssertionError: expected 'available' to equal 'not-available'
  at 19-business-hours.ts:972

Closing the default BH recalculates agent statuses via an async callback. The test closed the BH and immediately created a new agent — when the close had not propagated yet, the agent was created while the BH still counted as open and came up available, and nothing re-flips an already-created agent.

Fix: after closing the BH, poll the pre-existing agent until it loses the BH assignment (openBusinessHours empty — the same positive signal the next test already asserts) before creating the new agent. Replaces reliance on implicit timing with a bounded poll.

2. 00-rooms.ts — closing a queued room

livechat/room.forward ... waiting_queue enabled, but department is online, transfer should succeed but it should end queued on target:

Error: expected 200 "OK", got 400 "Bad Request"
  at closeOmnichannelRoom (tests/data/livechat/rooms.ts:428)
  at 00-rooms.ts:1793

The test's own scenario leaves the room queued (asserts inquiry.status === 'queued'). Cleanup then called closeOmnichannelRoom → room.closeByUser, which rejects a room that is not being served (400). It only passed when the queue processor happened to assign the room to the online target agent before cleanup ran — hence the flake.

Fix: close the room as the visitor (livechat/room.close with the visitor token), which is valid for a queued room, then run the rest of the cleanup.

Issue(s)

Steps to test or reproduce

yarn testapi:livechat --grep "On Agent created/removed"
yarn testapi:livechat --grep "should end queued on target"

Both races are load-dependent; the fixes remove the timing assumption rather than reproduce the race.

Further comments

Test-only, no changeset.

Task: ARCH-2294

Summary by CodeRabbit

  • Tests
    • Improved live chat end-to-end test cleanup to prevent room/department lifecycle conflicts during teardown.
    • Enhanced business-hours end-to-end tests with retry handling to better account for asynchronous propagation and reduce intermittent failures.