From 35fb53dc6a162bf78c6f8041eb5f78967d9114f6 Mon Sep 17 00:00:00 2001 From: eddnewgate Date: Sun, 25 Aug 2024 02:56:27 +0545 Subject: [PATCH] test: channel settings --- tests/test_channel_delegate.cairo | 3 +- tests/test_channel_settings.cairo | 56 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 tests/test_channel_settings.cairo diff --git a/tests/test_channel_delegate.cairo b/tests/test_channel_delegate.cairo index 95b3955..bd68c72 100644 --- a/tests/test_channel_delegate.cairo +++ b/tests/test_channel_delegate.cairo @@ -55,8 +55,7 @@ fn test_channel_delegate() { ] ); - - // Removed Delegate can send the notification + // Removed Delegate can send the notification cheat_caller_address(contract_address, USER_1(), CheatSpan::TargetCalls(1)); let is_success = push_comm.send_notification(CHANNEL_ADDRESS, USER_1(), indentity.clone()); assert(is_success == false, 'Send notification should fail'); diff --git a/tests/test_channel_settings.cairo b/tests/test_channel_settings.cairo new file mode 100644 index 0000000..2784e37 --- /dev/null +++ b/tests/test_channel_settings.cairo @@ -0,0 +1,56 @@ +use starknet::{ContractAddress, EthAddress}; + +use snforge_std::{ + declare, ContractClassTrait, cheat_caller_address, CheatSpan, spy_events, + EventSpyAssertionsTrait, Event, EventSpyTrait +}; +use push_comm::{PushComm, interface::IPushCommDispatcher, interface::IPushCommDispatcherTrait}; +use super::common::{USER_1, deploy_contract, CHAIN_NAME}; + +#[test] +fn test_channel_channel_user_settings() { + let contract_address = deploy_contract(); + let push_comm = IPushCommDispatcher { contract_address }; + let CHANNEL_ADDRESS: ContractAddress = 'some addrs'.try_into().unwrap(); + let mut spy = spy_events(); + + // user subscribes to the channel + cheat_caller_address(contract_address, USER_1(), CheatSpan::TargetCalls(1)); + push_comm.subscribe(CHANNEL_ADDRESS); + + // change_user_channel_settings + cheat_caller_address(contract_address, CHANNEL_ADDRESS, CheatSpan::TargetCalls(1)); + let notif_id = 1; + let notif_settings: ByteArray = "notif_settings"; + push_comm.change_user_channel_settings(CHANNEL_ADDRESS, notif_id, notif_settings.clone()); + + // Assert UserNotifcationSettingsAdded event was emitted + spy + .assert_emitted( + @array![ + ( + contract_address, + PushComm::Event::UserNotifcationSettingsAdded( + PushComm::UserNotifcationSettingsAdded { + channel: CHANNEL_ADDRESS, recipient: USER_1(), notif_id, notif_settings + } + ) + ) + ] + ); +} + +#[test] +#[should_panic(expected: '')] +fn test_channel_channel_unsubscribed_user_settings() { + let contract_address = deploy_contract(); + let push_comm = IPushCommDispatcher { contract_address }; + let CHANNEL_ADDRESS: ContractAddress = 'some addrs'.try_into().unwrap(); + let mut spy = spy_events(); + + // change_user_channel_settings + cheat_caller_address(contract_address, CHANNEL_ADDRESS, CheatSpan::TargetCalls(1)); + let notif_id = 1; + let notif_settings: ByteArray = "notif_settings"; + push_comm.change_user_channel_settings(CHANNEL_ADDRESS, notif_id, notif_settings.clone()); +} \ No newline at end of file