DEV: Remove mocks from specs.

This commit is contained in:
Guo Xiang Tan 2018-11-07 09:55:58 +08:00
parent a2044c4528
commit bdb8e9efdb
1 changed files with 10 additions and 6 deletions

View File

@ -11,8 +11,9 @@ describe Jobs::SuspiciousLogin do
end
it "will not send an email on first login" do
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :suspicious_login)).never
described_class.new.execute(user_id: user.id, client_ip: "1.1.1.1")
expect do
described_class.new.execute(user_id: user.id, client_ip: "1.1.1.1")
end.to_not change { Jobs::CriticalUserEmail.jobs.size }
expect(UserAuthTokenLog.where(action: "suspicious").count).to eq(0)
end
@ -20,9 +21,10 @@ describe Jobs::SuspiciousLogin do
it "will not send an email when user log in from a known location" do
UserAuthTokenLog.create!(action: "generate", user_id: user.id, client_ip: "1.1.1.1")
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :suspicious_login)).never
described_class.new.execute(user_id: user.id, client_ip: "1.1.1.1")
described_class.new.execute(user_id: user.id, client_ip: "1.1.1.2")
expect do
described_class.new.execute(user_id: user.id, client_ip: "1.1.1.1")
described_class.new.execute(user_id: user.id, client_ip: "1.1.1.2")
end.to_not change { Jobs::CriticalUserEmail.jobs.size }
expect(UserAuthTokenLog.where(action: "suspicious").count).to eq(0)
end
@ -30,10 +32,12 @@ describe Jobs::SuspiciousLogin do
it "will send an email when user logs in from a new location" do
UserAuthTokenLog.create!(action: "generate", user_id: user.id, client_ip: "1.1.1.1")
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :suspicious_login))
described_class.new.execute(user_id: user.id, client_ip: "1.1.2.1")
expect(UserAuthTokenLog.where(action: "suspicious").count).to eq(1)
expect(Jobs::CriticalUserEmail.jobs.first["args"].first["type"])
.to eq('suspicious_login')
end
end