|
1 | 1 | import { |
2 | | - ServerClient, createClient, |
| 2 | + ServerClient, createClient, HTTPAuthType, |
3 | 3 | } from "../index"; |
4 | 4 | import fetchMock from "jest-fetch-mock"; |
5 | 5 | import { ClientCredentials } from "simple-oauth2"; |
@@ -517,6 +517,66 @@ describe("ServerClient", () => { |
517 | 517 | }), |
518 | 518 | ); |
519 | 519 | }); |
| 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 | + }); |
520 | 580 | }); |
521 | 581 |
|
522 | 582 | describe("OAuth Token Handling", () => { |
@@ -668,5 +728,4 @@ describe("ServerClient", () => { |
668 | 728 | })).rejects.toThrow("External user ID is required"); |
669 | 729 | }); |
670 | 730 | }); |
671 | | - |
672 | 731 | }); |
0 commit comments