{"action":"created","issue":{"url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/845","repository_url":"https://api.github.com/repos/samselikoff/ember-cli-mirage","labels_url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/845/labels{/name}","comments_url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/845/comments","events_url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/845/events","html_url":"https://github.com/samselikoff/ember-cli-mirage/issues/845","id":172532013,"number":845,"title":"Mechanism for per-test request assertions","user":{"login":"aquamme","id":3794475,"avatar_url":"https://avatars.githubusercontent.com/u/3794475?v=3","gravatar_id":"","url":"https://api.github.com/users/aquamme","html_url":"https://github.com/aquamme","followers_url":"https://api.github.com/users/aquamme/followers","following_url":"https://api.github.com/users/aquamme/following{/other_user}","gists_url":"https://api.github.com/users/aquamme/gists{/gist_id}","starred_url":"https://api.github.com/users/aquamme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aquamme/subscriptions","organizations_url":"https://api.github.com/users/aquamme/orgs","repos_url":"https://api.github.com/users/aquamme/repos","events_url":"https://api.github.com/users/aquamme/events{/privacy}","received_events_url":"https://api.github.com/users/aquamme/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-08-22T19:18:30Z","updated_at":"2016-09-02T04:22:58Z","closed_at":null,"body":"First off, thanks for the nice addon @samselikoff.\r\n\r\nIn acceptance tests, I oftentimes want to assert that my app made a request to the right endpoint with the right parameters. This can be accomplished by overriding request handlers in the test, like so:\r\n\r\n```javascript\r\ntest('Item should be hidden when the hide button is selected', function (assert) {\r\n  let item = server.create('item');\r\n  server.put('/items/:id', (schema, request) => {\r\n    assert.equal(request.params.id, item.id);\r\n    // perform the usual logic for this endpoint, then...\r\n    return item;\r\n  });\r\n\r\n  // test\r\n  visit(...);\r\n});\r\n```\r\nThis pattern works, but it entails duplicating whatever logic you may have in the request handler you overrode.\r\n\r\nTo solve this problem, I propose adding a hook that lets you examine the parameters passed to mirage before the request handler is invoked. Something like:\r\n\r\n```javascript\r\n  server.beforePut('/items/:id', request => {\r\n    assert.equal(request.items.id, expectedItemId);\r\n  });\r\n```\r\nBy default, the `beforeVERB` hooks would be NOOPs.\r\nAny return value would be discarded.\r\nAll `beforeVERB` hooks would be reset to their default NOOP between tests.\r\n\r\nI'm glad to do the work to add the feature, but wanted to discuss the idea and the potential API first."},"comment":{"url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/comments/244279933","html_url":"https://github.com/samselikoff/ember-cli-mirage/issues/845#issuecomment-244279933","issue_url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/845","id":244279933,"user":{"login":"samselikoff","id":2922250,"avatar_url":"https://avatars.githubusercontent.com/u/2922250?v=3","gravatar_id":"","url":"https://api.github.com/users/samselikoff","html_url":"https://github.com/samselikoff","followers_url":"https://api.github.com/users/samselikoff/followers","following_url":"https://api.github.com/users/samselikoff/following{/other_user}","gists_url":"https://api.github.com/users/samselikoff/gists{/gist_id}","starred_url":"https://api.github.com/users/samselikoff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samselikoff/subscriptions","organizations_url":"https://api.github.com/users/samselikoff/orgs","repos_url":"https://api.github.com/users/samselikoff/repos","events_url":"https://api.github.com/users/samselikoff/events{/privacy}","received_events_url":"https://api.github.com/users/samselikoff/received_events","type":"User","site_admin":false},"created_at":"2016-09-02T04:22:58Z","updated_at":"2016-09-02T04:22:58Z","body":"I think order should matter, I don't think `server.to('/posts')` would ever make sense. Perhaps we could add an api if we wanted to check for any verb. Some options:\r\n\r\n```\r\nserver.received().to('/posts')\r\nserver.received('any').to('/posts')\r\nserver.receivedAny.to('/posts');\r\nserver.receivedRequest.to('/posts');\r\n```"}}
{"actor":{"display_login":"samselikoff"}}