basicallydan / interfake

:computer: Fake APIs for prototypes & automated tests.
Other
805 stars 39 forks source link

[in progress] simple regexp support for json specified endpoints #38

Closed javoire closed 9 years ago

javoire commented 9 years ago

Hey, this one is more of a feature discussion than a real PR at the moment. So I realized I needed regexp endpoints and I was using the JSON method, and couldn't find any support for regexps this way (only the JS method?), so I did this really rough solution to be able to do that. And my JSON would look like this

[
  {
    "request": {
      "url": "regexp=\/some\/v0\/endpoint/(.*)",
      "method": "get"
    },
    "response": {
      "code": 200,
      "body": {}
    }
  }
]

This is probably in the completely wrong place. Also it should probably be in the form a property e.g. regexp: true than a prefix. Thoughts?

basicallydan commented 9 years ago

@javoire, I must admit when I was doing regex support I hadn't even considered the people who use JSON to specify endpoints. I'm very ashamed, but I'm glad you've taken it on. Thank you for opening this up for discussion! :)

It looks like a sensible implementation, but as you suggested I think an object property would be better than a prefix, mostly because the simplest form, e.g. regexp=something, would actually be a valid path for a real URL. In the unlikely case that someone would want to use that (you never know!) let's avoid that.

How about this:

[
  {
    "request": {
      "url": {
            "pattern": "\/some\/v0\/endpoint/(.*)",
            "regexp": true
      },
      "method": "get"
    },
    "response": {
      "code": 200,
      "body": {}
    }
  }
]

Then rather than util.isString it could be util.isObject, and we can open up further flexibility/descriptiveness in the future for URLs.

Finally - and I hate to be a pedant - but a test for this would probably be good too. You could copy the expectations from the fluent tests, rewrite the setup and put it in the javascript tests.

What do you think?

javoire commented 9 years ago

Yeah I really like the JSON method cause I mock multiple backends and I can easily fire them all up from command line. Your suggestion seems like a good solution, I'll take a look at it.

basicallydan commented 9 years ago

Cool, thanks @javoire!

basicallydan commented 9 years ago

Hey @javoire it looks like you never got around to this so I'm gonna pick it up if you don't mind :) I'm feeling particularly productive today!

EDIT: Let me know if this is a problem!

javoire commented 9 years ago

True, never got around to it unfortunately (yet!) :P but yeah cool that you're having a go at it :+1:

basicallydan commented 9 years ago

It's done! :) On 3 Aug 2015 18:26, "Jonatan Dahl" notifications@github.com wrote:

True, never got around to it unfortunately (yet!) :P but yeah cool that you're having a go at it [image: :+1:]

— Reply to this email directly or view it on GitHub https://github.com/basicallydan/interfake/pull/38#issuecomment-127175623 .

javoire commented 9 years ago

awesome!