spree_auth_devise 4.0.0 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of spree_auth_devise might be problematic. Click here for more details.

Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +41 -0
  3. data/.gitignore +1 -0
  4. data/.travis.yml +33 -37
  5. data/Appraisals +3 -14
  6. data/Gemfile +1 -1
  7. data/README.md +3 -12
  8. data/Rakefile +9 -3
  9. data/app/controllers/spree/api/v2/storefront/account_confirmations_controller.rb +20 -0
  10. data/app/controllers/spree/api/v2/storefront/passwords_controller.rb +35 -0
  11. data/app/controllers/spree/user_confirmations_controller.rb +38 -0
  12. data/app/controllers/spree/user_passwords_controller.rb +9 -1
  13. data/app/controllers/spree/user_registrations_controller.rb +34 -1
  14. data/app/controllers/spree/user_sessions_controller.rb +23 -1
  15. data/app/mailers/spree/user_mailer.rb +11 -4
  16. data/app/models/spree/user.rb +42 -0
  17. data/app/services/spree/account/create.rb +19 -0
  18. data/app/services/spree/account/update.rb +17 -0
  19. data/app/views/spree/user_mailer/confirmation_instructions.html.erb +20 -0
  20. data/app/views/spree/user_mailer/confirmation_instructions.text.erb +8 -5
  21. data/app/views/spree/user_mailer/reset_password_instructions.html.erb +20 -0
  22. data/app/views/spree/user_mailer/reset_password_instructions.text.erb +7 -5
  23. data/app/views/spree/user_passwords/edit.html.erb +20 -17
  24. data/app/views/spree/user_passwords/new.html.erb +17 -15
  25. data/app/views/spree/user_registrations/new.html.erb +12 -17
  26. data/app/views/spree/user_sessions/new.html.erb +11 -12
  27. data/config/locales/de.yml +16 -0
  28. data/config/locales/en.yml +21 -6
  29. data/config/locales/zh-TW.yml +58 -0
  30. data/config/routes.rb +12 -3
  31. data/db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb +2 -2
  32. data/gemfiles/{spree_3_2.gemfile → spree_4_1.gemfile} +1 -1
  33. data/lib/controllers/api/spree/api/v2/storefront/account_controller_decorator.rb +41 -0
  34. data/lib/controllers/frontend/spree/checkout_controller_decorator.rb +3 -2
  35. data/lib/controllers/frontend/spree/users_controller.rb +4 -4
  36. data/lib/generators/spree/auth/install/install_generator.rb +0 -4
  37. data/lib/spree/auth/engine.rb +14 -1
  38. data/lib/spree/testing_support/auth_helpers.rb +36 -0
  39. data/lib/spree/testing_support/checkout_helpers.rb +24 -0
  40. data/lib/spree_auth_devise.rb +0 -1
  41. data/lib/views/backend/spree/admin/user_passwords/new.html.erb +1 -1
  42. data/lib/views/backend/spree/admin/user_sessions/new.html.erb +1 -1
  43. data/spec/controllers/spree/admin/orders_controller_spec.rb +1 -1
  44. data/spec/controllers/spree/admin/user_sessions_controller_spec.rb +1 -1
  45. data/spec/controllers/spree/api/v2/storefront/passwords_controller_spec.rb +63 -0
  46. data/spec/controllers/spree/checkout_controller_spec.rb +12 -13
  47. data/spec/controllers/spree/products_controller_spec.rb +1 -1
  48. data/spec/controllers/spree/user_passwords_controller_spec.rb +4 -4
  49. data/spec/controllers/spree/user_registrations_controller_spec.rb +8 -8
  50. data/spec/controllers/spree/user_sessions_controller_spec.rb +17 -17
  51. data/spec/controllers/spree/users_controller_spec.rb +4 -4
  52. data/spec/features/account_spec.rb +10 -8
  53. data/spec/features/admin/password_reset_spec.rb +2 -4
  54. data/spec/features/admin/sign_in_spec.rb +13 -9
  55. data/spec/features/admin/sign_out_spec.rb +1 -1
  56. data/spec/features/admin_permissions_spec.rb +1 -1
  57. data/spec/features/change_email_spec.rb +1 -7
  58. data/spec/features/checkout_spec.rb +40 -65
  59. data/spec/features/confirmation_spec.rb +4 -6
  60. data/spec/features/order_spec.rb +9 -15
  61. data/spec/features/password_reset_spec.rb +2 -4
  62. data/spec/features/sign_in_spec.rb +21 -17
  63. data/spec/features/sign_out_spec.rb +14 -23
  64. data/spec/features/sign_up_spec.rb +6 -4
  65. data/spec/mailers/user_mailer_spec.rb +4 -4
  66. data/spec/models/user_spec.rb +10 -8
  67. data/spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb +48 -0
  68. data/spec/requests/spree/api/v2/storefront/account_spec.rb +101 -0
  69. data/spec/spec_helper.rb +7 -22
  70. data/spree_auth_devise.gemspec +14 -27
  71. metadata +35 -337
  72. data/app/overrides/auth_shared_login_bar.rb +0 -6
  73. data/app/overrides/spree/admin/shared/_header/auth_admin_login_navigation_bar.html.erb.deface +0 -4
  74. data/app/views/spree/shared/_login.html.erb +0 -18
  75. data/app/views/spree/shared/_user_form.html.erb +0 -17
  76. data/gemfiles/spree_3_5.gemfile +0 -8
  77. data/gemfiles/spree_3_7.gemfile +0 -9
  78. data/gemfiles/spree_4_0.gemfile +0 -8
  79. data/lib/assets/javascripts/spree/backend/spree_auth.js.erb +0 -1
  80. data/lib/assets/javascripts/spree/frontend/account.js +0 -8
  81. data/lib/assets/javascripts/spree/frontend/spree_auth.js.erb +0 -2
  82. data/lib/assets/stylesheets/spree/backend/spree_auth.css.erb +0 -3
  83. data/lib/assets/stylesheets/spree/frontend/spree_auth.css.erb +0 -3
  84. data/lib/controllers/frontend/spree/store_controller_decorator.rb +0 -7
  85. data/lib/views/frontend/spree/checkout/_new_user.html.erb +0 -20
  86. data/lib/views/frontend/spree/checkout/registration.html.erb +0 -25
  87. data/lib/views/frontend/spree/shared/_link_to_account.html.erb +0 -6
  88. data/lib/views/frontend/spree/users/edit.html.erb +0 -17
  89. data/lib/views/frontend/spree/users/show.html.erb +0 -48
  90. data/spec/support/add_to_cart.rb +0 -15
  91. data/spec/support/authentication_helpers.rb +0 -14
  92. data/spec/support/cache_helpers.rb +0 -5
  93. data/spec/support/capybara.rb +0 -16
  94. data/spec/support/database_cleaner.rb +0 -17
  95. data/spec/support/factory_girl.rb +0 -5
  96. data/spec/support/spree.rb +0 -10
