From 7310e89a82205dbc773a89ef39be763e6bb9075b Mon Sep 17 00:00:00 2001 From: khoa-v-nguyen Date: Wed, 17 Apr 2024 14:18:27 -0600 Subject: [PATCH] Add test_create endpoint --- .../ask_va_api/v0/inquiries_controller.rb | 12 ++++++++++-- modules/ask_va_api/config/routes.rb | 1 + .../ask_va_api/spec/requests/v0/inquiries_spec.rb | 13 +++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/ask_va_api/app/controllers/ask_va_api/v0/inquiries_controller.rb b/modules/ask_va_api/app/controllers/ask_va_api/v0/inquiries_controller.rb index c0bdb1d7b59..0ec2b8d17ed 100644 --- a/modules/ask_va_api/app/controllers/ask_va_api/v0/inquiries_controller.rb +++ b/modules/ask_va_api/app/controllers/ask_va_api/v0/inquiries_controller.rb @@ -6,8 +6,8 @@ class InquiriesController < ApplicationController around_action :handle_exceptions before_action :get_inquiries_by_icn, only: [:index] before_action :get_inquiry_by_id, only: [:show] - skip_before_action :authenticate, only: %i[unauth_create upload_attachment] - skip_before_action :verify_authenticity_token, only: %i[unauth_create upload_attachment] + skip_before_action :authenticate, only: %i[unauth_create upload_attachment test_create] + skip_before_action :verify_authenticity_token, only: %i[unauth_create upload_attachment test_create] def index render json: @user_inquiries.payload, status: @user_inquiries.status @@ -17,6 +17,14 @@ def show render json: @inquiry.payload, status: @inquiry.status end + def test_create + service = Crm::Service.new(icn: nil) + payload = { reply: params[:reply] } + response = service.call(endpoint: params[:endpoint], method: :post, payload:) + + render json: response.to_json, status: :ok + end + def create render json: { message: 'success' }, status: :created end diff --git a/modules/ask_va_api/config/routes.rb b/modules/ask_va_api/config/routes.rb index 0c43f79eb11..eb52ce26270 100644 --- a/modules/ask_va_api/config/routes.rb +++ b/modules/ask_va_api/config/routes.rb @@ -15,6 +15,7 @@ post '/inquiries', to: 'inquiries#unauth_create' post '/upload_attachment', to: 'inquiries#upload_attachment' post '/inquiries/:id/reply/new', to: 'inquiries#create_reply' + post '/test_create', to: 'inquiries#test_create' # static_data get '/categories', to: 'static_data#categories' diff --git a/modules/ask_va_api/spec/requests/v0/inquiries_spec.rb b/modules/ask_va_api/spec/requests/v0/inquiries_spec.rb index 1427d49bed9..3e1bf2ffd11 100644 --- a/modules/ask_va_api/spec/requests/v0/inquiries_spec.rb +++ b/modules/ask_va_api/spec/requests/v0/inquiries_spec.rb @@ -100,6 +100,19 @@ end end + describe 'POST #test_create' do + before do + allow_any_instance_of(Crm::Service).to receive(:call).and_return({ message: 'success' }) + post '/ask_va_api/v0/test_create', + params: { 'reply' => 'test', 'endpoint' => 'inquiries/id/reply/new' }, + as: :json + end + + it 'response with 200' do + expect(response).to have_http_status(:ok) + end + end + describe 'GET #show' do let(:expected_response) do { 'data' =>