Skip to content

Commit

Permalink
fix: Conditionally add ftrack-api-options (#217)
Browse files Browse the repository at this point in the history
* Conditionally add api-options

* Readable form

* add test case
  • Loading branch information
swetapadmanabhan authored Mar 7, 2024
1 parent 911682d commit b9e690d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,11 @@ export class Session<
"ftrack-user": this.apiUser,
"ftrack-Clienttoken": this.clientToken,
"ftrack-pushtoken": pushToken,
"ftrack-api-options": ensureSerializableResponse
? "strict:1;denormalize:1"
: undefined,
...(ensureSerializableResponse
? {
"ftrack-api-options": "strict:1;denormalize:1",
}
: {}),
...this.additionalHeaders,
...additionalHeaders,
} as HeadersInit,
Expand Down
25 changes: 25 additions & 0 deletions test/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,31 @@ describe("Session", () => {
return expect((await headers).get("X-Test-Header")).toEqual("test");
});

it("Should allow api option header based on ensureSerializableResponse", async () => {
const headers = new Promise<Headers>((resolve) => {
server.use(
http.post(
"http://ftrack.test/api",
(info) => {
resolve(info.request.headers as any);
return HttpResponse.json(getInitialSessionQuery());
},
{ once: true },
),
);
});

new Session(
credentials.serverUrl,
credentials.apiUser,
credentials.apiKey,
{
ensureSerializableResponse: false,
},
);
return expect((await headers).get("ftrack-api-options")).toBeFalsy();
});

it("Should allow creating a User", () => {
const promise = session.create("User", {
username: getTestUsername(),
Expand Down

0 comments on commit b9e690d

Please sign in to comment.