@@ -3,13 +3,11 @@ require 'spec_helper'
3
3
  RSpec.feature 'Confirmation', type: :feature, reload_user: true do
4
4
  before do
5
5
  set_confirmable_option(true)
6
- Spree::UserMailer.stub(:confirmation_instructions).and_return(double(deliver: true))
6
+ expect(Spree::UserMailer).to receive(:confirmation_instructions).with(anything, anything, { current_store_id: Spree::Store.current.id }).and_return(double(deliver: true))
7
7
  end
8
8
 
9
9
  after(:each) { set_confirmable_option(false) }
10
10
 
11
- let!(:store) { create(:store) }
12
-
13
11
  background do
14
12
  ActionMailer::Base.default_url_options[:host] = 'http://example.com'
15
13
  end
@@ -20,9 +18,9 @@ RSpec.feature 'Confirmation', type: :feature, reload_user: true do
20
18
  fill_in 'Email', with: 'email@person.com'
21
19
  fill_in 'Password', with: 'password'
22
20
  fill_in 'Password Confirmation', with: 'password'
23
- click_button 'Create'
21
+ click_button 'Sign Up'
24
22
 
25
- expect(page).to have_text 'You have signed up successfully.'
26
- expect(Spree::User.last.confirmed?).to be(false)
23
+ expect(page).to have_text I18n.t('devise.user_registrations.signed_up_but_unconfirmed')
24
+ expect(Spree.user_class.last.confirmed?).to be(false)
27
25
  end
