Skip to content

Commit

Permalink
Merge pull request #4497 from santiment/disable-telegram-alert-bool
Browse files Browse the repository at this point in the history
Also disable alert_notify_telegram when disconnecting telegram bot
  • Loading branch information
IvanIvanoff authored Dec 12, 2024
2 parents 6b26045 + 4782ebf commit 75a4e1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
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

0 comments on commit 75a4e1f

Please sign in to comment.