{"id":18930050,"url":"https://github.com/labd/commercetools-node-mock","last_synced_at":"2026-01-02T16:17:17.310Z","repository":{"id":38223816,"uuid":"354759740","full_name":"labd/commercetools-node-mock","owner":"labd","description":"Mock for the commercetools rest api","archived":false,"fork":false,"pushed_at":"2025-04-07T20:28:38.000Z","size":3935,"stargazers_count":20,"open_issues_count":11,"forks_count":18,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-07T20:29:25.451Z","etag":null,"topics":["commercetools","testing"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/labd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-05T07:54:33.000Z","updated_at":"2025-04-07T20:28:40.000Z","dependencies_parsed_at":"2023-09-22T13:02:04.099Z","dependency_job_id":"e5e096a9-cf9b-4e95-a3fd-d0ba3db547e4","html_url":"https://github.com/labd/commercetools-node-mock","commit_stats":null,"previous_names":[],"tags_count":147,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-node-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-node-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-node-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-node-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/labd","download_url":"https://codeload.github.com/labd/commercetools-node-mock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249097896,"owners_count":21212372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["commercetools","testing"],"created_at":"2024-11-08T11:36:21.972Z","updated_at":"2026-01-02T16:17:17.280Z","avatar_url":"https://github.com/labd.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Commercetools Mocking library for Node\n\n[\u003cimg src=\"https://img.shields.io/npm/v/@labdigital/commercetools-mock\"\u003e](https://www.npmjs.com/package/@labdigital/commercetools-mock)\n[![codecov](https://codecov.io/gh/labd/commercetools-node-mock/branch/main/graph/badge.svg?token=muKkNunJ95)](https://codecov.io/gh/labd/commercetools-node-mock)\n\nThis library mocks the Commercetools rest API to ease testing of your typescript\ncodebases interacting with the commercetools api. It uses the same proven\napproach as our testing module in the\n[commercetools Python SDK](https://github.com/labd/commercetools-python-sdk/tree/main/src/commercetools/testing).\n\nSince version 2 of this library it is based on [msw](https://mswjs.io/) instead\nof nock. It is now therefore als recommended to manage the msw server yourself\nand use the `registerHandlers` method to register the handlers on this server.\n\nThis allows you to use the same server for mocking other API's as well.\n\n## Installation\n\n```bash\nyarn add --dev @labdigital/commercetools-mock\n```\n\n## Docker image\n\nThis codebase is also available as a docker image where it provides a runnable\nhttp server exposing the mocked endpoints. See\nhttps://hub.docker.com/r/labdigital/commercetools-mock-server\n\n## Example\n\n```typescript\nimport { CommercetoolsMock, getBaseResourceProperties } from '@labdigital/commercetools-mock'\nimport { setupServer } from 'msw/node'\n\nconst ctMock = new CommercetoolsMock({\n  apiHost: 'https://localhost',\n  authHost: 'https://localhost',\n  enableAuthentication: false,\n  validateCredentials: false,\n  defaultProjectKey: 'my-project',\n  silent: true,\n})\n\ndescribe('A module', () =\u003e {\n  const mswServer = setupServer()\n\n  beforeAll(() =\u003e {\n    mswServer.listen({ onUnhandledRequest: \"error\" })\n  })\n\n  beforeEach(() =\u003e {\n    ctMock.registerHandlers(mswServer)\n\n    ctMock.project().add('type', {\n      ...getBaseResourceProperties()\n      key: 'my-customt-type',\n      fieldDefinitions: [],\n    })\n  })\n\n  afterAll(() =\u003e {\n    mswServer.close()\n  })\n\n  afterEach(() =\u003e {\n    server.clearHandlers()\n    ctMock.clear()\n  })\n\n  test('my function', async () =\u003e {\n    ctMock.project().add('customer', customerFixture)\n\n    const res = await myFunction()\n\n    expect(res).toEqual(true)\n  })\n})\n```\n\n## Contributing\n\nThis codebases use [@changesets](https://github.com/changesets/changesets) for release and version management\n\n- Create a feature branch with new features / fixes (see [Adding a new service](#adding-a-service))\n- When your code changes are complete, add a changeset file to your feature branch using `pnpm changeset`\n- Create a PR to request your changes to be merged to main\n- After your PR is merged, GitHub actions will create a release PR or add your changeset to an existing release PR\n- When the release is ready merge the release branch. A new version will be released\n\n### Adding a new service {#adding-a-service}\n\nImplement the following:\n\n- New repository in src/repositories\n- New service in src/services\n- Add new service to src/ctMock.ts ctMock.\\_services\n- Add new service to src/storage.ts InMemoryStorage\n- Adjust src/types.ts RepositoryMap and possibly serviceTypes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabd%2Fcommercetools-node-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flabd%2Fcommercetools-node-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabd%2Fcommercetools-node-mock/lists"}