From 4782ebfd0c1f9b7b2fe1b51fb6d7f1e3cb0bd2f3 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Thu, 12 Dec 2024 10:26:26 +0200 Subject: [PATCH] Also disable alert_notify_telegram when disconnecting telegram bot --- lib/sanbase/accounts/user_settings.ex | 2 +- test/sanbase/telegram/telegram_test.exs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/sanbase/accounts/user_settings.ex b/lib/sanbase/accounts/user_settings.ex index 88eb986fc..2a7a3d6b4 100644 --- a/lib/sanbase/accounts/user_settings.ex +++ b/lib/sanbase/accounts/user_settings.ex @@ -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} -> diff --git a/test/sanbase/telegram/telegram_test.exs b/test/sanbase/telegram/telegram_test.exs index 039681bc1..d08f163a6 100644 --- a/test/sanbase/telegram/telegram_test.exs +++ b/test/sanbase/telegram/telegram_test.exs @@ -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]) @@ -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) @@ -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() @@ -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,