Skip to content

Commit

Permalink
chore(notifications): do not persist txn notification to history (#4403)
Browse files Browse the repository at this point in the history
* chore(notifications): do not persist txn notification to history

* test(notifications): e2e test using marketing notification

* chore(notifications): enable jobs for testing notifications
  • Loading branch information
thevaibhav-dixit authored May 2, 2024
1 parent 98ca257 commit 0006351
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 42 deletions.
71 changes: 44 additions & 27 deletions bats/core/notifications/notifications.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,62 @@

load "../../helpers/_common.bash"
load "../../helpers/user.bash"
load "../../helpers/onchain.bash"
load "../../helpers/admin.bash"

setup_file() {
clear_cache

create_user 'alice'

login_admin
}

@test "notifications: list stateful transactions" {
btc_wallet_name="alice.btc_wallet_id"
amount="0.01"
@test "notifications: list stateful notifications" {
admin_token="$(read_value 'admin.token')"

# Create address and broadcast transaction 1
variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
'{input: {walletId: $wallet_id}}'
'{
input: {
localizedNotificationContents: [
{
language: "en",
title: "Test title",
body: "test body"
}
],
shouldSendPush: false,
shouldAddToHistory: true,
shouldAddToBulletin: true,
deepLinkScreen: "EARN"
}
}'
)

exec_graphql 'alice' 'on-chain-address-create' "$variables"
on_chain_address_created_1="$(graphql_output '.data.onChainAddressCreate.address')"
[[ "${on_chain_address_created_1}" != "null" ]] || exit 1

bitcoin_cli sendtoaddress "$on_chain_address_created_1" "$amount"
retry 15 1 check_for_incoming_broadcast 'alice' "$on_chain_address_created_1"

exec_graphql 'alice' 'list-stateful-notifications'
n_notifications=$(graphql_output '.data.me.statefulNotifications.nodes | length')
[[ $n_notifications -eq 1 ]] || exit 1

bitcoin_cli -generate 2
retry 30 1 check_for_onchain_initiated_settled 'alice' "$on_chain_address_created_1" 2

exec_graphql 'alice' 'list-stateful-notifications'
n_notifications=$(graphql_output '.data.me.statefulNotifications.nodes | length')
[[ $n_notifications -eq 2 ]] || exit 1
# trigger a marketing notification
exec_admin_graphql "$admin_token" 'marketing-notification-trigger' "$variables"

local n_notifications
for i in {1..10}; do
exec_graphql 'alice' 'list-stateful-notifications'
n_notifications=$(graphql_output '.data.me.statefulNotifications.nodes | length')
[[ $n_notifications -eq 1 ]] && break;
sleep 1
done
[[ $n_notifications -eq 1 ]] || exit 1;

exec_admin_graphql "$admin_token" 'marketing-notification-trigger' "$variables"

for i in {1..10}; do
exec_graphql 'alice' 'list-stateful-notifications'
n_notifications=$(graphql_output '.data.me.statefulNotifications.nodes | length')
[[ $n_notifications -eq 2 ]] && break;
sleep 1
done
[[ $n_notifications -eq 2 ]] || exit 1;
}

@test "notifications: list stateful transactions paginated with cursor" {
@test "notifications: list stateful notifications paginated with cursor" {
exec_graphql 'alice' 'list-stateful-notifications' '{"first": 1}'
n_notifications=$(graphql_output '.data.me.statefulNotifications.nodes | length')
first_id=$(graphql_output '.data.me.statefulNotifications.nodes[0].id')
Expand All @@ -63,7 +80,7 @@ setup_file() {
[[ "$next_page" = "false" ]] || exit 1
}

@test "notifications: acknowledge stateful transactions" {
@test "notifications: acknowledge stateful notification" {
exec_graphql 'alice' 'list-stateful-notifications' '{"first": 1}'
n_notifications=$(graphql_output '.data.me.statefulNotifications.nodes | length')
id=$(graphql_output '.data.me.statefulNotifications.nodes[0].id')
Expand All @@ -80,7 +97,7 @@ setup_file() {
[[ "$acknowledged_at" != "null" ]] || exit 1
}

@test "notifications: unacknowledged_stateful_notifications_count" {
@test "notifications: unacknowledged stateful notifications count" {
exec_graphql 'alice' 'unacknowledged_stateful_notifications_count'
count=$(graphql_output '.data.me.unacknowledgedStatefulNotificationsCount')
[[ $count -eq 1 ]] || exit 1
Expand Down
5 changes: 4 additions & 1 deletion core/notifications/notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
# port: 6685
app:
# jobs:
# kickoff_link_email_reminder_delay: 5
# enabled: false
# max_concurrent_jobs: 24
# min_concurrent_jobs: 12
# kickoff_link_email_reminder_delay: 21600
# link_email_reminder:
# account_liveness_threshold_minutes: 30240
# account_aged_threshold_minutes: 30240
Expand Down
14 changes: 0 additions & 14 deletions core/notifications/src/notification_event/transaction_occurred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,6 @@ impl NotificationEvent for TransactionOccurred {

LocalizedPushMessage { title, body }
}

fn should_be_added_to_history(&self) -> bool {
true
}

fn to_localized_persistent_message(&self, locale: GaloyLocale) -> LocalizedStatefulMessage {
let push_msg = self.to_localized_push_msg(&locale);

LocalizedStatefulMessage {
locale,
title: push_msg.title,
body: push_msg.body,
}
}
}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions dev/config/notifications/notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ app:
push_executor:
fcm:
google_application_credentials_path: "./config/notifications/fake_service_account.json"
jobs:
enabled: true

0 comments on commit 0006351

Please sign in to comment.