Skip to content

Commit

Permalink
tests: add tests for middleware extension
Browse files Browse the repository at this point in the history
  • Loading branch information
fdionisi committed Jun 7, 2024
1 parent 6d0ef78 commit 09efa91
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion tests/edc-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { EdcConnectorClient, EdcConnectorClientContext } from "../src";
import {
EdcConnectorClient,
EdcConnectorClientContext,
EdcController,
} from "../src";
import { Addresses } from "../src";

describe("EdcConnectorClient", () => {
Expand Down Expand Up @@ -39,4 +43,38 @@ describe("EdcConnectorClient", () => {
expect(context.control).toBe(addresses.control);
});
});

describe("edcClient.Builder.use", () => {
interface ActiveResponse {
active: boolean;
}

class ResourcesCountController extends EdcController {
async active(): Promise<ActiveResponse> {
return {
active: true,
};
}
}

class WooooController extends EdcController {
async woooo(): Promise<ActiveResponse> {
return {
active: false,
};
}
}

it("allows to extend the clients through middlewares", async () => {
const client = new EdcConnectorClient.Builder()
.use("resourcesCount", ResourcesCountController)
.use("woooo", WooooController)
.build();

await expect(client.resourcesCount.active()).resolves.toEqual({
active: true,
});
await expect(client.woooo.woooo()).resolves.toEqual({ active: false });
});
});
});

0 comments on commit 09efa91

Please sign in to comment.