28
26
  end
@@ -6,46 +6,40 @@ RSpec.feature 'Orders', :js, type: :feature do
6
6
 
7
7
  # regression test for spree/spree#1687
8
8
  scenario 'merge incomplete orders from different sessions' do
9
- skip %{
10
- TODO: has been broken for ~2 months as of:
11
- https://github.com/spree/spree_auth_devise/commit/3157b47b22c559817d34ec34024587d8aa6136dc
12
- I dont think we can decode these sessions anymore since Rails 4 switched to encrypted cookies I believe devise stores session encrypted.
13
- }
14
- create(:product, name: 'RoR Mug')
15
- create(:product, name: 'RoR Shirt')
9
+ ror_mug = create(:product, name: 'RoR Mug')
10
+ ror_shirt = create(:product, name: 'RoR Shirt')
16
11
 
17
12
  user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
18
13
 
19
14
  using_session('first') do
20
- add_to_cart 'RoR Mug'
15
+ add_to_cart ror_mug
21
16
 
22
17
  visit spree.login_path
23
18
  fill_in 'Email', with: user.email
24
19
  fill_in 'Password', with: user.password
25
- click_button 'Login'
20
+ click_button 'Log in'
26
21
 
27
- click_link 'Cart'
22
+ visit spree.cart_path
28
23
  expect(page).to have_text 'RoR Mug'
29
24
  end
30
25
 
31
26
  using_session('second') do
32
- add_to_cart 'RoR Shirt'
27
+ add_to_cart ror_shirt
33
28
 
34
29
  visit spree.login_path
35
30
  fill_in 'Email', with: user.email
36
31
  fill_in 'Password', with: user.password
37
- click_button 'Login'
32
+ click_button 'Log in'
38
33
 
39
34
  # Order should have been merged with first session
40
- click_link 'Cart'
35
+ visit spree.cart_path
41
36
  expect(page).to have_text 'RoR Mug'
42
37
  expect(page).to have_text 'RoR Shirt'
43
38
  end
44
39
 
45
40
  using_session('first') do
46
41
  visit spree.root_path
47
-
48
- click_link 'Cart'
42
+ visit spree.cart_path
49
43
 
50
44
  # Order should have been merged with second session
51
45
  expect(page).to have_text 'RoR Mug'
@@ -1,6 +1,4 @@
1
1
  RSpec.feature 'Reset Password', type: :feature do
2
- let!(:store) { create(:store) }
3
-
4
2
  background do
5
3
  ActionMailer::Base.default_url_options[:host] = 'http://example.com'
6
4
  end
@@ -8,7 +6,7 @@ RSpec.feature 'Reset Password', type: :feature do
8
6
  scenario 'allow a user to supply an email for the password reset' do
9
7
  user = create(:user, email: 'foobar@example.com', password: 'secret', password_confirmation: 'secret')
10
8
  visit spree.login_path
11
- click_link 'Forgot Password?'
9
+ click_link 'Forgot password?'
12
10
  fill_in 'Email', with: 'foobar@example.com'
13
11
  click_button 'Reset my password'
14
12
  expect(page).to have_text 'You will receive an email with instructions'
