mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add ToS acceptance to customer endpoint
It's another read-only attribute. Please note that JSON:API specifies a format of `date-time` which we don't adhere to because it uses a `Z` in front of the timezone offset which doesn't seem to be included in the default json serialisation. So I didn't add the format and left it as simple `string`. Problem?
This commit is contained in:
@@ -14,6 +14,10 @@ class CustomerSchema < JsonApiSchema
|
||||
code: { type: :string, nullable: true, example: "BUYER1" },
|
||||
email: { type: :string, example: "alice@example.com" },
|
||||
allow_charges: { type: :boolean, example: false },
|
||||
terms_and_conditions_accepted_at: {
|
||||
type: :string, format: "date-time", nullable: true,
|
||||
example: "2022-03-12T15:55:00.000+11:00",
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
@@ -25,6 +29,7 @@ class CustomerSchema < JsonApiSchema
|
||||
attributes.except(
|
||||
:id,
|
||||
:allow_charges,
|
||||
:terms_and_conditions_accepted_at,
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ module Api
|
||||
module V1
|
||||
class CustomerSerializer < BaseSerializer
|
||||
attributes :id, :enterprise_id, :first_name, :last_name, :code, :email,
|
||||
:allow_charges
|
||||
:allow_charges, :terms_and_conditions_accepted_at
|
||||
|
||||
belongs_to :enterprise, links: {
|
||||
related: ->(object) {
|
||||
|
||||
@@ -5,7 +5,13 @@ require "swagger_helper"
|
||||
describe "Customers", type: :request do
|
||||
let!(:enterprise1) { create(:enterprise) }
|
||||
let!(:enterprise2) { create(:enterprise) }
|
||||
let!(:customer1) { create(:customer, enterprise: enterprise1) }
|
||||
let!(:customer1) {
|
||||
create(
|
||||
:customer,
|
||||
enterprise: enterprise1,
|
||||
terms_and_conditions_accepted_at: Time.zone.parse("2000-01-01"),
|
||||
)
|
||||
}
|
||||
let!(:customer2) { create(:customer, enterprise: enterprise1) }
|
||||
let!(:customer3) { create(:customer, enterprise: enterprise2) }
|
||||
|
||||
@@ -116,7 +122,8 @@ describe "Customers", type: :request do
|
||||
|
||||
run_test! do
|
||||
expect(json_response[:data][:attributes]).to include(
|
||||
allow_charges: false
|
||||
allow_charges: false,
|
||||
terms_and_conditions_accepted_at: nil,
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -179,7 +186,14 @@ describe "Customers", type: :request do
|
||||
param(:id) { customer1.id }
|
||||
schema "$ref": "#/components/schemas/resources/customer"
|
||||
|
||||
run_test!
|
||||
run_test! do
|
||||
date_time_string =
|
||||
json_response[:data][:attributes][:terms_and_conditions_accepted_at]
|
||||
expect(date_time_string).to match /^2000-01-01T00:00:00.000[Z+-].*$/
|
||||
expect(DateTime.parse(date_time_string)).to eq(
|
||||
customer1.terms_and_conditions_accepted_at
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
response "404", "Not found" do
|
||||
|
||||
@@ -63,6 +63,11 @@ components:
|
||||
allow_charges:
|
||||
type: boolean
|
||||
example: false
|
||||
terms_and_conditions_accepted_at:
|
||||
type: string
|
||||
format: date-time
|
||||
nullable: true
|
||||
example: '2022-03-12T15:55:00.000+11:00'
|
||||
required:
|
||||
- id
|
||||
- enterprise_id
|
||||
@@ -71,6 +76,7 @@ components:
|
||||
- code
|
||||
- email
|
||||
- allow_charges
|
||||
- terms_and_conditions_accepted_at
|
||||
relationships:
|
||||
type: object
|
||||
properties:
|
||||
@@ -137,6 +143,11 @@ components:
|
||||
allow_charges:
|
||||
type: boolean
|
||||
example: false
|
||||
terms_and_conditions_accepted_at:
|
||||
type: string
|
||||
format: date-time
|
||||
nullable: true
|
||||
example: '2022-03-12T15:55:00.000+11:00'
|
||||
required:
|
||||
- id
|
||||
- enterprise_id
|
||||
@@ -145,6 +156,7 @@ components:
|
||||
- code
|
||||
- email
|
||||
- allow_charges
|
||||
- terms_and_conditions_accepted_at
|
||||
relationships:
|
||||
type: object
|
||||
properties:
|
||||
|
||||
Reference in New Issue
Block a user