lundi 14 mars 2016

Cli mirage routes not working in acceptace test

I was trying acceptance test for login page, using cli mirage as mock server. Routes defined in a mirage works fine, when accessing it from application. But when trying it in ember test it returns

Mirage: Your Ember app tried to POST 'http://localhost:4200/tests?module=Acceptance | login', but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?

Acceptance Test

test('visiting /login', function(assert) {
  server.create('login', { username: 'xxx@test.com', password: 'password' });
  visit('/login');

  fillIn('input[placeholder="Email"]', 'xxx@test.com');
  fillIn('input[placeholder="Password"]', 'password');
  click('button.btn-primary');

  andThen(function() {
    assert.equal(currentURL(), '/route');
  });
});

Mirage/config

import Mirage from 'ember-cli-mirage';
export default function() {
this.post('/token', function(db, request) {
  var params = formEncodedToJson(request.requestBody);

  if(params.username === "xxx@test.com && params.password === "password") {
    return {
      "auth":"Pass$Word",
      "token_type":"bearer"
    };
  } else{
    var body = { errors: 'Email or password is invalid' };
    return new Mirage.Response(401, {}, body);
  }
});

How to rectify this issue? someone help me please.

Aucun commentaire:

Enregistrer un commentaire