Skip to content

Commit d4a8394

Browse files
committed
Improving tests
1 parent ce22436 commit d4a8394

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

packages/sdk/src/server/__tests__/server.test.ts

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
ServerClient, createClient,
2+
ServerClient, createClient, HTTPAuthType,
33
} from "../index";
44
import fetchMock from "jest-fetch-mock";
55
import { ClientCredentials } from "simple-oauth2";
@@ -517,6 +517,66 @@ describe("ServerClient", () => {
517517
}),
518518
);
519519
});
520+
521+
it("should invoke a workflow with OAuth auth type", async () => {
522+
fetchMock.mockResponseOnce(
523+
JSON.stringify({
524+
result: "workflow-response",
525+
}),
526+
{
527+
headers: {
528+
"Content-Type": "application/json",
529+
},
530+
},
531+
);
532+
533+
const result = await client.invokeWorkflow("https://example.com/workflow", {}, HTTPAuthType.OAuth);
534+
535+
expect(result).toEqual({
536+
result: "workflow-response",
537+
});
538+
539+
expect(fetchMock).toHaveBeenCalledWith(
540+
"https://example.com/workflow",
541+
expect.objectContaining({
542+
headers: expect.objectContaining({
543+
"Authorization": "Bearer mocked-oauth-token",
544+
}),
545+
}),
546+
);
547+
});
548+
549+
it("should invoke a workflow with static bearer auth type", async () => {
550+
fetchMock.mockResponseOnce(
551+
JSON.stringify({
552+
result: "workflow-response",
553+
}),
554+
{
555+
headers: {
556+
"Content-Type": "application/json",
557+
},
558+
},
559+
);
560+
561+
const result = await client.invokeWorkflow("https://example.com/workflow", {
562+
headers: {
563+
"Authorization": "Bearer static-token",
564+
},
565+
}, HTTPAuthType.StaticBearer);
566+
567+
expect(result).toEqual({
568+
result: "workflow-response",
569+
});
570+
571+
expect(fetchMock).toHaveBeenCalledWith(
572+
"https://example.com/workflow",
573+
expect.objectContaining({
574+
headers: expect.objectContaining({
575+
"Authorization": "Bearer static-token",
576+
}),
577+
}),
578+
);
579+
});
520580
});
521581

522582
describe("OAuth Token Handling", () => {
@@ -668,5 +728,4 @@ describe("ServerClient", () => {
668728
})).rejects.toThrow("External user ID is required");
669729
});
670730
});
671-
672731
});

0 commit comments

Comments
 (0)