docbrown/spec/requests/users_onboarding_spec.rb
Mac Siri 4b37f2384c
Refactor OnboardingsController (#17329)
* Refactor OnboardingsController

* Fix broken spec

* Update policy

* Fix spec

* Update config/routes.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Touchup

* Update routes

* Screw it, let's move notification_settings too

* Revert "Screw it, let's move notification_settings too"

This reverts commit aead8c05f4dda62cbc46cdd033afd0acdef2ad73.

* Temp .travis.yml changes

* Revert "Temp .travis.yml changes"

This reverts commit c26109843ba027f9a524e66282a9b01f0341f836.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-04-27 16:17:02 -04:00

75 lines
2.4 KiB
Ruby

require "rails_helper"
RSpec.describe "UsersOnboarding", type: :request do
let!(:user) do
create(:user,
saw_onboarding: false,
_skip_creating_profile: true,
profile: create(:profile, location: "Llama Town"))
end
describe "PATCH /onboarding" do
context "when signed in" do
before { sign_in user }
it "updates the user's last_onboarding_page attribute" do
params = { user: { last_onboarding_page: "v2: personal info form", username: "test" } }
expect do
patch "/onboarding", params: params
end.to change(user, :last_onboarding_page)
end
it "updates the user's username attribute" do
params = { user: { username: "WilhuffTarkin" } }
expect do
patch "/onboarding", params: params
end.to change(user, :username).to("wilhufftarkin")
end
it "returns a 422 error if the username is blank" do
params = { user: { username: "" } }
patch "/onboarding", params: params
expect(response).to have_http_status(:unprocessable_entity)
end
it "updates the user's profile" do
params = { profile: { location: "Galactic Empire" } }
expect do
patch "/onboarding", params: params
end.to change(user.profile, :location).to("Galactic Empire")
end
it "does not update the user's last_onboarding_page if it is empty" do
params = { user: { last_onboarding_page: "" } }
expect do
patch "/onboarding", params: params
end.not_to change(user, :last_onboarding_page)
end
end
context "when signed out" do
it "returns a not found error if user is not signed in" do
patch "/onboarding.json", params: {}
expect(response.parsed_body["error"]).to include("Please sign in")
end
end
end
describe "PATCH /onboarding_checkbox_update" do
context "when signed in" do
before { sign_in user }
it "updates saw_onboarding boolean" do
patch "/onboarding_checkbox_update.json", params: {}
expect(user.saw_onboarding).to be(true)
end
end
context "when signed out" do
it "returns a not found error if user is not signed in" do
patch "/onboarding_checkbox_update.json", params: {}
expect(response.parsed_body["error"]).to include("Please sign in")
end
end
end
end