11#![ allow( dead_code) ]
22
3+ use super :: Config ;
34use serde:: { Deserialize , Serialize } ;
45use typesense:: document:: Document ;
56use typesense:: Typesense ;
67use typesense_codegen:: apis:: collections_api;
7- use typesense_codegen:: apis:: configuration:: { ApiKey , Configuration } ;
8- use typesense_codegen:: models:: CollectionResponse ;
9- use typesense_codegen:: models:: CollectionSchema ;
8+ use typesense_codegen:: models:: { CollectionResponse , CollectionSchema } ;
109
1110#[ derive( Typesense , Serialize , Deserialize ) ]
1211#[ typesense( collection_name = "companies" , default_sorting_field = "num_employees" ) ]
@@ -30,18 +29,9 @@ fn schema_to_resp(schema: CollectionSchema, resp: &CollectionResponse) -> Collec
3029 }
3130}
3231
33- async fn create_collection ( host : impl Into < String > , api_key : impl Into < String > ) {
34- let config = Configuration {
35- base_path : host. into ( ) ,
36- api_key : Some ( ApiKey {
37- prefix : None ,
38- key : api_key. into ( ) ,
39- } ) ,
40- ..Default :: default ( )
41- } ;
42-
32+ async fn create_collection ( ) {
4333 let collection_schema_response =
44- collections_api:: create_collection ( & config , Company :: collection_schema ( ) )
34+ collections_api:: create_collection ( Config :: get ( ) , Company :: collection_schema ( ) )
4535 . await
4636 . unwrap ( ) ;
4737
@@ -52,17 +42,8 @@ async fn create_collection(host: impl Into<String>, api_key: impl Into<String>)
5242 ) ;
5343}
5444
55- async fn get_collection ( host : impl Into < String > , api_key : impl Into < String > ) {
56- let config = Configuration {
57- base_path : host. into ( ) ,
58- api_key : Some ( ApiKey {
59- prefix : None ,
60- key : api_key. into ( ) ,
61- } ) ,
62- ..Default :: default ( )
63- } ;
64-
65- let collection_schema_response = collections_api:: get_collection ( & config, "companies" )
45+ async fn get_collection ( ) {
46+ let collection_schema_response = collections_api:: get_collection ( Config :: get ( ) , "companies" )
6647 . await
6748 . unwrap ( ) ;
6849
@@ -73,17 +54,8 @@ async fn get_collection(host: impl Into<String>, api_key: impl Into<String>) {
7354 ) ;
7455}
7556
76- async fn delete_collection ( host : impl Into < String > , api_key : impl Into < String > ) {
77- let config = Configuration {
78- base_path : host. into ( ) ,
79- api_key : Some ( ApiKey {
80- prefix : None ,
81- key : api_key. into ( ) ,
82- } ) ,
83- ..Default :: default ( )
84- } ;
85-
86- let collection_schema_response = collections_api:: delete_collection ( & config, "companies" )
57+ async fn delete_collection ( ) {
58+ let collection_schema_response = collections_api:: delete_collection ( Config :: get ( ) , "companies" )
8759 . await
8860 . unwrap ( ) ;
8961
@@ -94,17 +66,10 @@ async fn delete_collection(host: impl Into<String>, api_key: impl Into<String>)
9466 ) ;
9567}
9668
97- async fn get_collections ( host : impl Into < String > , api_key : impl Into < String > ) {
98- let config = Configuration {
99- base_path : host. into ( ) ,
100- api_key : Some ( ApiKey {
101- prefix : None ,
102- key : api_key. into ( ) ,
103- } ) ,
104- ..Default :: default ( )
105- } ;
106-
107- let collection_schema_response = collections_api:: get_collections ( & config) . await . unwrap ( ) ;
69+ async fn get_collections ( ) {
70+ let collection_schema_response = collections_api:: get_collections ( Config :: get ( ) )
71+ . await
72+ . unwrap ( ) ;
10873
10974 assert_eq ! ( collection_schema_response. len( ) , 2 ) ;
11075}
@@ -115,42 +80,22 @@ mod tokio_test {
11580
11681 #[ tokio:: test]
11782 async fn create_collection_tokio ( ) {
118- let _ = dotenvy:: dotenv ( ) ;
119-
120- let host = std:: env:: var ( "URL" ) . expect ( "URL must be present in .env" ) ;
121- let api_key = std:: env:: var ( "API_KEY" ) . expect ( "API_KEY must be present in .env" ) ;
122-
123- create_collection ( host, api_key) . await
83+ create_collection ( ) . await
12484 }
12585
12686 #[ tokio:: test]
12787 async fn get_collection_tokio ( ) {
128- let _ = dotenvy:: dotenv ( ) ;
129-
130- let host = std:: env:: var ( "URL" ) . expect ( "URL must be present in .env" ) ;
131- let api_key = std:: env:: var ( "API_KEY" ) . expect ( "API_KEY must be present in .env" ) ;
132-
133- get_collection ( host, api_key) . await
88+ get_collection ( ) . await
13489 }
13590
13691 #[ tokio:: test]
13792 async fn delete_collection_tokio ( ) {
138- let _ = dotenvy:: dotenv ( ) ;
139-
140- let host = std:: env:: var ( "URL" ) . expect ( "URL must be present in .env" ) ;
141- let api_key = std:: env:: var ( "API_KEY" ) . expect ( "API_KEY must be present in .env" ) ;
142-
143- delete_collection ( host, api_key) . await
93+ delete_collection ( ) . await
14494 }
14595
14696 #[ tokio:: test]
14797 async fn get_collections_tokio ( ) {
148- let _ = dotenvy:: dotenv ( ) ;
149-
150- let host = std:: env:: var ( "URL" ) . expect ( "URL must be present in .env" ) ;
151- let api_key = std:: env:: var ( "API_KEY" ) . expect ( "API_KEY must be present in .env" ) ;
152-
153- get_collections ( host, api_key) . await
98+ get_collections ( ) . await
15499 }
155100}
156101
@@ -161,34 +106,31 @@ mod wasm_test {
161106
162107 wasm_bindgen_test:: wasm_bindgen_test_configure!( run_in_browser) ;
163108
164- const HOST : & str = "http://localhost:5000" ;
165- const API_KEY : & str = "VerySecretKey" ;
166-
167109 #[ wasm_bindgen_test]
168110 async fn create_collection_wasm ( ) {
169111 console_error_panic_hook:: set_once ( ) ;
170112
171- create_collection ( HOST , API_KEY ) . await
113+ create_collection ( ) . await
172114 }
173115
174116 #[ wasm_bindgen_test]
175117 async fn get_collection_wasm ( ) {
176118 console_error_panic_hook:: set_once ( ) ;
177119
178- get_collection ( HOST , API_KEY ) . await
120+ get_collection ( ) . await
179121 }
180122
181123 #[ wasm_bindgen_test]
182124 async fn delete_collection_wasm ( ) {
183125 console_error_panic_hook:: set_once ( ) ;
184126
185- delete_collection ( HOST , API_KEY ) . await
127+ delete_collection ( ) . await
186128 }
187129
188130 #[ wasm_bindgen_test]
189131 async fn get_collections_wasm ( ) {
190132 console_error_panic_hook:: set_once ( ) ;
191133
192- get_collections ( HOST , API_KEY ) . await
134+ get_collections ( ) . await
193135 }
194136}
0 commit comments