upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/login.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/login.rs')
-rw-r--r--tests/login.rs185
1 files changed, 95 insertions, 90 deletions
diff --git a/tests/login.rs b/tests/login.rs
index ee7450d..7fc9356 100644
--- a/tests/login.rs
+++ b/tests/login.rs
@@ -121,10 +121,10 @@ mod with_relays {
121 Ok(()) 121 Ok(())
122 } 122 }
123 123
124 #[test] 124 #[tokio::test]
125 #[serial] 125 #[serial]
126 fn when_latest_metadata_and_relay_list_on_all_relays() -> Result<()> { 126 async fn when_latest_metadata_and_relay_list_on_all_relays() -> Result<()> {
127 futures::executor::block_on(run_test_displays_correct_name( 127 run_test_displays_correct_name(
128 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 128 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
129 relay.respond_events( 129 relay.respond_events(
130 client_id, 130 client_id,
@@ -147,16 +147,17 @@ mod with_relays {
147 )?; 147 )?;
148 Ok(()) 148 Ok(())
149 }), 149 }),
150 )) 150 )
151 .await
151 } 152 }
152 153
153 mod poorly_quality_metadata_event { 154 mod poorly_quality_metadata_event {
154 use super::*; 155 use super::*;
155 156
156 #[test] 157 #[tokio::test]
157 #[serial] 158 #[serial]
158 fn when_metadata_contains_only_display_name() -> Result<()> { 159 async fn when_metadata_contains_only_display_name() -> Result<()> {
159 futures::executor::block_on(run_test_displays_correct_name( 160 run_test_displays_correct_name(
160 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 161 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
161 relay.respond_events( 162 relay.respond_events(
162 client_id, 163 client_id,
@@ -173,12 +174,13 @@ mod with_relays {
173 Ok(()) 174 Ok(())
174 }), 175 }),
175 None, 176 None,
176 )) 177 )
178 .await
177 } 179 }
178 180
179 #[test] 181 #[tokio::test]
180 #[serial] 182 #[serial]
181 fn when_metadata_contains_only_displayname() -> Result<()> { 183 async fn when_metadata_contains_only_displayname() -> Result<()> {
182 println!( 184 println!(
183 "displayName: {}", 185 "displayName: {}",
184 nostr::Metadata::new() 186 nostr::Metadata::new()
@@ -192,7 +194,7 @@ mod with_relays {
192 nostr::Metadata::new().name("fred").name.unwrap() 194 nostr::Metadata::new().name("fred").name.unwrap()
193 ); 195 );
194 196
195 futures::executor::block_on(run_test_displays_correct_name( 197 run_test_displays_correct_name(
196 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 198 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
197 relay.respond_events( 199 relay.respond_events(
198 client_id, 200 client_id,
@@ -210,12 +212,13 @@ mod with_relays {
210 Ok(()) 212 Ok(())
211 }), 213 }),
212 None, 214 None,
213 )) 215 )
216 .await
214 } 217 }
215 218
216 #[test] 219 #[tokio::test]
217 #[serial] 220 #[serial]
218 fn displays_npub_when_metadata_contains_no_name_displayname_or_display_name() 221 async fn displays_npub_when_metadata_contains_no_name_displayname_or_display_name()
219 -> Result<()> { 222 -> Result<()> {
220 println!( 223 println!(
221 "displayName: {}", 224 "displayName: {}",
@@ -230,7 +233,7 @@ mod with_relays {
230 nostr::Metadata::new().name("fred").name.unwrap() 233 nostr::Metadata::new().name("fred").name.unwrap()
231 ); 234 );
232 235
233 futures::executor::block_on(run_test_displays_fallback_to_npub( 236 run_test_displays_fallback_to_npub(
234 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 237 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
235 relay.respond_events( 238 relay.respond_events(
236 client_id, 239 client_id,
@@ -247,15 +250,16 @@ mod with_relays {
247 Ok(()) 250 Ok(())
248 }), 251 }),
249 None, 252 None,
250 )) 253 )
254 .await
251 } 255 }
252 } 256 }
253 257
254 #[test] 258 #[tokio::test]
255 #[serial] 259 #[serial]
256 fn when_latest_metadata_and_relay_list_on_some_relays_but_others_have_none() 260 async fn when_latest_metadata_and_relay_list_on_some_relays_but_others_have_none()
257 -> Result<()> { 261 -> Result<()> {
258 futures::executor::block_on(run_test_displays_correct_name( 262 run_test_displays_correct_name(
259 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 263 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
260 relay.respond_events( 264 relay.respond_events(
261 client_id, 265 client_id,
@@ -268,13 +272,15 @@ mod with_relays {
268 Ok(()) 272 Ok(())
269 }), 273 }),
270 None, 274 None,
271 )) 275 )
276 .await
272 } 277 }
273 278
274 #[test] 279 #[tokio::test]
275 #[serial] 280 #[serial]
276 fn when_latest_metadata_only_on_relay_and_relay_list_on_another() -> Result<()> { 281 async fn when_latest_metadata_only_on_relay_and_relay_list_on_another() -> Result<()>
277 futures::executor::block_on(run_test_displays_correct_name( 282 {
283 run_test_displays_correct_name(
278 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 284 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
279 relay.respond_events( 285 relay.respond_events(
280 client_id, 286 client_id,
@@ -291,13 +297,14 @@ mod with_relays {
291 )?; 297 )?;
292 Ok(()) 298 Ok(())
293 }), 299 }),
294 )) 300 )
301 .await
295 } 302 }
296 303
297 #[test] 304 #[tokio::test]
298 #[serial] 305 #[serial]
299 fn when_some_relays_return_old_metadata_event() -> Result<()> { 306 async fn when_some_relays_return_old_metadata_event() -> Result<()> {
300 futures::executor::block_on(run_test_displays_correct_name( 307 run_test_displays_correct_name(
301 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 308 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
302 relay.respond_events( 309 relay.respond_events(
303 client_id, 310 client_id,
@@ -317,13 +324,14 @@ mod with_relays {
317 )?; 324 )?;
318 Ok(()) 325 Ok(())
319 }), 326 }),
320 )) 327 )
328 .await
321 } 329 }
322 330
323 #[test] 331 #[tokio::test]
324 #[serial] 332 #[serial]
325 fn when_some_relays_return_other_users_metadata() -> Result<()> { 333 async fn when_some_relays_return_other_users_metadata() -> Result<()> {
326 futures::executor::block_on(run_test_displays_correct_name( 334 run_test_displays_correct_name(
327 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 335 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
328 relay.respond_events( 336 relay.respond_events(
329 client_id, 337 client_id,
@@ -343,13 +351,14 @@ mod with_relays {
343 )?; 351 )?;
344 Ok(()) 352 Ok(())
345 }), 353 }),
346 )) 354 )
355 .await
347 } 356 }
348 357
349 #[test] 358 #[tokio::test]
350 #[serial] 359 #[serial]
351 fn when_some_relays_return_other_event_kinds() -> Result<()> { 360 async fn when_some_relays_return_other_event_kinds() -> Result<()> {
352 futures::executor::block_on(run_test_displays_correct_name( 361 run_test_displays_correct_name(
353 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 362 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
354 let event = generate_test_key_1_kind_event(nostr::Kind::TextNote); 363 let event = generate_test_key_1_kind_event(nostr::Kind::TextNote);
355 relay.respond_events( 364 relay.respond_events(
@@ -370,31 +379,31 @@ mod with_relays {
370 )?; 379 )?;
371 Ok(()) 380 Ok(())
372 }), 381 }),
373 )) 382 )
383 .await
374 } 384 }
375 385
376 mod when_specifying_command_line_nsec_only { 386 mod when_specifying_command_line_nsec_only {
377 use super::*; 387 use super::*;
378 388
379 #[test] 389 #[tokio::test]
380 #[serial] 390 #[serial]
381 fn displays_correct_name() -> Result<()> { 391 async fn displays_correct_name() -> Result<()> {
382 futures::executor::block_on( 392 run_test_when_specifying_command_line_nsec_only_displays_correct_name(
383 run_test_when_specifying_command_line_nsec_only_displays_correct_name( 393 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
384 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 394 relay.respond_events(
385 relay.respond_events( 395 client_id,
386 client_id, 396 &subscription_id,
387 &subscription_id, 397 &vec![
388 &vec![ 398 generate_test_key_1_metadata_event("fred"),
389 generate_test_key_1_metadata_event("fred"), 399 generate_test_key_1_relay_list_event_same_as_fallback(),
390 generate_test_key_1_relay_list_event_same_as_fallback(), 400 ],
391 ], 401 )?;
392 )?; 402 Ok(())
393 Ok(()) 403 }),
394 }), 404 None,
395 None,
396 ),
397 ) 405 )
406 .await
398 } 407 }
399 async fn run_test_when_specifying_command_line_nsec_only_displays_correct_name( 408 async fn run_test_when_specifying_command_line_nsec_only_displays_correct_name(
400 relay_listener1: Option<ListenerReqFunc<'_>>, 409 relay_listener1: Option<ListenerReqFunc<'_>>,
@@ -430,10 +439,9 @@ mod with_relays {
430 mod when_specifying_command_line_password_only { 439 mod when_specifying_command_line_password_only {
431 use super::*; 440 use super::*;
432 441
433 #[test] 442 #[tokio::test]
434 #[serial] 443 #[serial]
435 fn displays_correct_name() -> Result<()> { 444 async fn displays_correct_name() -> Result<()> {
436 futures::executor::block_on(
437 run_test_when_specifying_command_line_password_only_displays_correct_name( 445 run_test_when_specifying_command_line_password_only_displays_correct_name(
438 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 446 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
439 relay.respond_events( 447 relay.respond_events(
@@ -447,8 +455,8 @@ mod with_relays {
447 Ok(()) 455 Ok(())
448 }), 456 }),
449 None, 457 None,
450 ), 458 )
451 ) 459 .await
452 } 460 }
453 async fn run_test_when_specifying_command_line_password_only_displays_correct_name( 461 async fn run_test_when_specifying_command_line_password_only_displays_correct_name(
454 relay_listener1: Option<ListenerReqFunc<'_>>, 462 relay_listener1: Option<ListenerReqFunc<'_>>,
@@ -495,10 +503,9 @@ mod with_relays {
495 mod when_specifying_command_line_nsec_and_password { 503 mod when_specifying_command_line_nsec_and_password {
496 use super::*; 504 use super::*;
497 505
498 #[test] 506 #[tokio::test]
499 #[serial] 507 #[serial]
500 fn displays_correct_name() -> Result<()> { 508 async fn displays_correct_name() -> Result<()> {
501 futures::executor::block_on(
502 run_test_when_specifying_command_line_nsec_and_password_displays_correct_name( 509 run_test_when_specifying_command_line_nsec_and_password_displays_correct_name(
503 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 510 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
504 relay.respond_events( 511 relay.respond_events(
@@ -512,8 +519,7 @@ mod with_relays {
512 Ok(()) 519 Ok(())
513 }), 520 }),
514 None, 521 None,
515 ), 522 ).await
516 )
517 } 523 }
518 async fn run_test_when_specifying_command_line_nsec_and_password_displays_correct_name( 524 async fn run_test_when_specifying_command_line_nsec_and_password_displays_correct_name(
519 relay_listener1: Option<ListenerReqFunc<'_>>, 525 relay_listener1: Option<ListenerReqFunc<'_>>,
@@ -557,12 +563,10 @@ mod with_relays {
557 mod when_no_metadata_found { 563 mod when_no_metadata_found {
558 use super::*; 564 use super::*;
559 565
560 #[test] 566 #[tokio::test]
561 #[serial] 567 #[serial]
562 fn warm_user_and_displays_npub() -> Result<()> { 568 async fn warm_user_and_displays_npub() -> Result<()> {
563 futures::executor::block_on( 569 run_test_when_no_metadata_found_warns_user_and_uses_npub(None, None).await
564 run_test_when_no_metadata_found_warns_user_and_uses_npub(None, None),
565 )
566 } 570 }
567 571
568 async fn run_test_when_no_metadata_found_warns_user_and_uses_npub( 572 async fn run_test_when_no_metadata_found_warns_user_and_uses_npub(
@@ -612,22 +616,21 @@ mod with_relays {
612 mod when_metadata_but_no_relay_list_found { 616 mod when_metadata_but_no_relay_list_found {
613 use super::*; 617 use super::*;
614 618
615 #[test] 619 #[tokio::test]
616 #[serial] 620 #[serial]
617 fn warm_user_and_displays_name() -> Result<()> { 621 async fn warm_user_and_displays_name() -> Result<()> {
618 futures::executor::block_on( 622 run_test_when_no_relay_list_found_warns_user_and_uses_npub(
619 run_test_when_no_relay_list_found_warns_user_and_uses_npub( 623 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
620 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 624 relay.respond_events(
621 relay.respond_events( 625 client_id,
622 client_id, 626 &subscription_id,
623 &subscription_id, 627 &vec![generate_test_key_1_metadata_event("fred")],
624 &vec![generate_test_key_1_metadata_event("fred")], 628 )?;
625 )?; 629 Ok(())
626 Ok(()) 630 }),
627 }), 631 None,
628 None,
629 ),
630 ) 632 )
633 .await
631 } 634 }
632 635
633 async fn run_test_when_no_relay_list_found_warns_user_and_uses_npub( 636 async fn run_test_when_no_relay_list_found_warns_user_and_uses_npub(
@@ -682,10 +685,10 @@ mod with_relays {
682 mod uses_cache { 685 mod uses_cache {
683 use super::*; 686 use super::*;
684 687
685 #[test] 688 #[tokio::test]
686 #[serial] 689 #[serial]
687 fn dislays_logged_in_with_correct_name() -> Result<()> { 690 async fn dislays_logged_in_with_correct_name() -> Result<()> {
688 futures::executor::block_on(run_test_dislays_logged_in_with_correct_name(Some( 691 run_test_dislays_logged_in_with_correct_name(Some(
689 &|relay, client_id, subscription_id, _| -> Result<()> { 692 &|relay, client_id, subscription_id, _| -> Result<()> {
690 relay.respond_events( 693 relay.respond_events(
691 client_id, 694 client_id,
@@ -697,7 +700,8 @@ mod with_relays {
697 )?; 700 )?;
698 Ok(()) 701 Ok(())
699 }, 702 },
700 ))) 703 ))
704 .await
701 } 705 }
702 async fn run_test_dislays_logged_in_with_correct_name( 706 async fn run_test_dislays_logged_in_with_correct_name(
703 relay_listener: Option<ListenerReqFunc<'_>>, 707 relay_listener: Option<ListenerReqFunc<'_>>,
@@ -794,10 +798,10 @@ mod with_relays {
794 } 798 }
795 799
796 /// this also tests that additional relays are queried 800 /// this also tests that additional relays are queried
797 #[test] 801 #[tokio::test]
798 #[serial] 802 #[serial]
799 fn displays_correct_name() -> Result<()> { 803 async fn displays_correct_name() -> Result<()> {
800 futures::executor::block_on(run_test_displays_correct_name( 804 run_test_displays_correct_name(
801 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 805 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
802 relay.respond_events( 806 relay.respond_events(
803 client_id, 807 client_id,
@@ -820,7 +824,8 @@ mod with_relays {
820 )?; 824 )?;
821 Ok(()) 825 Ok(())
822 }), 826 }),
823 )) 827 )
828 .await
824 } 829 }
825 } 830 }
826 } 831 }