generated from betagouv/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add QuoteCheck ErrorDetails custom feedbacks route
- Loading branch information
1 parent
3699313
commit 0e1b65a
Showing
8 changed files
with
204 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
spec/requests/api/v1/quote_check_validation_error_details_feedbacks_doc_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
require "swagger_helper" | ||
|
||
describe "Devis API" do | ||
path "/quote_checks/{quote_check_id}/error_details/{error_details_id}/feedbacks" do | ||
# TODO: i18n? | ||
post "Déposer un retour" do | ||
tags "Devis" | ||
security [basic_auth: []] | ||
consumes "application/json" | ||
produces "application/json" | ||
|
||
parameter name: :quote_check_id, in: :path, type: :string | ||
parameter name: :error_details_id, in: :path, type: :string | ||
parameter name: :quote_check_feedback, in: :body, schema: { | ||
type: :object, | ||
properties: { | ||
is_helpful: { type: :boolean, nullable: false }, | ||
comment: { | ||
type: :string, | ||
nullable: true, | ||
maxLength: QuoteCheckFeedback.validators_on(:comment).detect do |validator| | ||
validator.is_a?(ActiveModel::Validations::LengthValidator) | ||
end&.options&.[](:maximum) | ||
} | ||
}, | ||
required: %w[is_helpful] | ||
} | ||
|
||
let(:quote_check) { create(:quote_check, :invalid) } | ||
let(:quote_check_id) { quote_check.id } | ||
let(:error_details_id) { quote_check.validation_error_details.first.fetch("id") } | ||
let(:quote_check_feedback) do | ||
build(:quote_check_feedback, quote_check: quote_check).attributes | ||
end | ||
|
||
response "201", "Retour téléversé" do | ||
schema "$ref" => "#/components/schemas/quote_check_feedback" | ||
|
||
# See https://github.com/rswag/rswag/issues/316 | ||
let(:Authorization) { basic_auth_header.fetch("Authorization") } # rubocop:disable RSpec/VariableName | ||
|
||
run_test! | ||
end | ||
|
||
response "422", "missing params" do | ||
schema "$ref" => "#/components/schemas/api_error" | ||
|
||
let(:quote_check_feedback) do | ||
build(:quote_check_feedback).attributes | ||
.except("validation_error_details_id") | ||
.merge("is_helpful" => nil) | ||
end | ||
|
||
let(:Authorization) { basic_auth_header.fetch("Authorization") } # rubocop:disable RSpec/VariableName | ||
|
||
run_test! | ||
end | ||
end | ||
end | ||
end |
72 changes: 72 additions & 0 deletions
72
spec/requests/api/v1/quote_check_validation_error_details_feedbacks_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
# spec/controllers/posts_controller_spec.rb | ||
require "rails_helper" | ||
|
||
RSpec.describe "/api/v1/quote_checks/:quote_check_id/error_details/:validation_error_detail_id/feedbacks" do | ||
let(:quote_check) { create(:quote_check, :invalid) } | ||
let(:validation_error_details_id) { quote_check.validation_error_details.first.fetch("id") } | ||
let(:quote_check_id) { quote_check.id } | ||
|
||
let(:json) { response.parsed_body } | ||
|
||
describe "POST /api/v1/quote_checks/:quote_check_id/error_details/:validation_error_detail_id/feedbacks" do | ||
let(:quote_check_feedback_params) do | ||
{ | ||
is_helpful: false, | ||
comment: "FAUX" | ||
} | ||
end | ||
|
||
# rubocop:disable RSpec/ExampleLength | ||
it "returns a successful response" do | ||
post api_v1_quote_check_validation_error_detail_feedbacks_url( | ||
quote_check_id: quote_check_id, | ||
validation_error_detail_id: validation_error_details_id | ||
), params: quote_check_feedback_params, | ||
headers: basic_auth_header | ||
expect(response).to be_successful | ||
end | ||
|
||
it "returns a created response" do | ||
post api_v1_quote_check_validation_error_detail_feedbacks_url( | ||
quote_check_id: quote_check_id, | ||
validation_error_detail_id: validation_error_details_id | ||
), params: quote_check_feedback_params, | ||
headers: basic_auth_header | ||
expect(response).to have_http_status(:created) | ||
end | ||
|
||
it "returns the QuoteCheckFeedback" do | ||
post api_v1_quote_check_validation_error_detail_feedbacks_url( | ||
quote_check_id: quote_check_id, | ||
validation_error_detail_id: validation_error_details_id | ||
), params: quote_check_feedback_params, | ||
headers: basic_auth_header | ||
expect(json.fetch("quote_check_id")).to eq(quote_check_id) | ||
end | ||
|
||
it "creates a QuoteCheckFeedback" do | ||
expect do | ||
post api_v1_quote_check_validation_error_detail_feedbacks_url( | ||
quote_check_id: quote_check_id, | ||
validation_error_detail_id: validation_error_details_id | ||
), params: quote_check_feedback_params, | ||
headers: basic_auth_header | ||
end.to change(QuoteCheckFeedback, :count).by(1) | ||
end | ||
|
||
context "with wrong error details id" do | ||
it "returns a not found response" do | ||
post api_v1_quote_check_validation_error_detail_feedbacks_url( | ||
quote_check_id: quote_check_id, | ||
validation_error_detail_id: "wrong" | ||
), | ||
params: quote_check_feedback_params, | ||
headers: basic_auth_header | ||
expect(response).to have_http_status(:not_found) | ||
end | ||
end | ||
# rubocop:enable RSpec/ExampleLength | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters