diff --git a/bats/core/notifications/notifications.bats b/bats/core/notifications/notifications.bats index fbcff44f20..a8bf8497df 100644 --- a/bats/core/notifications/notifications.bats +++ b/bats/core/notifications/notifications.bats @@ -180,3 +180,65 @@ setup_file() { [[ "${first_id}" != "${second_id}" ]] || exit 1 [[ "$next_page" = "false" ]] || exit 1 } + +@test "notifications: list stateful notifications without bulletin enabled" { + local n_notifications + exec_graphql 'alice' 'list-stateful-notifications-without-bulletin-enabled' + n_notifications=$(graphql_output '.data.me.listStatefulNotificationsWithoutBulletinEnabled.nodes | length') + [[ $n_bulletins -eq 0 ]] || exit 1 + + admin_token="$(read_value 'admin.token')" + + variables=$( + jq -n \ + '{ + input: { + localizedNotificationContents: [ + { + language: "en", + title: "Test title", + body: "test body" + } + ], + shouldSendPush: false, + shouldAddToHistory: true, + shouldAddToBulletin: false, + } + }' + ) + + # trigger two marketing notification + exec_admin_graphql "$admin_token" 'marketing-notification-trigger' "$variables" + exec_admin_graphql "$admin_token" 'marketing-notification-trigger' "$variables" + + for i in {1..10}; do + exec_graphql 'alice' 'list-stateful-notifications-without-bulletin-enabled' + n_notifications=$(graphql_output '.data.me.listStatefulNotificationsWithoutBulletinEnabled.nodes | length') + [[ $n_notifications -eq 2 ]] && break; + sleep 1 + done + [[ $n_notifications -eq 2 ]] || exit 1; +} + +@test "notifications: list stateful notifications without bulletin enabled paginated with cursor" { + exec_graphql 'alice' 'list-stateful-notifications-without-bulletin-enabled' '{"first": 1}' + n_notifications=$(graphql_output '.data.me.listStatefulNotificationsWithoutBulletinEnabled.nodes | length') + first_id=$(graphql_output '.data.me.listStatefulNotificationsWithoutBulletinEnabled.nodes[0].id') + cursor=$(graphql_output '.data.me.listStatefulNotificationsWithoutBulletinEnabled.pageInfo.endCursor') + next_page=$(graphql_output '.data.me.listStatefulNotificationsWithoutBulletinEnabled.pageInfo.hasNextPage') + [[ $n_notifications -eq 1 ]] || exit 1 + [[ "$next_page" = "true" ]] || exit 1 + + variables=$( + jq -n \ + --arg after "${cursor}" \ + '{first: 1, after: $after}' + ) + exec_graphql 'alice' 'list-stateful-notifications-without-bulletin-enabled' "$variables" + n_notifications=$(graphql_output '.data.me.listStatefulNotificationsWithoutBulletinEnabled.nodes | length') + second_id=$(graphql_output '.data.me.listStatefulNotificationsWithoutBulletinEnabled.nodes[0].id') + next_page=$(graphql_output '.data.me.listStatefulNotificationsWithoutBulletinEnabled.pageInfo.hasNextPage') + [[ $n_notifications -eq 1 ]] || exit 1 + [[ "${first_id}" != "${second_id}" ]] || exit 1 + [[ "$next_page" = "false" ]] || exit 1 +} diff --git a/bats/gql/list-stateful-notifications-without-bulletin-enabled.gql b/bats/gql/list-stateful-notifications-without-bulletin-enabled.gql new file mode 100644 index 0000000000..ab157fc5a6 --- /dev/null +++ b/bats/gql/list-stateful-notifications-without-bulletin-enabled.gql @@ -0,0 +1,19 @@ +query listStatefulNotificationsWithoutBulletinEnabled($first: Int = 2, $after: String = null) { + me { + id + statefulNotifications(first: $first, after: $after) { + pageInfo { + endCursor + hasNextPage + } + nodes { + id + body + title + deepLink + acknowledgedAt + createdAt + } + } + } +}