diff --git a/src/services/mongoose/accounts.ts b/src/services/mongoose/accounts.ts index 1d8cec8fa1..f66958022c 100644 --- a/src/services/mongoose/accounts.ts +++ b/src/services/mongoose/accounts.ts @@ -227,15 +227,14 @@ const translateToAccount = (result: AccountRecord): Account => ({ ), withdrawFee: result.withdrawFee as Satoshis, isEditor: result.role === "editor", - notificationSettings: - result.notificationSettings || - ({ - push: { - enabled: true, - disabledCategories: [], - }, - } as NotificationSettings), - + notificationSettings: { + push: { + enabled: result.notificationSettings + ? result.notificationSettings.push.enabled + : true, + disabledCategories: result.notificationSettings?.push?.disabledCategories || [], + }, + }, // TODO: remove quizQuestions: result.earn?.map( diff --git a/test/bats/gql/account-disable-notification-category.gql b/test/bats/gql/account-disable-notification-category.gql new file mode 100644 index 0000000000..771a6c7e9f --- /dev/null +++ b/test/bats/gql/account-disable-notification-category.gql @@ -0,0 +1,15 @@ +mutation accountDisableNotificationCategory($input: AccountDisableNotificationCategoryInput!) { + accountDisableNotificationCategory(input: $input) { + errors { + message + } + account { + notificationSettings { + push { + enabled + disabledCategories + } + } + } + } +} diff --git a/test/bats/gql/account-disable-notification-channel.gql b/test/bats/gql/account-disable-notification-channel.gql new file mode 100644 index 0000000000..34e9a5795b --- /dev/null +++ b/test/bats/gql/account-disable-notification-channel.gql @@ -0,0 +1,15 @@ +mutation accountDisableNotificationChannel($input: AccountDisableNotificationChannelInput!) { + accountDisableNotificationChannel(input: $input) { + errors { + message + } + account { + notificationSettings { + push { + enabled + disabledCategories + } + } + } + } +} diff --git a/test/bats/gql/account-enable-notification-category.gql b/test/bats/gql/account-enable-notification-category.gql new file mode 100644 index 0000000000..5b5b752fe9 --- /dev/null +++ b/test/bats/gql/account-enable-notification-category.gql @@ -0,0 +1,15 @@ +mutation accountEnableNotificationCategory($input: AccountEnableNotificationCategoryInput!) { + accountEnableNotificationCategory(input: $input) { + errors { + message + } + account { + notificationSettings { + push { + enabled + disabledCategories + } + } + } + } +} diff --git a/test/bats/gql/account-enable-notification-channel.gql b/test/bats/gql/account-enable-notification-channel.gql new file mode 100644 index 0000000000..a3593270dc --- /dev/null +++ b/test/bats/gql/account-enable-notification-channel.gql @@ -0,0 +1,15 @@ +mutation accountEnableNotificationChannel($input: AccountEnableNotificationChannelInput!) { + accountEnableNotificationChannel(input: $input) { + errors { + message + } + account { + notificationSettings { + push { + enabled + disabledCategories + } + } + } + } +} diff --git a/test/bats/gql/account-update-push-notification-settings.gql b/test/bats/gql/account-update-push-notification-settings.gql deleted file mode 100644 index 195d37c4b1..0000000000 --- a/test/bats/gql/account-update-push-notification-settings.gql +++ /dev/null @@ -1,13 +0,0 @@ -mutation accountUpdatePushNotificationSettings($input: AccountUpdatePushNotificationSettingsInput!) { - accountUpdatePushNotificationSettings(input: $input) { - errors { - message - } - account { - pushNotificationSettings { - pushNotificationsEnabled - disabledPushNotificationTypes - } - } - } -} diff --git a/test/bats/notification-settings.bats b/test/bats/notification-settings.bats new file mode 100644 index 0000000000..3496ff27e8 --- /dev/null +++ b/test/bats/notification-settings.bats @@ -0,0 +1,54 @@ +#!/usr/bin/env bats + +load "helpers/setup-and-teardown" + +setup_file() { + clear_cache + reset_redis + + bitcoind_init + start_trigger + start_server + + initialize_user_from_onchain "$ALICE_TOKEN_NAME" "$ALICE_PHONE" "$CODE" +} + +teardown_file() { + stop_trigger + stop_server +} + + +@test "notification-settings: disable/enable notification channel" { + token_name="$ALICE_TOKEN_NAME" + + variables=$( + jq -n \ + '{input: { channel: "PUSH" }}') + + exec_graphql "$token_name" 'account-disable-notification-channel' "$variables" + channel_enabled="$(graphql_output '.data.accountDisableNotificationChannel.account.notificationSettings.push.enabled')" + [[ "$channel_enabled" == "false" ]] || exit 1 + + exec_graphql "$token_name" 'account-enable-notification-channel' "$variables" + + channel_enabled="$(graphql_output '.data.accountEnableNotificationChannel.account.notificationSettings.push.enabled')" + [[ "$channel_enabled" == "true" ]] || exit 1 +} + +@test "notification-settings: disable/enable notification category" { + token_name="$ALICE_TOKEN_NAME" + + variables=$( + jq -n \ + '{input: { channel: "PUSH", category: "Circles" }}') + + exec_graphql "$token_name" 'account-disable-notification-category' "$variables" + disabled_category="$(graphql_output '.data.accountDisableNotificationCategory.account.notificationSettings.push.disabledCategories[0]')" + [[ "$disabled_category" == "Circles" ]] || exit 1 + + exec_graphql "$token_name" 'account-enable-notification-category' "$variables" + + disabled_length="$(graphql_output '.data.accountEnableNotificationCategory.account.notificationSettings.push.disabledCategories | length')" + [[ "$disabled_length" == "0" ]] || exit 1 +} diff --git a/test/bats/push-notification-settings.bats b/test/bats/push-notification-settings.bats deleted file mode 100644 index 83c1566ec9..0000000000 --- a/test/bats/push-notification-settings.bats +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bats - -load "helpers/setup-and-teardown" - -setup_file() { - clear_cache - reset_redis - - bitcoind_init - start_trigger - start_server - - initialize_user_from_onchain "$ALICE_TOKEN_NAME" "$ALICE_PHONE" "$CODE" -} - -teardown_file() { - stop_trigger - stop_server -} - - -@test "push-notification-settings: set and get" { - token_name="$ALICE_TOKEN_NAME" - - variables=$( - jq -n \ - '{input: { pushNotificationsEnabled: true, disabledPushNotificationTypes: [ "Circles" ] }}') - - exec_graphql "$token_name" 'account-update-push-notification-settings' "$variables" - - disabled_notification="$(graphql_output '.data.accountUpdatePushNotificationSettings.account.pushNotificationSettings.disabledPushNotificationTypes[0]')" - [[ "$disabled_notification" == "Circles" ]] || exit 1 -}