Skip to content

Commit cd6f401

Browse files
committed
fix failed tests
1 parent 6d9f5a5 commit cd6f401

7 files changed

+40
-17
lines changed

app/services/telegram_member_fetcher.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "telegram/bot"
2+
13
class TelegramMemberFetcher
24
def self.get_bot_chat_member(group_id)
35
bot_id = Rails.cache.fetch("bot_id", expires_in: 24.hours) do

test/controllers/group_classifier_states_controller_test.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ class GroupClassifierStatesControllerTest < ActionDispatch::IntegrationTest
1717

1818
test "should create group_classifier_state" do
1919
assert_difference("GroupClassifierState.count") do
20-
post group_classifier_states_url, params: { group_classifier_state: { group_id: @group_classifier_state.group_id, ham_counts: @group_classifier_state.ham_counts, spam_counts: @group_classifier_state.spam_counts, total_ham_messages: @group_classifier_state.total_ham_messages, total_ham_words: @group_classifier_state.total_ham_words, total_spam_messages: @group_classifier_state.total_spam_messages, total_spam_words: @group_classifier_state.total_spam_words, vocabulary_size: @group_classifier_state.vocabulary_size } }
20+
post group_classifier_states_url, params: { group_classifier_state:
21+
{ group_id: 99,
22+
ham_counts: @group_classifier_state.ham_counts,
23+
spam_counts: @group_classifier_state.spam_counts,
24+
total_ham_messages: @group_classifier_state.total_ham_messages,
25+
total_ham_words: @group_classifier_state.total_ham_words,
26+
total_spam_messages: @group_classifier_state.total_spam_messages,
27+
total_spam_words: @group_classifier_state.total_spam_words,
28+
vocabulary_size: @group_classifier_state.vocabulary_size } }
2129
end
2230

2331
assert_redirected_to group_classifier_state_url(GroupClassifierState.last)

test/controllers/trained_messages_controller_test.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ class TrainedMessagesControllerTest < ActionDispatch::IntegrationTest
1717

1818
test "should create trained_message" do
1919
assert_difference("TrainedMessage.count") do
20-
post trained_messages_url, params: { trained_message: { group_id: @trained_message.group_id, message: @trained_message.message, message_type: @trained_message.message_type, sender_chat_id: @trained_message.sender_chat_id } }
20+
TelegramMemberFetcher.stub(:get_bot_chat_member, OpenStruct.new(status: "administrator", can_restrict_members: true)) do
21+
post trained_messages_url, params: { trained_message: {
22+
group_id: @trained_message.group_id,
23+
message: @trained_message.message,
24+
message_type: @trained_message.message_type,
25+
sender_chat_id: @trained_message.sender_chat_id } }
26+
end
2127
end
2228

2329
assert_redirected_to trained_message_url(TrainedMessage.last)

test/fixtures/group_classifier_states.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ one:
1111
vocabulary_size: 1
1212

1313
two:
14-
group_id: 1
14+
group_id: 2
1515
spam_counts: '{"word5": 2, "word6": 8}'
1616
ham_counts: '{"word7": 4, "word8": 6}'
1717
total_spam_words: 1

test/services/spam_detection_service_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ def setup
5757
tg_message = OpenStruct.new(chat: @chat, from: @from, text: pre_existing_message.message, message_id: 123)
5858
service = SpamDetectionService.new(tg_message)
5959

60-
result = service.process
60+
result = nil
61+
TelegramMemberFetcher.stub(:get_bot_chat_member, OpenStruct.new(status: "administrator", can_restrict_members: true)) do
62+
result = service.process
63+
end
6164

6265
assert result.is_spam
6366
assert_equal TrainedMessage::TrainingTarget::MESSAGE_CONTENT, result.target

test/system/group_classifier_states_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class GroupClassifierStatesTest < ApplicationSystemTestCase
1414
visit group_classifier_states_url
1515
click_on "New Group Classifier"
1616

17-
fill_in "Group", with: @group_classifier_state.group_id
17+
fill_in "Group", with: 99
1818
fill_in "Ham counts", with: @group_classifier_state.ham_counts
1919
fill_in "Spam counts", with: @group_classifier_state.spam_counts
2020
fill_in "Total ham messages", with: @group_classifier_state.total_ham_messages

test/system/trained_messages_test.rb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require "application_system_test_case"
2+
require "ostruct"
3+
require "minitest/mock"
24

35
class TrainedMessagesTest < ApplicationSystemTestCase
46
setup do
@@ -11,18 +13,20 @@ class TrainedMessagesTest < ApplicationSystemTestCase
1113
end
1214

1315
test "should create trained message" do
14-
visit trained_messages_url
15-
click_on "New trained message"
16-
17-
fill_in "Group", with: @trained_message.group_id
18-
fill_in "Message", with: @trained_message.message
19-
select "Spam", from: "Message type"
20-
select "Message Content", from: "Training target"
21-
fill_in "Sender chat", with: @trained_message.sender_chat_id
22-
click_on "Create Trained message"
23-
24-
assert_text "Trained message was successfully created"
25-
click_on "Back"
16+
TelegramMemberFetcher.stub(:get_bot_chat_member, OpenStruct.new(status: "administrator", can_restrict_members: true)) do
17+
visit trained_messages_url
18+
click_on "New trained message"
19+
20+
fill_in "Group", with: @trained_message.group_id
21+
fill_in "Message", with: @trained_message.message
22+
select "Spam", from: "Message type"
23+
select "Message Content", from: "Training target"
24+
fill_in "Sender chat", with: @trained_message.sender_chat_id
25+
click_on "Create Trained message"
26+
27+
assert_text "Trained message was successfully created"
28+
click_on "Back"
29+
end
2630
end
2731

2832
test "should update Trained message" do

0 commit comments

Comments
 (0)