Skip to content

Commit 69b62c5

Browse files
authored
Update duplicate collection name in join_test (#24)
1 parent 5298c5e commit 69b62c5

6 files changed

Lines changed: 72 additions & 54 deletions

File tree

config/config.exs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
import Config
22

3-
if config_env() in [:dev, :test] do
4-
config :open_api_typesense,
5-
api_key: "xyz",
6-
host: "localhost",
7-
port: 8108,
8-
scheme: "http"
9-
end
10-
11-
if config_env() in [:dev] do
12-
config :oapi_generator,
13-
default: [
14-
output: [
15-
base_module: OpenApiTypesense,
16-
location: "lib/open_api_typesense",
17-
operation_subdirectory: "operations/",
18-
schema_subdirectory: "schemas/"
19-
]
20-
]
21-
end
3+
# Import environment specific config. This must remain at the bottom
4+
# of this file so it overrides the configuration defined above.
5+
import_config "#{config_env()}.exs"

config/dev.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Config
2+
3+
config :open_api_typesense,
4+
api_key: "xyz",
5+
host: "localhost",
6+
port: 8108,
7+
scheme: "http"
8+
9+
config :oapi_generator,
10+
default: [
11+
output: [
12+
base_module: OpenApiTypesense,
13+
location: "lib/open_api_typesense",
14+
operation_subdirectory: "operations/",
15+
schema_subdirectory: "schemas/"
16+
]
17+
]

config/test.exs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Config
2+
3+
config :open_api_typesense,
4+
api_key: "xyz",
5+
host: "localhost",
6+
port: 8108,
7+
scheme: "http",
8+
max_retries: 0,
9+
retry: false

lib/open_api_typesense/client.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ defmodule OpenApiTypesense.Client do
3737
@spec get_client :: keyword() | nil
3838
def get_client, do: Application.get_env(:open_api_typesense, :client)
3939

40+
defp test_max_retries, do: Application.get_env(:open_api_typesense, :max_retries)
41+
defp test_retry, do: Application.get_env(:open_api_typesense, :retry)
42+
4043
@doc """
4144
Returns the Typesense's API key
4245
@@ -110,8 +113,8 @@ defmodule OpenApiTypesense.Client do
110113
method: opts[:method] || :get,
111114
body: encode_body(opts),
112115
url: url,
113-
max_retries: opts[:req][:max_retries] || 3,
114-
retry: opts[:req][:retry] || :safe_transient,
116+
max_retries: test_max_retries() || opts[:req][:max_retries] || 3,
117+
retry: test_retry() || opts[:req][:retry] || :safe_transient,
115118
compress_body: opts[:req][:compress] || false,
116119
cache: opts[:req][:cache] || false,
117120
decode_json: [keys: :atoms]

test/operations/collections_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ defmodule CollectionsTest do
104104

105105
body = %{fields: [%{name: "price", drop: true}]}
106106

107-
assert {:ok, %CollectionUpdateSchema{}} =
107+
assert {:ok, %CollectionUpdateSchema{fields: [%{name: "price", drop: true}]}} =
108108
Collections.update_collection(name, body)
109109

110110
assert {:error, %ApiResponse{message: _}} = Collections.update_collection(name, body, [])

test/operations/join_test.exs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
defmodule JoinTest do
22
use ExUnit.Case, async: true
33

4-
alias OpenApiTypesense.ApiResponse
54
alias OpenApiTypesense.Collections
65
alias OpenApiTypesense.Documents
76
alias OpenApiTypesense.MultiSearchResult
@@ -45,7 +44,7 @@ defmodule JoinTest do
4544
}
4645

4746
product_schema = %{
48-
name: "products",
47+
name: "join_products",
4948
fields: [
5049
%{name: "product_id", type: "string"},
5150
%{name: "product_name", type: "string"},
@@ -58,7 +57,7 @@ defmodule JoinTest do
5857
fields: [
5958
%{name: "title", type: "string"},
6059
%{name: "price", type: "float"},
61-
%{name: "product_id", type: "string", reference: "products.product_id"}
60+
%{name: "product_id", type: "string", reference: "join_products.product_id"}
6261
]
6362
}
6463

@@ -84,7 +83,7 @@ defmodule JoinTest do
8483
fields: [
8584
%{name: "customer_id", type: "string"},
8685
%{name: "custom_price", type: "float"},
87-
%{name: "product_id", type: "string", reference: "products.product_id"}
86+
%{name: "product_id", type: "string", reference: "join_products.product_id"}
8887
]
8988
}
9089

@@ -113,18 +112,21 @@ defmodule JoinTest do
113112
]
114113
}
115114

116-
{:ok, _} = Collections.create_collection(author_schema)
117-
{:ok, _} = Collections.create_collection(book_schema)
118-
{:ok, _} = Collections.create_collection(customer_schema)
119-
{:ok, _} = Collections.create_collection(order_schema)
120-
{:ok, _} = Collections.create_collection(product_schema)
121-
{:ok, _} = Collections.create_collection(product_variant_schema)
122-
{:ok, _} = Collections.create_collection(retailer_schema)
123-
{:ok, _} = Collections.create_collection(inventory_schema)
124-
{:ok, _} = Collections.create_collection(customer_product_prices_schema)
125-
{:ok, _} = Collections.create_collection(document_schema)
126-
{:ok, _} = Collections.create_collection(user_schema)
127-
{:ok, _} = Collections.create_collection(user_doc_access_schema)
115+
[
116+
author_schema,
117+
book_schema,
118+
customer_schema,
119+
order_schema,
120+
product_schema,
121+
product_variant_schema,
122+
retailer_schema,
123+
inventory_schema,
124+
customer_product_prices_schema,
125+
document_schema,
126+
user_schema,
127+
user_doc_access_schema
128+
]
129+
|> Enum.each(&Collections.create_collection/1)
128130

129131
[
130132
%{
@@ -323,18 +325,21 @@ defmodule JoinTest do
323325
end)
324326

325327
on_exit(fn ->
326-
{:ok, _} = Collections.delete_collection(author_schema.name)
327-
{:ok, _} = Collections.delete_collection(book_schema.name)
328-
{:ok, _} = Collections.delete_collection(customer_schema.name)
329-
{:ok, _} = Collections.delete_collection(order_schema.name)
330-
{:ok, _} = Collections.delete_collection(product_schema.name)
331-
{:ok, _} = Collections.delete_collection(product_variant_schema.name)
332-
{:ok, _} = Collections.delete_collection(retailer_schema.name)
333-
{:ok, _} = Collections.delete_collection(inventory_schema.name)
334-
{:ok, _} = Collections.delete_collection(customer_product_prices_schema.name)
335-
{:ok, _} = Collections.delete_collection(document_schema.name)
336-
{:ok, _} = Collections.delete_collection(user_schema.name)
337-
{:ok, _} = Collections.delete_collection(user_doc_access_schema.name)
328+
[
329+
author_schema.name,
330+
book_schema.name,
331+
customer_schema.name,
332+
order_schema.name,
333+
product_schema.name,
334+
product_variant_schema.name,
335+
retailer_schema.name,
336+
inventory_schema.name,
337+
customer_product_prices_schema.name,
338+
document_schema.name,
339+
user_schema.name,
340+
user_doc_access_schema.name
341+
]
342+
|> Enum.each(&Collections.delete_collection/1)
338343
end)
339344

340345
:ok
@@ -437,12 +442,12 @@ defmodule JoinTest do
437442
searches: [
438443
%{
439444
q: "*",
440-
collection: "products",
445+
collection: "join_products",
441446
filter_by: "$customer_product_prices(customer_id:=1)"
442447
},
443448
%{
444449
q: "*",
445-
collection: "products",
450+
collection: "join_products",
446451
filter_by: "$customer_product_prices(customer_id:=1 && custom_price:<=100)"
447452
}
448453
]
@@ -626,7 +631,7 @@ defmodule JoinTest do
626631
]
627632
}
628633
]
629-
}} = Documents.search("products", opts)
634+
}} = Documents.search("join_products", opts)
630635
end
631636

632637
@tag ["27.1": true, "27.0": true, "26.0": true]
@@ -660,6 +665,6 @@ defmodule JoinTest do
660665
}
661666
}
662667
]
663-
}} = Documents.search("products", opts)
668+
}} = Documents.search("join_products", opts)
664669
end
665670
end

0 commit comments

Comments
 (0)