From ee795d23d064c12c2f97821578674bbebdc71c5f Mon Sep 17 00:00:00 2001 From: Bernard Lambeau Date: Thu, 6 Jun 2024 13:22:37 +0200 Subject: [PATCH] Validate raw_output against the output schema, even if unstructured data. --- CHANGELOG.md | 5 +++++ lib/webspicy/tester/result/error_schema_met.rb | 7 +++++-- lib/webspicy/tester/result/output_schema_met.rb | 7 +++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec86b7e..95b4f67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,11 @@ conditions who want to execute a test case they have. Alternative to find_and_call. +* Bug fix: validate output schema against the raw output when output + is not "structured" (e.g. application/json) but pure text + (e.g. `text/plain`, `text/csv`). Otherwise using String(s | ... ) has + no effect. + ## 0.26.0 - 2023-06-23 * Upgrade runtime and devel dependencies, notably http (5.x) and diff --git a/lib/webspicy/tester/result/error_schema_met.rb b/lib/webspicy/tester/result/error_schema_met.rb index a1114d1..137f2fc 100644 --- a/lib/webspicy/tester/result/error_schema_met.rb +++ b/lib/webspicy/tester/result/error_schema_met.rb @@ -12,8 +12,11 @@ def must? end def call - return unless invocation.is_structured_output? - output = invocation.loaded_body + output = if invocation.is_structured_output? + invocation.loaded_body + else + invocation.raw_output + end service.error_schema.dress(output) rescue Finitio::TypeError => ex _! "Invalid error: #{ex.message}" diff --git a/lib/webspicy/tester/result/output_schema_met.rb b/lib/webspicy/tester/result/output_schema_met.rb index 87108dc..9b63232 100644 --- a/lib/webspicy/tester/result/output_schema_met.rb +++ b/lib/webspicy/tester/result/output_schema_met.rb @@ -12,8 +12,11 @@ def must? end def call - return unless invocation.is_structured_output? - output = invocation.loaded_body + output = if invocation.is_structured_output? + invocation.loaded_body + else + invocation.raw_output + end service.output_schema.dress(output) rescue Finitio::TypeError => ex _! "Invalid output: #{ex.message}"