Skip to content

Commit

Permalink
test: channel settings
Browse files Browse the repository at this point in the history
  • Loading branch information
eddnewgate committed Aug 24, 2024
1 parent df1f678 commit 35fb53d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
3 changes: 1 addition & 2 deletions tests/test_channel_delegate.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
56 changes: 56 additions & 0 deletions tests/test_channel_settings.cairo
Original file line number Diff line number Diff line change
@@ -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());
}

0 comments on commit 35fb53d

Please sign in to comment.