Ember Octane - Mirage requestbody null

166 views Asked by At

I am newbie on ember.js, trying to do some tests with mirage. Only certain fields of model come true, but the others come as null. As I am a newbie, I am not sure if the reason is about these lines

Account.js

const accountId = this.args.account.id;
var data = this.store.createRecord('subscription', 
{
  id:1,
  accountId: accountId,
  startDate: Date.now(),
  endDate: Date.now()
});
data.save();

Mirage - Config.js

this.post('/subscriptions', (schema, request) => {
    let requestBody = JSON.parse(request.requestBody);
    schema.subscriptions.push(requestBody);
  }, {timing: 2000});
1

There are 1 answers

0
jrjohnson On

You will need to return something from the this.post route to get a response with data in it. There are some examples in the documentation that may provide more detail for you.

In your example this may look like:

this.post('/subscriptions', (schema, request) => {
    let requestBody = JSON.parse(request.requestBody);
    return schema.subscriptions.create(requestBody);
  }, {timing: 2000});

However this is going to depend a lot on how your application is configured. If you're using JSON:API it may require parsing the request slightly differently so more information about how your models and adapters are configured would make it easier to answer this question.