Skip to content

commercetools/test-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

commercetools Test Data 🤖

✨ Monorepository with test data models for commercetools platform entities 🛠

Latest release GitHub license

This repository contains data models within the commercetools platform ecosystem.

In time, we will continue to implement and open source test data models. If you are interested or missing a specific data model, feel free to open a feature request or try to contribute to the repository.

Models are defined in the models/* workspace and are grouped by domain in different packages.

All models are built using the core package, which contains the necessary methods to implement and work with models. The core package is very much agnostic of the commercetools platform domain, so you can potentially use it to build your own models for other domains.

To know more about how to work and build data models, check out the documentation of the core package.

Usage

Using models is pretty straightforward. You import the package and build the model, which returns the data in the requested shape.

For example, assuming we have an Author model from a stories package:

import type { TAuthor } from '@commercetools-test-data/stories';

import { Author } from '@commercetools-test-data/stories';

const author1 = Author.random().firstName('John').buildGraphql<TAuthor>();
const author2 = Author.random().firstName('Rebecca').buildGraphql<TAuthor>();

Local Development with Linked Packages

When developing with multiple repositories, you may need to link packages locally to ensure your application uses the latest local changes without waiting for a package to be published. Below is a general approach to achieve this:

Steps to Link a Local Package

  1. Clone and Set Up the test-data Repository:

    • Ensure that the test-data repository you want to link is cloned locally and properly set up.
      cd path-to-test-data-repo
      pnpm install
  2. Update the Application's package.json:

    • In your application’s package.json, replace the dependency version with the relative path to the local package directory. For example:
      {
        "dependencies": {
          "@example/package-name": "<path-to-test-data-package>",
          "@commercetools-test-data/commons": "../../../test-data/models/commons"
        }
      }
  3. Install Dependencies:

    • Run the following commands to ensure your application is using the local version of the package:
      cd path-to-application-repo
      pnpm install
  4. Verify the Link:

    • Ensure that the package is correctly linked by inspecting the node_modules directory in your application repository. The package should point to your local build instead of fetching from a remote registry.
  5. Development Workflow:

    • During development, make changes in the test-data repository, rebuild the package using pnpm install in test-data repository, and re-run your application to see the changes reflect immediately.
    • Remember to revert the package.json changes before committing or pushing to a remote repository unless those changes are intended to be shared.

Important Notes

  • This approach is ideal for local development and testing. It ensures that your application runs with the latest package changes without the need to publish the package.
  • Make sure to revert or manage these changes appropriately when switching between local development and production environments.

Contribution

Presets Folder

For organization & ownership purposes, Pangolin & FCT house their presets under their respective folders (e.g. change-history-data, sample-data-fashion, sample-data-b2c-lifestyle). These should not be altered by an external team; however, if modifications occur for any reason, a corresponding team review is mandatory.

FAQ

whose review is mandatory for creating PR?

For pull requests concerning your team's specific presets, only your team's approval is required. If modifications are made to the models, inviting representatives from other teams for review is mandatory.

Can I simply copy/paste existing test model from other repository (eg: mc-frontend) to test-data?

Avoid directly copying and pasting from other repository models, as it may complicate cleanup efforts. While specific sections like generator fields and portions of specs may be copied over as is, be mindful that the overall structure and composition may differ significantly from your current setup.

Is there a easy way to know which models are already available?

No, there is no overarching inventory page at this time that outlines each package with its corresponding models. Each package contains the draft & final models that are grouped/organized by their representations as outlined in the docs. Take cartDiscounts#representations for example. If you’d like to review what has been created to date for underlying representations, you can just drill to the main index of that package.

How do I test a new model (e.g, with my MC component spec) when I create?

Unfortunately, that part does become a bit more complex. Copy and pasting it into the node_modules folder is one option. Another trick that we typically do is to add the new models locally in a separate file, make the call to it, then address any tweaks necessary.

What is the procedure after merging the PR?

For merged pull requests, there is no set schedule for releasing version packages (VP). To date it has simply depended on the traffic and urgency at that point in time. If you need a version released quickly, you are more than welcome to ping the #test-data-migration channel to see if there are any objections to doing so. Once the VP is released, it is immediately accessible. You have the option to either wait for dependency updates to process (e.g update all test-data packages to v6.10.0), or updating them manually.