Skip to content

Commit b9e690d

Browse files
fix: Conditionally add ftrack-api-options (#217)
* Conditionally add api-options * Readable form * add test case
1 parent 911682d commit b9e690d

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

source/session.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,11 @@ export class Session<
663663
"ftrack-user": this.apiUser,
664664
"ftrack-Clienttoken": this.clientToken,
665665
"ftrack-pushtoken": pushToken,
666-
"ftrack-api-options": ensureSerializableResponse
667-
? "strict:1;denormalize:1"
668-
: undefined,
666+
...(ensureSerializableResponse
667+
? {
668+
"ftrack-api-options": "strict:1;denormalize:1",
669+
}
670+
: {}),
669671
...this.additionalHeaders,
670672
...additionalHeaders,
671673
} as HeadersInit,

test/session.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,31 @@ describe("Session", () => {
229229
return expect((await headers).get("X-Test-Header")).toEqual("test");
230230
});
231231

232+
it("Should allow api option header based on ensureSerializableResponse", async () => {
233+
const headers = new Promise<Headers>((resolve) => {
234+
server.use(
235+
http.post(
236+
"http://ftrack.test/api",
237+
(info) => {
238+
resolve(info.request.headers as any);
239+
return HttpResponse.json(getInitialSessionQuery());
240+
},
241+
{ once: true },
242+
),
243+
);
244+
});
245+
246+
new Session(
247+
credentials.serverUrl,
248+
credentials.apiUser,
249+
credentials.apiKey,
250+
{
251+
ensureSerializableResponse: false,
252+
},
253+
);
254+
return expect((await headers).get("ftrack-api-options")).toBeFalsy();
255+
});
256+
232257
it("Should allow creating a User", () => {
233258
const promise = session.create("User", {
234259
username: getTestUsername(),

0 commit comments

Comments
 (0)