Skip to content

Commit

Permalink
integration tests for stream and timeout error
Browse files Browse the repository at this point in the history
  • Loading branch information
balexand committed May 10, 2024
1 parent b5265bb commit d618645
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,31 @@ defmodule Sanity.MutateIntegrationTest do
Sanity.query(~S<{"hello": "world"}>)
|> Sanity.request(Keyword.put(config, :cdn, true))
end

test "stream", %{config: config} do
type = "streamItem#{:rand.uniform(1_000_000)}"

Sanity.mutate(Enum.map(1..5, &%{create: %{_type: type, title: "item #{&1}"}}))
|> Sanity.request(config)

assert [
%{"title" => "item 1"},
%{"title" => "item 2"},
%{"title" => "item 3"},
%{"title" => "item 4"},
%{"title" => "item 5"}
] =
Sanity.stream(query: "_type == '#{type}'", batch_size: 2, request_opts: config)
|> Enum.to_list()
|> Enum.sort_by(& &1["title"])
end

test "timeout error", %{config: config} do
config = Keyword.put(config, :http_options, receive_timeout: 0, retry_log_level: false)

assert_raise Sanity.Error, "%Mint.TransportError{reason: :timeout}", fn ->
Sanity.query(~S<{"hello": "world"}>)
|> Sanity.request(config)
end
end
end

0 comments on commit d618645

Please sign in to comment.