Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also disable alert_notify_telegram when disconnecting telegram bot #4497

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sanbase/accounts/user_settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ defmodule Sanbase.Accounts.UserSettings do
user_settings_for(user, force: true)

user_settings
|> changeset(%{settings: %{telegram_chat_id: nil}})
|> changeset(%{settings: %{telegram_chat_id: nil, alert_notify_telegram: false}})
|> Sanbase.Repo.update()
|> case do
{:ok, user_settings} ->
Expand Down
18 changes: 9 additions & 9 deletions test/sanbase/telegram/telegram_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ defmodule Sanbase.TelegramTest do
use SanbaseWeb.ConnCase, async: false

import SanbaseWeb.Graphql.TestHelpers
import Sanbase.Factory

alias Sanbase.Repo
alias Sanbase.Accounts.{User, Settings, UserSettings}
alias Sanbase.Telegram
alias Sanbase.Accounts.Settings
alias Sanbase.Accounts.UserSettings

@bot_username Application.compile_env(:sanbase, [Sanbase.Telegram, :bot_username])
@telegram_endpoint Application.compile_env(:sanbase, [Sanbase.Telegram, :telegram_endpoint])
Expand All @@ -18,9 +19,7 @@ defmodule Sanbase.TelegramTest do
%Tesla.Env{status: 200, body: "ok"}
end)

user =
%User{salt: User.generate_salt(), privacy_policy_accepted: true}
|> Repo.insert!()
user = insert(:user, user_settings: %{settings: %{alert_notify_telegram: true}})

conn = setup_jwt_auth(build_conn(), user)

Expand Down Expand Up @@ -56,8 +55,9 @@ defmodule Sanbase.TelegramTest do
%Telegram.UserToken{token: user_token} = Telegram.UserToken.by_user_id(context.user.id)

simulate_telegram_deep_link_follow(context, user_token)
%Settings{telegram_chat_id: chat_id} = UserSettings.settings_for(context.user, force: true)
assert chat_id == @telegram_chat_id

assert %Settings{telegram_chat_id: @telegram_chat_id, alert_notify_telegram: true} =
UserSettings.settings_for(context.user, force: true)

self_pid = self()

Expand All @@ -69,8 +69,8 @@ defmodule Sanbase.TelegramTest do
assert %{"settings" => %{"hasTelegramConnected" => false}} =
disconnect_telegram_bot(context)

%Settings{telegram_chat_id: chat_id} = UserSettings.settings_for(context.user, force: true)
assert chat_id == nil
assert %Settings{telegram_chat_id: nil, alert_notify_telegram: false} =
UserSettings.settings_for(context.user, force: true)

assert_receive(
{:telegram_to_self,
Expand Down
Loading