From 79a8a2572b62f5e11c35528f156fb814685601a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillem=20C=C3=B3rdoba?= Date: Wed, 3 Jan 2024 14:12:53 +0100 Subject: [PATCH] Changed trait --- flake.lock | 24 +--- flake.nix | 2 +- .../Cargo.toml | 1 + .../src/lib.rs | 14 ++- oldtests/Cargo.toml | 19 --- oldtests/tests/complex_flow.rs | 117 ------------------ tests/src/complex-flow.test.ts | 8 +- 7 files changed, 18 insertions(+), 167 deletions(-) delete mode 100644 oldtests/Cargo.toml delete mode 100644 oldtests/tests/complex_flow.rs diff --git a/flake.lock b/flake.lock index e479273..c947a20 100644 --- a/flake.lock +++ b/flake.lock @@ -215,7 +215,10 @@ "pre-commit-hooks-nix": "pre-commit-hooks-nix", "repo-git": "repo-git", "rust-overlay": "rust-overlay_2", - "scaffolding": "scaffolding", + "scaffolding": [ + "holochain-flake", + "empty" + ], "versions": [ "versions" ] @@ -408,23 +411,6 @@ } }, "scaffolding": { - "flake": false, - "locked": { - "lastModified": 1703255019, - "narHash": "sha256-OlG3n5frSCggBDw7KOBSWgiSke93xSSJqPDVkD3wVBw=", - "owner": "holochain", - "repo": "scaffolding", - "rev": "4b14a8e1728bddf145baa5534165f2b90120d1b1", - "type": "github" - }, - "original": { - "owner": "holochain", - "ref": "develop", - "repo": "scaffolding", - "type": "github" - } - }, - "scaffolding_2": { "flake": false, "locked": { "lastModified": 1695674679, @@ -461,7 +447,7 @@ "holochain": "holochain", "lair": "lair", "launcher": "launcher", - "scaffolding": "scaffolding_2" + "scaffolding": "scaffolding" }, "locked": { "dir": "versions/0_2", diff --git a/flake.nix b/flake.nix index 8bcf02b..687d96b 100644 --- a/flake.nix +++ b/flake.nix @@ -6,7 +6,7 @@ holochain-flake.url = "github:holochain/holochain"; holochain-flake.inputs.versions.follows = "versions"; - holochain-flake.inputs.scaffolding.url = "github:holochain/scaffolding/develop"; + # holochain-flake.inputs.scaffolding.url = "github:holochain/scaffolding/develop"; nixpkgs.follows = "holochain-flake/nixpkgs"; flake-parts.follows = "holochain-flake/flake-parts"; diff --git a/notifications/crates/hc_zome_trait_pending_notifications/Cargo.toml b/notifications/crates/hc_zome_trait_pending_notifications/Cargo.toml index 601c146..1596991 100644 --- a/notifications/crates/hc_zome_trait_pending_notifications/Cargo.toml +++ b/notifications/crates/hc_zome_trait_pending_notifications/Cargo.toml @@ -8,4 +8,5 @@ edition = "2021" [dependencies] hdk = { workspace = true } serde = "1" + hc_zome_traits = { git = "https://github.com/holochain-open-dev/zome-traits", branch = "main" } diff --git a/notifications/crates/hc_zome_trait_pending_notifications/src/lib.rs b/notifications/crates/hc_zome_trait_pending_notifications/src/lib.rs index 02a1961..ed68474 100644 --- a/notifications/crates/hc_zome_trait_pending_notifications/src/lib.rs +++ b/notifications/crates/hc_zome_trait_pending_notifications/src/lib.rs @@ -10,16 +10,22 @@ pub struct HrlWithContext { } #[derive(Serialize, Deserialize, Debug)] -pub struct PendingNotification { - pub id: AnyDhtHash, +pub struct Notification { pub title: String, pub body: String, - // pub hrl_to_navigate_to_on_click: HrlWithContext, + pub hrl_to_navigate_to_on_click: HrlWithContext, + pub pending: bool, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct GetNotificationInput { + notification_hash: AnyDhtHash, + locale: String, } #[zome_trait] pub trait PendingNotifications { - fn get_pending_notifications(_: ()) -> ExternResult>; + fn get_notification(input: GetNotificationInput) -> ExternResult>; fn emit_new_pending_notification( pending_notification: PendingNotification, diff --git a/oldtests/Cargo.toml b/oldtests/Cargo.toml deleted file mode 100644 index 0757541..0000000 --- a/oldtests/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "tests" -version = "0.0.1" -edition = "2021" - -[dependencies] -hdk = { workspace = true } - -serde = { workspace = true } -hc_zome_notifications_provider_fcm_types = { path = "../providers/fcm/crates/notifications_provider_fcm_types" } - -[dev-dependencies] -fixt = "*" -futures = { version = "0.3.1", default-features = false } -hdk = { workspace = true, features = ["encoding", "test_utils"] } -holochain = { workspace = true, default-features = false, features = [ - "test_utils", -] } -tokio = { version = "1.3", features = ["full"] } diff --git a/oldtests/tests/complex_flow.rs b/oldtests/tests/complex_flow.rs deleted file mode 100644 index 70fbe6f..0000000 --- a/oldtests/tests/complex_flow.rs +++ /dev/null @@ -1,117 +0,0 @@ -use std::collections::BTreeMap; - -use hc_zome_notifications_provider_fcm_types::ServiceAccountKey; -use hdk::prelude::*; -use holochain::test_utils::consistency_10s; -use holochain::{conductor::config::ConductorConfig, sweettest::*}; - -#[tokio::test(flavor = "multi_thread")] -async fn complex_flow() { - // Use prebuilt DNA file - let notifications_dna = SweetDnaFile::from_bundle( - &std::env::current_dir() - .unwrap() - .join("../notifications/workdir/notifications.dna"), - ) - .await - .unwrap(); - let fixture_app = [notifications_dna]; - - let fcm_notifications_dna= SweetDnaFile::from_bundle(&std::env::current_dir() - .unwrap() - .join("../providers/fcm/apps/notifications_provider_fcm/dnas/notifications/workdir/notifications.dna")).await.unwrap(); - let fcm_provider_dna= SweetDnaFile::from_bundle(&std::env::current_dir() - .unwrap() - .join("../providers/fcm/apps/notifications_provider_fcm/dnas/notifications_provider_fcm/workdir/notifications_provider_fcm.dna")).await.unwrap(); - let fcm_provider_app = [fcm_notifications_dna, fcm_provider_dna]; - - let fcm_recipient_dna= SweetDnaFile::from_bundle(&std::env::current_dir() - .unwrap() - .join("../providers/fcm/apps/notifications_provider_fcm_recipient/workdir/notifications_fcm_recipient.dna")).await.unwrap(); - let fcm_recipient_app = [fcm_recipient_dna]; - - // Set up conductors - let mut conductors = SweetConductorBatch::from_config(3, ConductorConfig::default()).await; - - let fixture_app = conductors[0] - .setup_app("gather", &fixture_app) - .await - .unwrap(); - let provider_app = conductors[1] - .setup_app("fcm_provider", &fcm_provider_app) - .await - .unwrap(); - let recipient_app = conductors[2] - .setup_app("fcm_recipient", &fcm_recipient_app) - .await - .unwrap(); - conductors.exchange_peer_info().await; - - let conductors = conductors.into_inner(); - - let fixture = &conductors[0]; - let provider = &conductors[1]; - let recipient = &conductors[2]; - - let fixture_alice = fixture_app.into_cells(); - let fixture_zome = fixture_alice[0].zome("notifications"); - - let provider_cells = provider_app.into_cells(); - let provider_notifications_zome = provider_cells[0].zome("notifications"); - let provider_fcm_zome = provider_cells[1].zome("notifications_provider_fcm"); - - let recipient_cells = recipient_app.into_cells(); - let recipient_zome = recipient_cells[0].zome("notifications"); - - /* Setup provider */ - - // Publish Service Account Key - let _r: () = provider - .call( - &provider_fcm_zome, - "publish_new_service_account_key", - sample_service_account_key(), - ) - .await; - // assert_eq!(record_1, None); - // Announce as provider - let _r: () = provider - .call(&provider_notifications_zome, "announce_as_provider", ()) - .await; - - /* Setup recipient */ - // Register FCM token - // Shutdown recipient - - /* Send notification */ - // Send notification from fixture notification zome - // FCM provider zome sends signal - // Turn on recipient again - - // consistency_10s([&alice, &bobbo]).await; -} - -fn sample_service_account_key() -> ServiceAccountKey { - ServiceAccountKey { - /// key_type - key_type: None, - /// project_id - project_id: None, - /// private_key_id - private_key_id: None, - /// private_key - private_key: String::from("pk"), - /// client_email - client_email: String::from("pk"), - /// client_id - client_id: None, - /// auth_uri - auth_uri: None, - /// token_uri - token_uri: String::from("tu"), - /// auth_provider_x509_cert_url - auth_provider_x509_cert_url: None, - /// client_x509_cert_url - client_x509_cert_url: None, - } -} diff --git a/tests/src/complex-flow.test.ts b/tests/src/complex-flow.test.ts index 55a58dd..6a10835 100644 --- a/tests/src/complex-flow.test.ts +++ b/tests/src/complex-flow.test.ts @@ -95,6 +95,7 @@ test('setup provider and recipient, and send a notification to it', async t => { await Promise.race([ new Promise((_, reject) => setTimeout(() => reject(), 2000)), new Promise(async resolve => { + // FCM provider zome sends signal (provider.appAgentWs as AppAgentWebsocket).on('signal', signal => { console.log(signal); resolve(undefined); @@ -112,13 +113,6 @@ test('setup provider and recipient, and send a notification to it', async t => { }); }), ]); - - // FCM provider zome sends signal - // Turn on recipient again - // assert.deepEqual( - // contentUpdate, - // cleanNodeDecoding(readUpdatedOutput1.entry) - // ); }, true, { timeout: 30000 }