diff --git a/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee index c77fdc1fd6..ec9a6553a2 100644 --- a/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee @@ -9,10 +9,9 @@ angular.module('Darkswarm').controller "RegistrationFormCtrl", ($scope, Registra $scope.create = (form) -> if ($scope.valid(form)) $scope.disableButton() - EnterpriseRegistrationService.create().then(() -> + EnterpriseRegistrationService.create($scope.enableButton).then(() -> $scope.enableButton() ) - end $scope.update = (nextStep, form) -> EnterpriseRegistrationService.update(nextStep) if $scope.valid(form) diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index 9e184e7cd3..f2081bbb14 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -159,6 +159,54 @@ describe "Registration" do expect(page).to have_checked_field "enterprise_visible_only_through_links" end + context "Enterprise name is already taken" do + let(:owner) do + Spree::User.create!(email: "penny.profile@example.org", password: "cannotbeblank") + end + + before do + address = Spree::Address.create!(firstname: 'John', lastname: 'Doe', + address1: '1400 Sesame street', zipcode: '3070', + city: 'Southcote', phone: '12 3456 7890', + country_id: 1, state_id: 1, company: 'unused') + Enterprise.create(name: 'My Awesome Enterprise', address:, owner:) + end + + it "checks that button after failure is still enabled" do + visit registration_path + switch_to_login_tab + + fill_in "Email", with: user.email + fill_in "Password", with: user.password + click_button "Login" + click_button "Let's get started!" + + fill_in 'enterprise_name', with: "My Awesome Enterprise" + fill_in 'enterprise_address', with: '123 Abc Street' + fill_in 'enterprise_city', with: 'Northcote' + fill_in 'enterprise_zipcode', with: '3070' + select 'Vic', from: 'enterprise_state' + click_button "Continue" + + fill_in 'enterprise_contact', with: 'Saskia Munroe' + fill_in 'enterprise_phone', with: '12 3456 7890' + + click_button "Continue" + click_button "Create Profile" + click_link "producer-panel" + alert_text = <<~TEXT.strip + Name has already been taken. If this is your enterprise and you would \ + like to claim ownership, or if you would like to trade with this \ + enterprise please contact the current manager of this profile at \ + penny.profile@example.org. + TEXT + accept_alert(alert_text) do + click_button "Create Profile" + end + expect(page).to have_button "Create Profile", disabled: false + end + end + context "when the user has no more remaining enterprises" do before do user.update(enterprise_limit: 0)