* Don't set saw_onboarding automatically This should be set by the onboarding checkbox update (user accepted terms of service and code of conduct). The issue is a PATCH request to track the last seen page is sent on the first page, _before_ the user consents to the terms via the checkboxes. This issue is masked by a 422 unprocessable entity response when we don't get a username in the patch request (next commit). * Only validate username on the username page Every other "last page seen" dialog was returning a 422 because the username is only submitted in the 3rd dialog "build your profile". Only validate the username field when it's submitted, process other onboarding updates normally. * Remove failing test Since the onboarding_update action no longer sets saw onboarding (since we send the patch before they've accepted the code of conduct), don't test that we do. There's a parallel test for the onboarding checkbox update later in this file that covers the checkboxes have been accepted. * overwrite instead of merging user_params We now initialize it empty, no need to merge params here.
75 lines
2.4 KiB
Ruby
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_update" 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_update.json", 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_update.json", 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_update.json", 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_update.json", 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_update.json", 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_update.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 eq(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
|