From 4ef92a4e6756afde65af9a8ee0765800d27612b9 Mon Sep 17 00:00:00 2001 From: Brian Alexander Date: Sat, 11 May 2024 13:52:14 -0600 Subject: [PATCH] integration test to prepare for perspectives --- test/integration_test.exs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/test/integration_test.exs b/test/integration_test.exs index 2bd2513..5065ddb 100644 --- a/test/integration_test.exs +++ b/test/integration_test.exs @@ -131,7 +131,12 @@ defmodule Sanity.MutateIntegrationTest do type = "streamItem#{:rand.uniform(1_000_000)}" Sanity.mutate(Enum.map(1..5, &%{create: %{_type: type, title: "item #{&1}"}})) - |> Sanity.request(config) + |> Sanity.request!(config) + + Sanity.mutate([ + %{create: %{_id: "drafts.a-#{:rand.uniform(1_000_000)}", _type: type, title: "my draft"}} + ]) + |> Sanity.request!(config) assert [ %{"title" => "item 1"}, @@ -143,10 +148,28 @@ defmodule Sanity.MutateIntegrationTest do Sanity.stream(query: "_type == '#{type}'", batch_size: 2, request_opts: config) |> Enum.to_list() |> Enum.sort_by(& &1["title"]) + + # Only draft documents + assert [%{"title" => "my draft"}] = + Sanity.stream(query: "_type == '#{type}'", drafts: :only, request_opts: config) + |> Enum.to_list() + + # Include both drafts and published documents + assert [ + %{"title" => "my draft"}, + %{"title" => "item 1"}, + %{"title" => "item 2"}, + %{"title" => "item 3"}, + %{"title" => "item 4"}, + %{"title" => "item 5"} + ] = + Sanity.stream(query: "_type == '#{type}'", drafts: :include, 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) + config = Keyword.put(config, :http_options, receive_timeout: 0, retry: false) assert_raise Sanity.Error, "%Mint.TransportError{reason: :timeout}", fn -> Sanity.query(~S<{"hello": "world"}>)