mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-09 23:06:06 +00:00
Adding controller actions and routes for pausing and unpausing a standing order
This commit is contained in:
@@ -410,7 +410,7 @@ describe Admin::StandingOrdersController, type: :controller do
|
||||
before { shop.update_attributes(owner: user) }
|
||||
|
||||
it 'renders the cancelled standing_order as json' do
|
||||
spree_get :cancel, params
|
||||
spree_put :cancel, params
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['canceled_at']).to_not be nil
|
||||
expect(json_response['id']).to eq standing_order.id
|
||||
@@ -420,4 +420,94 @@ describe Admin::StandingOrdersController, type: :controller do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'pause' do
|
||||
let!(:user) { create(:user, enterprise_limit: 10) }
|
||||
let!(:shop) { create(:distributor_enterprise) }
|
||||
let!(:standing_order) { create(:standing_order_with_items, shop: shop) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { user }
|
||||
end
|
||||
|
||||
context 'json' do
|
||||
let(:params) { { format: :json, id: standing_order.id } }
|
||||
|
||||
context 'as a regular user' do
|
||||
it 'redirects to unauthorized' do
|
||||
spree_put :pause, params
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context 'as an enterprise user' do
|
||||
context "without authorisation" do
|
||||
let!(:shop2) { create(:distributor_enterprise) }
|
||||
before { shop2.update_attributes(owner: user) }
|
||||
|
||||
it 'redirects to unauthorized' do
|
||||
spree_put :pause, params
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "with authorisation" do
|
||||
before { shop.update_attributes(owner: user) }
|
||||
|
||||
it 'renders the paused standing_order as json' do
|
||||
spree_put :pause, params
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['paused_at']).to_not be nil
|
||||
expect(json_response['id']).to eq standing_order.id
|
||||
expect(standing_order.reload.paused_at).to be_within(5.seconds).of Time.now
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'unpause' do
|
||||
let!(:user) { create(:user, enterprise_limit: 10) }
|
||||
let!(:shop) { create(:distributor_enterprise) }
|
||||
let!(:standing_order) { create(:standing_order_with_items, shop: shop, paused_at: Time.zone.now) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { user }
|
||||
end
|
||||
|
||||
context 'json' do
|
||||
let(:params) { { format: :json, id: standing_order.id } }
|
||||
|
||||
context 'as a regular user' do
|
||||
it 'redirects to unauthorized' do
|
||||
spree_put :unpause, params
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context 'as an enterprise user' do
|
||||
context "without authorisation" do
|
||||
let!(:shop2) { create(:distributor_enterprise) }
|
||||
before { shop2.update_attributes(owner: user) }
|
||||
|
||||
it 'redirects to unauthorized' do
|
||||
spree_put :unpause, params
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "with authorisation" do
|
||||
before { shop.update_attributes(owner: user) }
|
||||
|
||||
it 'renders the paused standing_order as json' do
|
||||
spree_put :unpause, params
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['paused_at']).to be nil
|
||||
expect(json_response['id']).to eq standing_order.id
|
||||
expect(standing_order.reload.paused_at).to be nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user