Skip to content

Commit

Permalink
add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
oma-s committed Apr 8, 2024
1 parent 5860d68 commit a19209b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
19 changes: 19 additions & 0 deletions spec/models/daily_nerd_message_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe DailyNerdMessage do
fixtures :all
let(:user) { users(:john) }
let(:daily_nerd_message) { user.sprint_feedbacks.take.daily_nerd_messages.create(message: "I'm a daily nerd") }

describe "#push_to_slack" do
it "posts the daily nerd message to Slack" do
slack_notification = instance_double("User::SlackNotification")
allow(User::SlackNotification).to receive(:new).with(user).and_return(slack_notification)
expect(slack_notification).to receive(:post_daily_nerd_message).with(daily_nerd_message.message)

daily_nerd_message.push_to_slack
end
end
end
64 changes: 64 additions & 0 deletions spec/system/daily_nerd_messages_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

require "system_helper"

RSpec.describe "Daily Nerd messages" do
fixtures :all
let(:user) { users(:john) }
let(:sprint) { sprints(:empty) }
let(:sprint_feedback) { SprintFeedback.find_by(user:, sprint:) }

before do
allow(Slack.instance).to receive(:retrieve_users_profile_image_url_by_email).and_return("https://example.com/image.jpg")
allow(Slack.instance).to receive(:push_personalized_message_to_daily_nerd_channel)
end

def login_and_create_daily_nerd_message
travel_to "2023-01-29"
login user

visit root_path

expect(page).to have_content "Daily Nerd"
expect(page).to have_field "Message", placeholder: "How was your day? What did you learn?"

fill_in "Message", with: "I'm a daily nerd"
click_on "Create Daily nerd message"

expect(page).to have_current_path sprints_path
visit root_path

expect(page).to have_field "Message", with: "I'm a daily nerd"

fill_in "Message", with: "I'm a daily nerd and I learned a lot"
click_on "Update Daily nerd message"
end

it "creates and edits daily nerd messages" do
login_and_create_daily_nerd_message

expect(page).to have_current_path sprints_path
visit root_path

expect(page).to have_field "Message", with: "I'm a daily nerd and I learned a lot"
end

it "does not show the form, when there is no current sprint" do
travel_to "3000-01-01"
login user

visit root_path

expect(page).not_to have_content "Daily Nerd"
expect(page).not_to have_field "Message"
end

it "adds a daily nerd entry to the sprint feedback" do
expect(sprint_feedback.daily_nerd_count).to eq 3

login_and_create_daily_nerd_message

expect(sprint_feedback.reload.daily_nerd_count).to eq 4
expect(sprint_feedback.daily_nerd_entry_dates).to include(Time.zone.now)
end
end

0 comments on commit a19209b

Please sign in to comment.