@@ -16,7 +14,7 @@ RSpec.feature 'Reset Password', type: :feature do
16
14
 
17
15
  scenario 'shows errors if no email is supplied' do
18
16
  visit spree.login_path
19
- click_link 'Forgot Password?'
17
+ click_link 'Forgot password?'
20
18
  click_button 'Reset my password'
21
19
  expect(page).to have_text "Email can't be blank"
22
20
  end
@@ -10,23 +10,21 @@ RSpec.feature 'Sign In', type: :feature do
10
10
  end
11
11
 
12
12
  scenario 'let a user sign in successfully', js: true do
13
- fill_in 'Email', with: @user.email
14
- fill_in 'Password', with: @user.password
15
- click_button 'Login'
13
+ log_in(email: @user.email, password: @user.password)
14
+ show_user_menu
16
15
 
17
- expect(page).to have_text 'Logged in successfully'
18
16
  expect(page).not_to have_text 'Login'
19
- expect(page).to have_text 'Logout'
20
- expect(current_path).to eq '/'
17
+ expect(page).to have_text 'LOG OUT'
18
+ expect(current_path).to eq '/account'
21
19
  end
22
20
 
23
21
  scenario 'show validation erros' do
24
22
  fill_in 'Email', with: @user.email
25
23
  fill_in 'Password', with: 'wrong_password'
26
- click_button 'Login'
24
+ click_button 'Log in'
27
25
 
28
26
  expect(page).to have_text 'Invalid email or password'
29
- expect(page).to have_text 'Login'
27
+ expect(page).to have_text 'Log in'
30
28
  end
31
29
 
32
30
  scenario 'allow a user to access a restricted page after logging in' do
@@ -35,19 +33,25 @@ RSpec.feature 'Sign In', type: :feature do
35
33
 
36
34
  fill_in 'Email', with: user.email
37
35
  fill_in 'Password', with: user.password
38
- click_button 'Login'
39
-
40
- within '.user-menu' do
41
- expect(page).to have_text 'admin@person.com'
36
+ click_button 'Log in'
37
+
38
+ if Spree.version.to_f > 4.1
39
+ within '.navbar .dropdown-menu' do
40
+ expect(page).to have_text 'admin@person.com'
41
+ end
42
+ else
43
+ within '.user-menu' do
44
+ expect(page).to have_text 'admin@person.com'
45
+ end
42
46
  end
43
47
  expect(current_path).to eq '/admin/orders'
44
48
  end
45
49
 
46
- xit "should store the user previous location" do
50
+ it 'should store the user previous location' do
47
51
  visit spree.account_path
48
- fill_in "Email", with: @user.email
49
- fill_in "Password", with: @user.password
50
- click_button "Login"
51
- expect(current_path).to eq "/account"
52
+ fill_in 'Email', with: @user.email
53
+ fill_in 'Password', with: @user.password
54
+ click_button 'Log in'
55
+ expect(current_path).to eq '/account'
52
56
  end
53
57
  end
@@ -7,44 +7,35 @@ RSpec.feature 'Sign Out', type: :feature, js: true do
7
7
  end
8
8
 
9
9
  background do
10
- visit spree.login_path
11
- fill_in 'Email', with: user.email
12
- fill_in 'Password', with: user.password
13
- # Regression test for #1257
14
- check 'Remember me'
15
- click_button 'Login'
10
+ log_in(email: user.email, password: user.password)
16
11
  end
17
12
 
18
13
  scenario 'allow a signed in user to logout' do
19
- click_link 'Logout'
14
+ log_out
15
+
20
16
  visit spree.root_path
21
- expect(page).to have_text 'Login'
22
- expect(page).not_to have_text 'Logout'
17
+ show_user_menu
18
+
19
+ expect(page).to have_link 'LOG IN'
20
+ expect(page).not_to have_link 'LOG OUT'
23
21
  end
