diff --git a/affiliations-tools/tests.hurl b/affiliations-tools/tests.hurl index 219e54c..e21845a 100644 --- a/affiliations-tools/tests.hurl +++ b/affiliations-tools/tests.hurl @@ -442,6 +442,14 @@ ``` HTTP 200 +``` +Année;Adresse;RNSR +2015;CNRS UMR AMAP MONTPELLIER FRA;200317641S +2015;IRD UMR AMAP MONTPELLIER FRA;200317641S +2015;University of Bordeaux, IMS, CNRS UMR5218, Talence, F-33405, France;200711887V +2015;CENBG, CNRS/IN2P3, Chemin du Solarium B. P. 120, Gradignan, F-33175, France; +``` + POST https://affiliations-tools.services.istex.fr/v1/rnsr/conditor diff --git a/bin/generate-example-tests.mjs b/bin/generate-example-tests.mjs index c86dda8..cd3e9c5 100755 --- a/bin/generate-example-tests.mjs +++ b/bin/generate-example-tests.mjs @@ -10,6 +10,10 @@ /** @param {string} s */ const isInteger = (s) => Number.isInteger(Number(s)); +const isText = request => request.headers.has("Content-Type") && + request.headers.get("Content-Type").startsWith("text/"); + +const wrapText = text => "```\n" + text + "```\n\n"; /** * Converts a REST client request object into a Hurl request. @@ -21,10 +25,9 @@ let requestString = `${request.method} ${request.url}\n`; request.headers.forEach((value, key) => requestString += `${key}: ${value}\n`); - const isCSV = request.headers.has("Content-Type") && - request.headers.get("Content-Type") === "text/csv"; - if (isCSV) { - requestString += "```\n" + request.body + "```\n\n"; + if (isText(request)) { + // requestString += "```\n" + request.body + "```\n\n"; + requestString += wrapText(request.body); } else { requestString += request.body + '\n'; } @@ -32,7 +35,9 @@ try { const { response } = await request.request(); - const responseString = "HTTP 200\n" + (isCSV ? "" : response.getBody()); + const responseString = "HTTP 200\n" + (isText(request) + ? wrapText(response.getBody()) + : response.getBody()); return requestString + responseString + "\n"; } catch (error) {