Skip to content

Commit

Permalink
Add FirestoreStore::find_all_items test
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Dec 1, 2023
1 parent 60b8dd5 commit 1eaec4e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions firebase/firestore.rules
Expand Up @@ -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;
Expand Down
35 changes: 35 additions & 0 deletions rust/crates/web/src/infra/firestore_store.rs
Expand Up @@ -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<ItemDocumentData> = 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(())
}
}

0 comments on commit 1eaec4e

Please sign in to comment.