diff --git a/app/controllers/api/v1/customers_controller.rb b/app/controllers/api/v1/customers_controller.rb index d342f05ef8..5353c6d39f 100644 --- a/app/controllers/api/v1/customers_controller.rb +++ b/app/controllers/api/v1/customers_controller.rb @@ -88,20 +88,17 @@ module Api attributes = params.require(:customer).permit( :email, :enterprise_id, :code, :first_name, :last_name, - :billing_address, - shipping_address: [ + :billing_address, shipping_address: [ :phone, :latitude, :longitude, :first_name, :last_name, :street_address_1, :street_address_2, :postal_code, :locality, { region: [:name, :code], country: [:name, :code] }, - ], - tags: [], + ] ).to_h attributes.merge!(created_manually: true) - tags = attributes.delete(:tags) - attributes.merge!(tag_list: tags) if tags.present? + attributes.merge!(tag_list: params[:tags]) if params.key?(:tags) transform_address!(attributes, :billing_address, :bill_address) transform_address!(attributes, :shipping_address, :ship_address) diff --git a/spec/requests/api/v1/customers_spec.rb b/spec/requests/api/v1/customers_spec.rb index 0dea8f4a4e..9f158e1de4 100644 --- a/spec/requests/api/v1/customers_spec.rb +++ b/spec/requests/api/v1/customers_spec.rb @@ -173,23 +173,15 @@ RSpec.describe "Customers", swagger_doc: "v1.yaml", feature: :api_v1 do parameter name: :customer, in: :body, schema: { type: :object, - properties: { - customer: { - type: :object, - properties: CustomerSchema.writable_attributes, - required: CustomerSchema.required_attributes - } - }, - required: ['customer'] + properties: CustomerSchema.writable_attributes, + required: CustomerSchema.required_attributes } response "201", "Minimal customer created" do let(:customer) do { - customer: { - email: "test@example.com", - enterprise_id: enterprise1.id.to_s - } + email: "test@example.com", + enterprise_id: enterprise1.id.to_s } end schema '$ref': "#/components/schemas/customer" @@ -207,15 +199,12 @@ RSpec.describe "Customers", swagger_doc: "v1.yaml", feature: :api_v1 do response "201", "Example customer created" do let(:customer) do - { - customer: CustomerSchema.writable_attributes.transform_values do |attribute| - attribute[:example] - end.merge( - enterprise_id: enterprise1.id, - ) - } + CustomerSchema.writable_attributes.transform_values do |attribute| + attribute[:example] + end.merge( + enterprise_id: enterprise1.id, + ) end - schema '$ref': "#/components/schemas/customer" run_test! do @@ -234,11 +223,9 @@ RSpec.describe "Customers", swagger_doc: "v1.yaml", feature: :api_v1 do response "422", "Unpermitted parameter" do let(:customer) do { - customer: { - email: "test@example.com", - enterprise_id: enterprise1.id.to_s, - allow_charges: true, - } + email: "test@example.com", + enterprise_id: enterprise1.id.to_s, + allow_charges: true, } end schema '$ref': "#/components/schemas/error_response" @@ -360,14 +347,8 @@ RSpec.describe "Customers", swagger_doc: "v1.yaml", feature: :api_v1 do parameter name: :customer, in: :body, schema: { type: :object, - properties: { - customer: { - type: :object, - properties: CustomerSchema.writable_attributes, - required: CustomerSchema.required_attributes - } - }, - required: ['customer'] + properties: CustomerSchema.writable_attributes, + required: CustomerSchema.required_attributes } response "200", "Customer updated" do diff --git a/swagger/v1.yaml b/swagger/v1.yaml index 837a15fcfa..a9305be001 100644 --- a/swagger/v1.yaml +++ b/swagger/v1.yaml @@ -347,62 +347,57 @@ paths: schema: type: object properties: - customer: + enterprise_id: + type: integer + example: 2 + first_name: + type: string + nullable: true + example: Alice + last_name: + type: string + nullable: true + example: Springs + code: + type: string + nullable: true + example: BUYER1 + email: + type: string + example: alice@example.com + tags: + type: array + items: + type: string + example: + - staff + - discount + billing_address: type: object - properties: - enterprise_id: - type: integer - example: 2 - first_name: - type: string - nullable: true - example: Alice - last_name: - type: string - nullable: true - example: Springs - code: - type: string - nullable: true - example: BUYER1 - email: - type: string - example: alice@example.com - tags: - type: array - items: - type: string - example: - - staff - - discount - billing_address: - type: object - nullable: true - example: - shipping_address: - type: object - nullable: true - example: - phone: 0404 333 222 111 - latitude: -37.8173751 - longitude: 144.964803195704 - first_name: Alice - last_name: Springs - street_address_1: 1 Flinders Street - street_address_2: '' - postal_code: '1234' - locality: Melbourne - region: - code: Vic - name: Victoria - country: - code: AU - name: Australia - required: - - enterprise_id - - email + nullable: true + example: + shipping_address: + type: object + nullable: true + example: + phone: 0404 333 222 111 + latitude: -37.8173751 + longitude: 144.964803195704 + first_name: Alice + last_name: Springs + street_address_1: 1 Flinders Street + street_address_2: '' + postal_code: '1234' + locality: Melbourne + region: + code: Vic + name: Victoria + country: + code: AU + name: Australia required: - - customer + - enterprise_id + - email "/api/v1/customers/{id}": get: summary: Show customer @@ -575,62 +570,57 @@ paths: schema: type: object properties: - customer: + enterprise_id: + type: integer + example: 2 + first_name: + type: string + nullable: true + example: Alice + last_name: + type: string + nullable: true + example: Springs + code: + type: string + nullable: true + example: BUYER1 + email: + type: string + example: alice@example.com + tags: + type: array + items: + type: string + example: + - staff + - discount + billing_address: type: object - properties: - enterprise_id: - type: integer - example: 2 - first_name: - type: string - nullable: true - example: Alice - last_name: - type: string - nullable: true - example: Springs - code: - type: string - nullable: true - example: BUYER1 - email: - type: string - example: alice@example.com - tags: - type: array - items: - type: string - example: - - staff - - discount - billing_address: - type: object - nullable: true - example: - shipping_address: - type: object - nullable: true - example: - phone: 0404 333 222 111 - latitude: -37.8173751 - longitude: 144.964803195704 - first_name: Alice - last_name: Springs - street_address_1: 1 Flinders Street - street_address_2: '' - postal_code: '1234' - locality: Melbourne - region: - code: Vic - name: Victoria - country: - code: AU - name: Australia - required: - - enterprise_id - - email + nullable: true + example: + shipping_address: + type: object + nullable: true + example: + phone: 0404 333 222 111 + latitude: -37.8173751 + longitude: 144.964803195704 + first_name: Alice + last_name: Springs + street_address_1: 1 Flinders Street + street_address_2: '' + postal_code: '1234' + locality: Melbourne + region: + code: Vic + name: Victoria + country: + code: AU + name: Australia required: - - customer + - enterprise_id + - email delete: summary: Delete customer tags: