From 1eaec4e30e34e485c562ef56c688b741e2efcf61 Mon Sep 17 00:00:00 2001 From: bouzuya Date: Fri, 1 Dec 2023 23:26:01 +0900 Subject: [PATCH] Add FirestoreStore::find_all_items test --- firebase/firestore.rules | 3 ++ rust/crates/web/src/infra/firestore_store.rs | 35 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/firebase/firestore.rules b/firebase/firestore.rules index 992b48c..446c15d 100644 --- a/firebase/firestore.rules +++ b/firebase/firestore.rules @@ -4,6 +4,9 @@ service cloud.firestore { match /check_lists/{check_list_id} { allow read, write: if true; } + match /items/{item_id} { + allow read, write: if true; + } match /repositories/{repository_id} { allow read, write: if true; diff --git a/rust/crates/web/src/infra/firestore_store.rs b/rust/crates/web/src/infra/firestore_store.rs index e071e24..ce383b6 100644 --- a/rust/crates/web/src/infra/firestore_store.rs +++ b/rust/crates/web/src/infra/firestore_store.rs @@ -169,4 +169,39 @@ mod tests { Ok(()) } + + #[tokio::test] + async fn test_find_all_items() -> anyhow::Result<()> { + let endpoint = "http://firebase:8080"; + let mut client = Client::new( + "demo-project1".to_string(), + "(default)".to_string(), + endpoint, + ) + .await?; + let collection = client.collection("items")?; + let doc = collection.doc("1")?; + + let input = ItemDocumentData { + id: "1".to_string(), + name: "name1".to_string(), + }; + let created: Document = client.create(&doc, input).await?; + + let store = FirestoreStore { + client: Arc::new(tokio::sync::Mutex::new(client.clone())), + }; + let found = store.find_all_items().await?; + assert_eq!( + found, + vec![Item { + id: "1".to_string(), + name: "name1".to_string() + }] + ); + + client.delete(&doc, created.update_time()).await?; + + Ok(()) + } }