简体   繁体   中英

Ember Octane - Mirage requestbody null

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});

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM