diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 52b08ce53..6b4a70fe3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -58,7 +58,7 @@ jobs: "friendly_image_tag": "latest", "image_tag": "prod-${{ github.sha }}", "ecs_cluster": "scfm", - "docs_path": "docs/scfm" + "docs_path": "docs/open-ews" } ] EOF @@ -141,9 +141,6 @@ jobs: cp -R api_docs/api/* source bundle exec middleman build --build-dir=build/api - cp -R api_docs/open_ews_api/* source - bundle exec middleman build --build-dir=build/open_ews_api - - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -157,7 +154,6 @@ jobs: - name: Deploy API Documentation run: | aws s3 sync --delete --acl public-read build/api s3://www.somleng.org/${{ matrix.docs_path }} - aws s3 sync --delete --acl public-read build/open_ews_api s3://www.somleng.org/${{ matrix.docs_path }}/open_ews_api - name: Invalidate Cache run: aws cloudfront create-invalidation --distribution-id E3962XCJFZ0KB1 --paths /${{ matrix.docs_path }}/\* diff --git a/app/request_schemas/v1/beneficiary_request_schema.rb b/app/request_schemas/v1/beneficiary_request_schema.rb index 2deb6343e..4c16f5d5f 100644 --- a/app/request_schemas/v1/beneficiary_request_schema.rb +++ b/app/request_schemas/v1/beneficiary_request_schema.rb @@ -4,7 +4,7 @@ class BeneficiaryRequestSchema < JSONAPIRequestSchema required(:data).value(:hash).schema do required(:type).filled(:str?, eql?: "beneficiary") required(:attributes).value(:hash).schema do - required(:msisdn).filled(:string) + required(:phone_number).filled(:string) required(:iso_country_code).filled(Types::UpcaseString, included_in?: Contact.iso_country_code.values) optional(:language_code).maybe(:string) optional(:date_of_birth).maybe(:date) @@ -25,32 +25,32 @@ class BeneficiaryRequestSchema < JSONAPIRequestSchema end end - attribute_rule(:msisdn).validate(:phone_number_format) + attribute_rule(:phone_number).validate(:phone_number_format) rule(data: :attributes) do Rules.new(self).validate end def output result = super - result[:msisdn] = PhonyRails.normalize_number(result.fetch(:msisdn)) if result.key?(:msisdn) + result[:msisdn] = PhonyRails.normalize_number(result.delete(:phone_number)) result end class Rules < SchemaRules::JSONAPISchemaRules def validate if resource.blank? - return key(:msisdn).failure(text: "can't be blank") if values[:msisdn].blank? + return key(:phone_number).failure(text: "can't be blank") if values[:phone_number].blank? - key(:msisdn).failure(text: "must be unique") if contact_exists? - elsif values[:msisdn].present? - key(:msisdn).failure(text: "must be unique") if contact_exists? + key(:phone_number).failure(text: "must be unique") if contact_exists? + elsif values[:phone_number].present? + key(:phone_number).failure(text: "must be unique") if contact_exists? end end private def contact_exists? - relation = account.contacts.where_msisdn(values.fetch(:msisdn)) + relation = account.contacts.where_msisdn(values.fetch(:phone_number)) relation = relation.where.not(id: resource.id) if resource.present? relation.exists? end diff --git a/app/request_schemas/v1/update_beneficiary_request_schema.rb b/app/request_schemas/v1/update_beneficiary_request_schema.rb index c6e160b0c..3c34901c1 100644 --- a/app/request_schemas/v1/update_beneficiary_request_schema.rb +++ b/app/request_schemas/v1/update_beneficiary_request_schema.rb @@ -5,24 +5,24 @@ class UpdateBeneficiaryRequestSchema < JSONAPIRequestSchema required(:id).filled(:integer) required(:type).filled(:str?, eql?: "beneficiary") required(:attributes).value(:hash).schema do - optional(:msisdn).filled(:string) + optional(:iso_country_code).filled(Types::UpcaseString, included_in?: Contact.iso_country_code.values) + optional(:phone_number).filled(:string) optional(:language_code).maybe(:string) optional(:date_of_birth).maybe(:date) optional(:gender).maybe(:string, included_in?: Contact.gender.values) - optional(:iso_country_code).maybe(:string, included_in?: Contact.iso_country_code.values) optional(:metadata).maybe(:hash?) end end end - attribute_rule(:msisdn).validate(:phone_number_format) + attribute_rule(:phone_number).validate(:phone_number_format) rule do BeneficiaryRequestSchema::Rules.new(self).validate end def output result = super - result[:msisdn] = PhonyRails.normalize_number(result.fetch(:msisdn)) if result.key?(:msisdn) + result[:msisdn] = PhonyRails.normalize_number(result.delete(:phone_number)) if result.key?(:phone_number) result end end diff --git a/app/serailizers/beneficiary_serializer.rb b/app/serailizers/beneficiary_serializer.rb index b19a3169f..33dfb17f1 100644 --- a/app/serailizers/beneficiary_serializer.rb +++ b/app/serailizers/beneficiary_serializer.rb @@ -1,8 +1,12 @@ class BeneficiarySerializer < ResourceSerializer - attributes :msisdn, :language_code, :date_of_birth, :iso_country_code, :metadata + attributes :phone_number, :language_code, :date_of_birth, :iso_country_code, :metadata has_many :addresses, serializer: BeneficiaryAddressSerializer attribute :gender do |object| object.gender_value end + + attribute :phone_number do |object| + object.msisdn + end end diff --git a/spec/request_schemas/v1/beneficiary_request_schema_spec.rb b/spec/request_schemas/v1/beneficiary_request_schema_spec.rb index fe00a54c3..06f816eb4 100644 --- a/spec/request_schemas/v1/beneficiary_request_schema_spec.rb +++ b/spec/request_schemas/v1/beneficiary_request_schema_spec.rb @@ -2,34 +2,34 @@ module V1 RSpec.describe BeneficiaryRequestSchema, type: :request_schema do - it "validates the msisdn" do + it "validates the phone_number" do contact = create(:contact) expect( - validate_schema(input_params: { data: { attributes: { msisdn: nil } } }) - ).not_to have_valid_field(:data, :attributes, :msisdn) + validate_schema(input_params: { data: { attributes: { phone_number: nil } } }) + ).not_to have_valid_field(:data, :attributes, :phone_number) expect( - validate_schema(input_params: { data: { attributes: { msisdn: "+855 97 2345 6789" } } }) - ).not_to have_valid_field(:data, :attributes, :msisdn) + validate_schema(input_params: { data: { attributes: { phone_number: "+855 97 2345 6789" } } }) + ).not_to have_valid_field(:data, :attributes, :phone_number) expect( - validate_schema(input_params: { data: { attributes: { msisdn: "+855 97 2345 678" } } }) - ).to have_valid_field(:data, :attributes, :msisdn) + validate_schema(input_params: { data: { attributes: { phone_number: "+855 97 2345 678" } } }) + ).to have_valid_field(:data, :attributes, :phone_number) expect( validate_schema( - input_params: { data: { attributes: { msisdn: contact.msisdn, iso_country_code: "KH" } } }, + input_params: { data: { attributes: { phone_number: contact.msisdn, iso_country_code: "KH" } } }, options: { account: contact.account } ) - ).not_to have_valid_field(:data, :attributes, :msisdn) + ).not_to have_valid_field(:data, :attributes, :phone_number) expect( validate_schema( - input_params: { data: { attributes: { msisdn: "+855 97 2345 678", iso_country_code: "KH" } } }, + input_params: { data: { attributes: { phone_number: "+855 97 2345 678", iso_country_code: "KH" } } }, options: { account: contact.account } ) - ).to have_valid_field(:data, :attributes, :msisdn) + ).to have_valid_field(:data, :attributes, :phone_number) end it "validates the iso_country_code" do @@ -131,7 +131,7 @@ module V1 input_params: { data: { attributes: { - msisdn: "(855) 97 2345 678", + phone_number: "(855) 97 2345 678", iso_country_code: "kh" } } diff --git a/spec/requests/open_ews_api/v1/beneficiaries/addresses_spec.rb b/spec/requests/open_ews_api/v1/beneficiaries/addresses_spec.rb index cefd41c38..4d7d79b6f 100644 --- a/spec/requests/open_ews_api/v1/beneficiaries/addresses_spec.rb +++ b/spec/requests/open_ews_api/v1/beneficiaries/addresses_spec.rb @@ -1,8 +1,8 @@ require "rails_helper" -RSpec.resource "Beneficiary's Addresses" do +RSpec.resource "Addresses" do get "/v1/beneficiaries/:beneficiary_id/addresses" do - example "List all a beneficiary's addresses" do + example "List all addresses for a beneficiary" do account = create(:account) beneficiary = create(:beneficiary, account:) address1 = create(:beneficiary_address, beneficiary:) @@ -51,7 +51,7 @@ end get "/v1/beneficiaries/:beneficiary_id/addresses/:id" do - example "Get an address for a beneficiary" do + example "Fetch an address for a beneficiary" do account = create(:account) beneficiary = create(:beneficiary, account:) address = create(:beneficiary_address, beneficiary:) diff --git a/spec/requests/open_ews_api/v1/beneficiaries_spec.rb b/spec/requests/open_ews_api/v1/beneficiaries_spec.rb index c674afbbd..f2f9e8ee9 100644 --- a/spec/requests/open_ews_api/v1/beneficiaries_spec.rb +++ b/spec/requests/open_ews_api/v1/beneficiaries_spec.rb @@ -44,7 +44,7 @@ post "/v1/beneficiaries" do with_options scope: %i[data attributes] do parameter( - :msisdn, "Phone number in E.164 format or shortcode.", + :phone_number, "Phone number in E.164 format or shortcode.", required: true ) parameter( @@ -60,7 +60,7 @@ required: false ) parameter( - :iso_country_code, "The ISO 3166-1 alpha-2 country code of the phone number. It must be matched with the country of `msisdn` parameter.", + :iso_country_code, "The ISO 3166-1 alpha-2 country code of the phone number. It must be matched with the country of `phone_number` parameter.", required: false ) parameter( @@ -107,7 +107,7 @@ data: { type: :beneficiary, attributes: { - msisdn: "+85510999999", + phone_number: "+85510999999", language_code: "km", gender: "M", date_of_birth: "1990-01-01", @@ -125,7 +125,7 @@ expect(response_status).to eq(201) expect(response_body).to match_jsonapi_resource_schema("beneficiary") expect(jsonapi_response_attributes).to include( - "msisdn" => "+85510999999", + "phone_number" => "+85510999999", "language_code" => "km", "gender" => "M", "date_of_birth" => "1990-01-01", @@ -149,7 +149,7 @@ data: { type: :beneficiary, attributes: { - msisdn: "+85510999999", + phone_number: "+85510999999", iso_country_code: "kh" } } @@ -159,13 +159,13 @@ expect(response_body).to match_api_response_schema("jsonapi_error") expect(json_response.dig("errors", 0)).to include( "title" => "must be unique", - "source" => { "pointer" => "/data/attributes/msisdn" } + "source" => { "pointer" => "/data/attributes/phone_number" } ) end end get "/v1/beneficiaries/:id" do - example "Get a beneficiary" do + example "Fetch a beneficiary" do beneficiary = create(:beneficiary) set_authorization_header_for(beneficiary.account) @@ -195,7 +195,7 @@ id: beneficiary.id, type: :beneficiary, attributes: { - msisdn: "+85510999002", + phone_number: "+85510999002", gender: "F", status: "disabled", language_code: "en", @@ -210,7 +210,7 @@ expect(response_status).to eq(200) expect(response_body).to match_jsonapi_resource_schema("beneficiary") expect(jsonapi_response_attributes).to include( - "msisdn" => "+85510999002", + "phone_number" => "+85510999002", "language_code" => "en", "gender" => "F", "date_of_birth" => "1990-01-01", diff --git a/spec/support/api_response_schemas/beneficiary_schema.rb b/spec/support/api_response_schemas/beneficiary_schema.rb index dd961e0a6..c2cfc6d24 100644 --- a/spec/support/api_response_schemas/beneficiary_schema.rb +++ b/spec/support/api_response_schemas/beneficiary_schema.rb @@ -4,7 +4,7 @@ module APIResponseSchema required(:type).filled(eql?: "beneficiary") required(:attributes).schema do - required(:msisdn).filled(:str?) + required(:phone_number).filled(:str?) required(:language_code).maybe(:str?) required(:gender).maybe(:str?) required(:date_of_birth).maybe(:str?) diff --git a/spec/support/request_spec_helpers.rb b/spec/support/request_spec_helpers.rb index 861c5e9fe..06dfb45d8 100644 --- a/spec/support/request_spec_helpers.rb +++ b/spec/support/request_spec_helpers.rb @@ -21,10 +21,10 @@ def jsonapi_response_attributes config.include(RequestSpecHelpers, type: :request) config.define_derived_metadata(file_path: %r{spec/requests/scfm_api/}) do |metadata| - metadata[:document] = :scfm_api + metadata[:document] = false end config.define_derived_metadata(file_path: %r{spec/requests/open_ews_api/}) do |metadata| - metadata[:document] = :open_ews_api + metadata[:jsonapi] = true end end diff --git a/spec/support/rspec_api_documentation.rb b/spec/support/rspec_api_documentation.rb index 47f8f9406..977491c8c 100644 --- a/spec/support/rspec_api_documentation.rb +++ b/spec/support/rspec_api_documentation.rb @@ -1,9 +1,9 @@ require "rspec_api_documentation/dsl" RspecApiDocumentation.configure do |config| - config.api_name = "Somleng SCFM API Documentation" + config.api_name = "OpenEWS API Documentation" config.api_explanation = <<~HEREDOC - This is the API Documentation for Somleng Simple Call Flow Manager (Somleng SCFM). + This is the API Documentation for OpenEWS. HEREDOC config.format = :slate config.curl_headers_to_filter = [ "Host", "Cookie", "Content-Type" ] @@ -13,7 +13,7 @@ config.request_body_formatter = proc do |params| JSON.pretty_generate(params) if params.present? end - config.keep_source_order = false + config.keep_source_order = true config.disable_dsl_status! # https://github.com/zipmark/rspec_api_documentation/pull/458 @@ -24,14 +24,4 @@ response_body end end - - config.define_group :scfm_api do |conf| - conf.filter = :scfm_api - conf.docs_dir = Rails.root.join("doc/api") - end - - config.define_group :open_ews_api do |conf| - conf.filter = :open_ews_api - conf.docs_dir = Rails.root.join("doc/open_ews_api") - end end diff --git a/spec/support/rspec_api_documentation_client.rb b/spec/support/rspec_api_documentation_client.rb index d4c4ec9b2..2c8af27fc 100644 --- a/spec/support/rspec_api_documentation_client.rb +++ b/spec/support/rspec_api_documentation_client.rb @@ -1,18 +1,11 @@ class APIDocumentationClient < RspecApiDocumentation::RackTestClient - DOC_HOSTS = { - scfm_api: "https://scfm.somleng.org", - open_ews_api: "https://api.open-ews.org" - } - - private def process(method, path, params = {}, headers = {}) if path.start_with?("http") full_path = path else - doc_host = DOC_HOSTS.fetch(metadata[:document]) { DOC_HOSTS[:scfm_api] } - full_path = URI.join(doc_host, path) + full_path = URI.join("https://api.open-ews.org", path) end do_request(method, full_path, params, headers) @@ -30,7 +23,7 @@ def client RSpec.configure do |config| config.prepend(APIDocumentationHelpers, api_doc_dsl: :resource) - config.before(:each, document: :open_ews_api) do + config.before(:each, jsonapi: true) do header("Content-Type", "application/vnd.api+json") end end