24
22
 
25
23
  describe 'before_logout' do
26
- before do
27
- create(:product, name: 'RoR Mug')
28
- create(:product, name: 'RoR Shirt')
29
- end
30
-
24
+ let!(:mug) { create(:product_in_stock, name: 'RoR Mug') }
25
+ let!(:shirt) { create(:product, name: 'RoR Shirt') }
31
26
  let!(:other_user) { create(:user) }
32
27
 
33
28
  it 'clears token cookies' do
34
- add_to_cart 'RoR Mug'
35
- expect(page).to have_text 'RoR Mug'
29
+ add_to_cart(mug)
36
30
 
37
- click_link 'Logout'
31
+ log_out
38
32
 
39
- click_link 'Cart'
33
+ find('#link-to-cart').click
40
34
  expect(page).to have_text Spree.t(:your_cart_is_empty)
41
35
 
42
- visit spree.login_path
43
- fill_in 'Email', with: other_user.email
44
- fill_in 'Password', with: other_user.password
45
- click_button 'Login'
36
+ log_in(email: other_user.email, password: user.password)
37
+ find('#link-to-cart').click
46
38
 
47
- click_link 'Cart'
48
39
  expect(page).to have_text Spree.t(:your_cart_is_empty)
49
40
  end
50
41
  end
@@ -6,10 +6,11 @@ RSpec.feature 'Sign Up', type: :feature do
6
6
  fill_in 'Email', with: 'email@person.com'
7
7
  fill_in 'Password', with: 'password'
8
8
  fill_in 'Password Confirmation', with: 'password'
9
- click_button 'Create'
9
+
10
+ click_button 'Sign Up'
10
11
 
11
12
  expect(page).to have_text 'You have signed up successfully.'
12
- expect(Spree::User.count).to eq(1)
13
+ expect(Spree.user_class.count).to eq(1)
13
14
  end
14
15
  end
15
16
 
@@ -20,10 +21,11 @@ RSpec.feature 'Sign Up', type: :feature do
20
21
  fill_in 'Email', with: 'email@person.com'
21
22
  fill_in 'Password', with: 'password'
22
23
  fill_in 'Password Confirmation', with: ''
23
- click_button 'Create'
24
+
25
+ click_button 'Sign Up'
24
26
 
25
27
  expect(page).to have_css '#errorExplanation'
26
- expect(Spree::User.count).to eq(0)
28
+ expect(Spree.user_class.count).to eq(0)
27
29
  end
28
30
  end
29
31
  end
@@ -1,11 +1,11 @@
1
1
  RSpec.describe Spree::UserMailer, type: :mailer do
2
- let!(:store) { create(:store) }
3
2
  let(:user) { create(:user) }
3
+ let(:store) { Spree::Store.default }
4
4
 
5
5
  describe '#reset_password_instructions' do
6
6
  describe 'message contents' do
7
7
  before do
8
- @message = described_class.reset_password_instructions(user, 'token goes here')
8
+ @message = described_class.reset_password_instructions(user, 'token goes here', { current_store_id: Spree::Store.current.id })
9
9
  end
10
10
 
11
11
  context 'subject includes' do
@@ -22,7 +22,7 @@ RSpec.describe Spree::UserMailer, type: :mailer do
22
22
 
23
23
  context 'body includes' do
24
24
  it 'password reset url' do
25
- expect(@message.body.raw_source).to include "http://#{store.url}/user/spree_user/password/edit"
25
+ expect(@message.body.encoded).to include "http://#{store.url}/user/spree_user/password/edit"
26
26
  end
27
27
  end
28
28
  end
@@ -30,7 +30,7 @@ RSpec.describe Spree::UserMailer, type: :mailer do
30
30
  describe 'legacy support for User object' do
31
31
  it 'sends an email' do
32
32
  expect {
33
- described_class.reset_password_instructions(user, 'token goes here').deliver_now
33
+ described_class.reset_password_instructions(user, 'token goes here', { current_store_id: Spree::Store.current.id }).deliver_now
34
34
  }.to change(ActionMailer::Base.deliveries, :size).by(1)
35
35
  end
36
36
  end
@@ -1,5 +1,6 @@
1
1
  RSpec.describe Spree::User, type: :model do
2
2
  before(:all) { Spree::Role.create name: 'admin' }
3
+ let!(:store) { create(:store) }
3
4
 
4
5
  it '#admin?' do
5
6
  expect(create(:admin_user).admin?).to be true
@@ -8,8 +9,9 @@ RSpec.describe Spree::User, type: :model do
8
9
 
9
10
  it 'generates the reset password token' do
10
11
  user = build(:user)
11
- expect(Spree::UserMailer).to receive(:reset_password_instructions).with(user, anything, {}).and_return(double(deliver: true))
12
- user.send_reset_password_instructions
12
+ current_store = Spree::Store.current
13
+ expect(Spree::UserMailer).to receive(:reset_password_instructions).with(user, anything, { current_store_id: current_store.id }).and_return(double(deliver: true))
14
+ user.send_reset_password_instructions(current_store)
13
15
  expect(user.reset_password_token).not_to be_nil
14
16
  end
15
17
 
@@ -31,9 +33,9 @@ RSpec.describe Spree::User, type: :model do
31
33
  order.save
32
34
  user = order.user
33
35
  user.destroy
34
- expect(Spree::User.find_by_id(user.id)).to be_nil
35
- expect(Spree::User.with_deleted.find_by_id(user.id).id).to eq(user.id)
36
- expect(Spree::User.with_deleted.find_by_id(user.id).orders.first).to eq(order)
36
+ expect(Spree.user_class.find_by_id(user.id)).to be_nil
37
+ expect(Spree.user_class.with_deleted.find_by_id(user.id).id).to eq(user.id)
38
+ expect(Spree.user_class.with_deleted.find_by_id(user.id).orders.first).to eq(order)
37
39
 
38
40
  expect(Spree::Order.find_by_user_id(user.id)).not_to be_nil
39
41
  expect(Spree::Order.where(user_id: user.id).first).to eq(order)
@@ -66,14 +68,14 @@ RSpec.describe Spree::User, type: :model do
66
68
  describe "confirmable", reload_user: true do
67
69
  it "is confirmable if the confirmable option is enabled" do
68
70
  set_confirmable_option(true)
69
- Spree::UserMailer.stub(:confirmation_instructions).and_return(double(deliver: true))
70
- expect(Spree::User.devise_modules).to include(:confirmable)
71
+ Spree::UserMailer.stub(:confirmation_instructions).with(anything, anything, { current_store_id: Spree::Store.current.id }).and_return(double(deliver: true))
72
+ expect(Spree.user_class.devise_modules).to include(:confirmable)
71
73
  set_confirmable_option(false)
72
74
  end
73
75
 
74
76
  it "is not confirmable if the confirmable option is disabled" do
75
77
  set_confirmable_option(false)
76
- expect(Spree::User.devise_modules).to_not include(:confirmable)
78
+ expect(Spree.user_class.devise_modules).to_not include(:confirmable)
77
79
  end
78
80
  end
