adopted-ember-addons/ember-data-factory-guy

mock() doesn't use the supplied status

ryedeer opened this issue · 5 comments

Hello! I've found that mock() doesn't use the status value provided to it and just always sets 200. Here's a small test to illustrate it:

  test("mockAny status", function(assert) {
    let mockAny = mock({url: '/meep-meep', status: 404});
    assert.equal(mockAny.status, '404'); // fails because the status is '200'
  });

It looks that the reason is simple: the status value just isn't given to the mock constructor here: https://github.com/danielspaniel/ember-data-factory-guy/blob/master/addon/mocks/exposed-request-functions.js#L33

your right @ryedeer .. that was silly of me. want to PR that ?

I think I can do it. Also, if we talk about a PR, I think it would be nice to add an ability to set custom response headers. As I can see, now mock() just sets empty response headers, so I can't define the proper content type for the response.

actually @ryedeer .. i forgot also that the mock is a child of mockResponse which has most of the methods that the other mocks have like:

addResponseHeaders()
fails()
succeeds()

so, you can make the =>

mock({url}).fails({status: 404})
mock({url}).fails() // default to status 500 
mock({url}).addResponseHeaders({token: blah})

you get the idea
as i recall .. that is why i did not set the status up front in the options hash of mock() .. i figured it did not matter .. but the documentation was not clear .. which is my fault

Thank you for making it clear! fails(), succeeds(), and addResponseHeaders() work just fine. However, I couldn't find any mention of addResponseHeaders() in the documentation -- I think it's worth adding!

100% definitely Oleg .. I will add that