mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-11 18:26:50 +00:00
There were a few changes needed: * Plugins are now specified through `plugin:` config keyword. * All plugin gems need to be specified explicitly in Gemfile since they are no longer dependencies of plugins already specified explicitly. * All plugin gems need to be updated in other to use the new APIs. * One cop was renamed. * New offenses safe to correct were corrected directly with `bundle exec rubocop -a`. * New offenses unsafe to correct were added to the TODO configuration with `bundle exec rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1400 --no-auto-gen-timestamp`.
71 lines
2.0 KiB
Ruby
71 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
module Api
|
|
RSpec.describe V0::CustomersController do
|
|
include AuthenticationHelper
|
|
|
|
render_views
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
describe "index" do
|
|
let!(:customer1) { create(:customer, created_manually: true) }
|
|
let!(:customer2) { create(:customer, created_manually: true) }
|
|
|
|
before do
|
|
user.customers << customer1
|
|
allow(controller).to receive(:spree_current_user) { user }
|
|
end
|
|
|
|
it "lists customers associated with the current user" do
|
|
get :index
|
|
expect(response).to have_http_status :ok
|
|
expect(json_response.length).to eq 1
|
|
expect(json_response.first[:id]).to eq customer1.id
|
|
end
|
|
end
|
|
|
|
describe "#update" do
|
|
let(:customer) { create(:customer, user:) }
|
|
let(:params) { { format: :json, id: customer.id, customer: { code: '123' } } }
|
|
|
|
context "as a user who is not associated with the customer" do
|
|
before do
|
|
allow(controller).to receive(:spree_current_user) { create(:user) }
|
|
end
|
|
|
|
it "returns unauthorized" do
|
|
spree_post :update, params
|
|
assert_unauthorized!
|
|
end
|
|
end
|
|
|
|
context "as the user associated with the customer" do
|
|
before do
|
|
allow(controller).to receive(:spree_current_user) { user }
|
|
end
|
|
|
|
context "when the update request is successful" do
|
|
it "returns the id of the updated customer" do
|
|
spree_post :update, params
|
|
expect(response).to have_http_status :ok
|
|
expect(json_response[:id]).to eq customer.id
|
|
end
|
|
end
|
|
|
|
context "when the update request fails" do
|
|
before { params[:customer][:email] = '' }
|
|
|
|
it "returns a 422, with an error message" do
|
|
spree_post :update, params
|
|
expect(response).to have_http_status :unprocessable_entity
|
|
expect(json_response[:error]).to be
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|