angular-multimocks icon indicating copy to clipboard operation
angular-multimocks copied to clipboard

Let scenarios be composable from other scenarios

Open edconolly opened this issue 9 years ago • 4 comments

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"
  ],

edconolly avatar Oct 29 '15 22:10 edconolly

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"
  ]

chrisiconolly avatar Oct 29 '15 22:10 chrisiconolly

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?

edconolly avatar Oct 30 '15 09:10 edconolly

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"
    ]
  }

chrisiconolly avatar Oct 30 '15 22:10 chrisiconolly

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!

nabil-boag avatar Nov 10 '15 10:11 nabil-boag