简体   繁体   English

Ember Octane - Mirage 请求体 null

[英]Ember Octane - Mirage requestbody null

I am newbie on ember.js, trying to do some tests with mirage.我是 ember.js 的新手,试图用 mirage 做一些测试。 Only certain fields of model come true, but the others come as null.只有 model 的某些字段实现,但其他字段为 null。 As I am a newbie, I am not sure if the reason is about these lines由于我是新手,我不确定原因是否与这些线路有关

Account.js 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海市蜃楼 - 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.您将需要从this.post路由返回一些内容以获取包含数据的响应。 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.如果您使用 JSON:API 可能需要稍微不同地解析请求,因此有关如何配置模型和适配器的更多信息将更容易回答这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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