79
81
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Storefront API v2 Account Confirmation spec', type: :request do
4
+ describe 'account_confirmations#show' do
5
+
6
+ before do
7
+ Spree::User.stub(:confirm_by_token, confirmation_token: confirmation_token).and_return user
8
+ get "/api/v2/storefront/account_confirmations/#{confirmation_token}"
9
+ end
10
+
11
+ context 'valid confirmation_token param' do
12
+ let(:user) { create(:user, confirmation_token: '12345') }
13
+ let(:confirmation_token) { user.confirmation_token }
14
+
15
+ it_behaves_like 'returns 200 HTTP status'
16
+
17
+ it 'returns user state' do
18
+ expect(JSON.parse(response.body)['data']['state']).to eq('')
19
+ end
20
+ end
21
+
22
+ context 'invalid confirmation_token param' do
23
+ let(:user) do
24
+ user = create(:user)
25
+ user.errors.add(:confirmation_token, :invalid)
26
+ return user
27
+ end
28
+ let(:confirmation_token) { 'dummy_token' }
29
+
30
+ it 'return 422 status' do
31
+ expect(response.code).to eq('422')
32
+ end
33
+
34
+ it 'return JSON API payload of error' do
35
+ expect(JSON.parse(response.body)['error']).to eq("Confirmation token is invalid")
36
+ end
37
+ end
38
+
39
+ context 'blank confirmation_token param' do
40
+ let(:user) { build(:user) }
41
+ let(:confirmation_token) { '' }
42
+
43
+ it 'return 301 status' do
44
+ expect(response.code).to eq('301')
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Storefront API v2 Account spec', type: :request do
4
+ describe 'account#create' do
5
+ before { post '/api/v2/storefront/account', params: params }
6
+
7
+ context 'valid user params' do
8
+ let(:params) do
9
+ {
10
+ "user": {
11
+ "email": "hello@example.com",
12
+ "password": "password123",
13
+ "password_confirmation": "password123"
14
+ }
15
+ }
16
+ end
17
+
18
+ it_behaves_like 'returns 200 HTTP status'
19
+
20
+ it 'return JSON API payload of User' do
21
+ expect(JSON.parse(response.body)['data']['attributes']['email']).to eq('hello@example.com')
22
+ end
23
+ end
24
+
25
+ context 'invalid user params' do
26
+ let(:params) do
27
+ {
28
+ "user": {
29
+ "email": "hello@example.com",
30
+ "password": "password123",
31
+ "password_confirmation": ""
32
+ }
33
+ }
34
+ end
35
+
36
+ it 'return JSON API payload of error' do
37
+ expect(JSON.parse(response.body)['error']).to eq("Password Confirmation doesn't match Password")
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ describe 'account#update' do
44
+ include_context 'API v2 tokens'
45
+
46
+ let!(:user) { create(:user_with_addresses) }
47
+ let(:headers) { headers_bearer }
48
+
49
+ before { patch '/api/v2/storefront/account', params: params, headers: headers }
50
+
51
+ context 'valid user params' do
52
+ let(:params) do
53
+ {
54
+ "user": {
55
+ "email": "spree@example.com",
56
+ "password": "password123",
57
+ "password_confirmation": "password123"
58
+ }
59
+ }
60
+ end
61
+
62
+ it_behaves_like 'returns 200 HTTP status'
63
+
64
+ it 'return JSON API payload of User' do
65
+ expect(JSON.parse(response.body)['data']['attributes']['email']).to eq('spree@example.com')
66
+ end
67
+ end
68
+
69
+ context 'valid user params without passwords' do
70
+ let(:params) do
71
+ {
72
+ "user": {
73
+ "email": "spree@example.com"
74
+ }
75
+ }
76
+ end
77
+
78
+ it_behaves_like 'returns 200 HTTP status'
79
+
80
+ it 'return JSON API payload of User' do
81
+ expect(JSON.parse(response.body)['data']['attributes']['email']).to eq('spree@example.com')
82
+ end
83
+ end
84
+
85
+ context 'invalid user params' do
86
+ let(:params) do
87
+ {
88
+ "user": {
89
+ "email": "spree@example.com",
90
+ "password": "password123",
91
+ "password_confirmation": ""
92
+ }
93
+ }
94
+ end
95
+
96
+ it 'return JSON API payload of error' do
97
+ expect(JSON.parse(response.body)['error']).to eq("Password Confirmation doesn't match Password")
98
+ end
99
+ end
100
+ end
101
+ end