Http mock and persisting data

With the fixture adapter you could create new records and save them. By default the ember CLI http mock can receive a POST but just returns a status code. Is there a reason for this? What is the best practice for persisting data in a non server based test application?

You could change the mock to make it do whatever you want, it lives in /server/mocks/[model].js. It’s an Express server, so check out their docs on the api.

You could also try my project Mirage which helps you mock in the client, and was designed to make the kinds of things you’re talking about as simple as possible.

1 Like

one thing you can do is to return the data send to the mock-server with a random id. Thats not really persisted, but works for testing. Its important to require the body-parser to read the data.

module.exports = function(app) {
  var express   = require('express');
  var usersRouter = express.Router();
  
  usersRouter.post('/', function(req, res) {
    var body     = req.body;
    body.user.id = Math.round(Math.random() * 100);
   
    res.send(body);
  });

  app.use('/api/users', require('body-parser').json(), adsRouter);
};