nabil-boag / angular-multimocks

Tools for managing mock data scenarios in AngularJS applications.
MIT License
35 stars 11 forks source link

Let scenarios be composable from other scenarios #29

Open edconolly opened 8 years ago

edconolly commented 8 years ago

It would be great to have scenarios not just be made up of resources but other scenarios as well.

Maybe something like

"emptyShoppingCart": [
    "extends": [
       "fooScenario",
       "barScenario"
    ]
    "cart/noItems.json"
  ],
chrisiconolly commented 8 years ago

This makes a lot of sense - what should happen if fooScenario and barScenario contain conflicting resources? eg: fooScenario contains quote/error.json and fooScenario contains quote/slowResponse.json

If we choose the pattern that resources declared later are used it also allows you to extend a single scenario and just overwrite files directly

"emptyShoppingCart": [
    "extends": [
       "fooScenario"
    ]
    "cart/noItems.json"
  ]
edconolly commented 8 years ago

It still doesn't get around the problem, since I can still state quote/fastResponse.json in my actual resource definitions also. Do we need a build time check?

chrisiconolly commented 8 years ago

You can use the same logic, the last conflicting mock in the definition is the one that gets used. So anything you explicitly declare will be used as a priority. Be interesting to see what Nabil thinks.

This feature however might mean the config of laying out mocks might have to go through a braking change to something more like

"userWithCreditHasEmptyCart": {
    "extends": [
      "someItems",
      "userHasCredit"
    ],
    "mocks": [
      "cart/empty.json"
    ]
  }
nabil-boag commented 8 years ago

I think this is a great feature request, and one that is the natural next step for mocking.

We should try to add this functionality without breaking backwards compatibility, but if we find an elegant solution that breaks backwards compatibility, we are still a small project so we should go for it. As @chrisiconolly said, this might be worth bumping the project up to v 1.0 for!