# frozen_string_literal: true

require_relative "../spec_helper"
require_relative "worker"

RSpec.describe "DurableWorkflow" do
  it "completes a durable sleep then waits for event" do
    ref = DURABLE_WORKFLOW.run_no_wait

    wait_for_running_status(HATCHET, ref.workflow_run_id)
    sleep(DURABLE_SLEEP_TIME + 3)

    # Push the event to unblock the durable task
    HATCHET.events.create(key: DURABLE_EVENT_KEY, data: { "test" => true })

    result = ref.result
    expect(result["durable_task"]["status"]).to eq("success")
  end

  it "handles multi-sleep in durable tasks" do
    result = WAIT_FOR_SLEEP_TWICE.run

    expect(result["runtime"]).to be >= DURABLE_SLEEP_TIME
  end
end
