Skip to content

Commit

Permalink
fix: avoid adding _format to delete calls (#427)
Browse files Browse the repository at this point in the history
FHIR Specification doesn't say _format can be added to delete calls
The delete interaction removes an existing resource. The interaction is performed by an HTTP DELETE command as shown:

  DELETE [base]/[type]/[id]
The request body SHALL be empty.
  • Loading branch information
AmirthavalliG authored Feb 5, 2024
1 parent d6dd790 commit b2a40f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/sap/fhir/model/r4/lib/FHIRRequestor.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ sap.ui.define([
mParameters = merge(mParameters, this.oDefaultQueryParams);
}

if (!this._isFormatSupported(mParameters._format)) {
if (!this._isFormatSupported(mParameters._format) && sMethod !== HTTPMethod.DELETE) {
mParameters._format = "json";
}

Expand All @@ -486,7 +486,7 @@ sap.ui.define([
}
}.bind(this));

return "?" + aQuery.join("&");
return aQuery.length > 0 ? "?" + aQuery.join("&") : "";
};

/**
Expand Down
8 changes: 5 additions & 3 deletions test/qunit/model/FHIRModel.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ sap.ui.define([
"sap/fhir/model/r4/SubmitMode",
"sap/fhir/model/r4/lib/FHIRBundleType",
"sap/fhir/model/r4/lib/FHIRBundleRequest",
"sap/base/util/deepEqual"
], function(jQuery, TestUtils, FHIRFilter, FHIRFilterType, FHIRFilterOperator, FHIRFilterProcessor, OperationMode, RequestHandle, Sliceable, FilterOperator, Filter, SubmitMode, FHIRBundleType, FHIRBundleRequest, deepEqual) {
"sap/base/util/deepEqual",
"sap/fhir/model/r4/lib/HTTPMethod"
], function (jQuery, TestUtils, FHIRFilter, FHIRFilterType, FHIRFilterOperator, FHIRFilterProcessor, OperationMode, RequestHandle, Sliceable, FilterOperator, Filter, SubmitMode, FHIRBundleType, FHIRBundleRequest, deepEqual, HTTPMethod) {

"use strict";

Expand Down Expand Up @@ -163,13 +164,14 @@ sap.ui.define([
}.bind(this), new Error("A depth of 3 is not supported for simple filtering, please reduce it to a maximum of 2"));
});

QUnit.test("check that format request parameter", function(assert) {
QUnit.test("check that format request parameter", function (assert) {
assert.strictEqual(this.oFhirModel1.oRequestor._buildQueryParameters(), "");
assert.strictEqual(this.oFhirModel1.oRequestor._buildQueryParameters({ _format: "xml" }, this.oFhirModel1.getBindingInfo("/Patient")), "?_format=json&_total=accurate");
assert.strictEqual(this.oFhirModel1.oRequestor._buildQueryParameters({ _format: "xml" }, this.oFhirModel1.getBindingInfo("/Patient/123")), "?_format=json");
assert.strictEqual(this.oFhirModel1.oRequestor._buildQueryParameters({ _format: "application/json" }, this.oFhirModel1.getBindingInfo("/Patient/123")), "?_format=application/json");
assert.strictEqual(this.oFhirModel1.oRequestor._buildQueryParameters({ _format: "application/fhir+json" }, this.oFhirModel1.getBindingInfo("/Patient/123")), "?_format=application/fhir%2Bjson");
assert.strictEqual(this.oFhirModel1.oRequestor._buildQueryParameters({ _format: "json" }, this.oFhirModel1.getBindingInfo("/Patient/123")), "?_format=json");
assert.strictEqual(this.oFhirModel1.oRequestor._buildQueryParameters({}, this.oFhirModel1.getBindingInfo("/Patient/123"), HTTPMethod.DELETE), "");
});

QUnit.test("check listbinding getcontexts in relative case for different depths of paths when resource gets newly created", function(assert) {
Expand Down

0 comments on commit b2a40f2

Please sign in to comment.