Skip to content

Commit

Permalink
feat: Add ctMock().getHandlers()
Browse files Browse the repository at this point in the history
This allows us to use the handlers for one-time setup:

e.g.
```
const mswServer = setupServer(...ctMock.getHandlers());
```
  • Loading branch information
mvantellingen committed Jan 20, 2025
1 parent 2d3f6e9 commit 0212cb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-bats-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/commercetools-mock": patch
---

Add `ctMock().getHandlers()` to return all msw handlers for initial setup
9 changes: 7 additions & 2 deletions src/ctMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,13 @@ export class CommercetoolsMock {
// allows you to manage msw server yourself and register the handlers needed
// for commercetools-mock to work.
public registerHandlers(server: SetupServerApi) {
const handlers = this.getHandlers(server);
server.use(...handlers);
}

public getHandlers(server: SetupServerApi) {
const app = this.app;
server.use(
return [
http.post(`${this.options.authHost}/oauth/*`, async ({ request }) => {
const body = await request.text();
const url = new URL(request.url);
Expand Down Expand Up @@ -290,7 +295,7 @@ export class CommercetoolsMock {
headers: mapHeaderType(res.headers),
});
}),
);
];
}

public mswServer() {
Expand Down

0 comments on commit 0212cb4

Please sign in to comment.