-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Piotr Milewski
committed
Jun 1, 2020
1 parent
f608c28
commit 2e5ea1b
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
app/controllers/spree/api/v2/storefront/account_confirmations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Spree | ||
module Api | ||
module V2 | ||
module Storefront | ||
class AccountConfirmationsController < ::Spree::Api::V2::BaseController | ||
|
||
def show | ||
user = Spree.user_class.confirm_by_token(params[:id]) | ||
|
||
if user.errors.empty? | ||
render json: { data: { state: user.respond_to?(:state) ? user.state : '' } }, status: :ok | ||
else | ||
render json: { error: user.errors.full_messages.to_sentence }, status: :unprocessable_entity | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Storefront API v2 Account Confirmation spec', type: :request do | ||
describe 'account_confirmations#show' do | ||
|
||
before do | ||
set_confirmable_option(true) | ||
get "/api/v2/storefront/account_confirmations/#{confirmation_token}" | ||
end | ||
|
||
after(:each) { set_confirmable_option(false) } | ||
|
||
context 'valid confirmation_token param' do | ||
let(:user) { create(:user, confirmation_token: '12345') } | ||
let(:confirmation_token) { user.confirmation_token } | ||
|
||
it_behaves_like 'returns 200 HTTP status' | ||
|
||
it 'returns user state' do | ||
expect(JSON.parse(response.body)['data']['state']).to eq('') | ||
end | ||
end | ||
|
||
context 'invalid confirmation_token param' do | ||
let(:confirmation_token) { 'dummy_token' } | ||
|
||
it 'return 422 status' do | ||
expect(response.code).to eq('422') | ||
end | ||
|
||
it 'return JSON API payload of error' do | ||
expect(JSON.parse(response.body)['error']).to eq("Confirmation token is invalid") | ||
end | ||
end | ||
|
||
context 'blank confirmation_token param' do | ||
let(:confirmation_token) { '' } | ||
|
||
it 'return 301 status' do | ||
expect(response.code).to eq('301') | ||
end | ||
end | ||
end | ||
end |