烬。在seralizer上测试序列化方法

时间:2016-07-15 15:48:18

标签: testing ember.js ember-cli serializer

我在为序列化程序编写测试时遇到了一些麻烦。我不知道如何创建'record'或'snapshot'来执行“serializer.serialize(trade._createSnapshot())”。 这是我走了多远。救命! :)

import {expect} from 'chai';
import {describeModule, it} from 'ember-mocha';
import {describe} from 'mocha';
import DS from 'ember-data';
import startApp from 'appG/tests/helpers/start-app';


describeModule(
  'serializer:trade',
  'Unit | Serializer | trade ',
  {
   needs: ['model:trade', 'model:offer']
  },
 function() {
   describe('#serialize', function(){

  let offer = this.store.createRecord('offer', {
    condition:                'good',
    expiresAt:                new Date('4/13/16'),
  });

  let trade = this.store.createRecord('trade', {
    firstName:    "Cats",
    lastName:     "Meow",
    streetName1:  "123 street",
    streetName2:  "apt 503",
    city:         "boston",
    state:        "ma",
    zipcode:      "02210",
    telephone:    "1231231234",
    email:        "meow@cats.com",
    offer: offer
  });


  it ('turns the data to what the api needs', function() {
    let serializer = this.subject();
    let serializeJson = serializer.serialize(trade._createSnapshot());

    expect(serializeJson).to.eql(
      {
        "cart": [
          {
            "product_id": "1",
            "condition": "good"
          }
        ],
        "payment_information": {
          "first_name": "Cats",
          "last_name": "Meow",
          "street_name1": "123 street",
          "street_name2": "apt 503",
          "city": "Chicago",
          "state": "ma",
          "zipcode": "02210",
          "telephone": '9999999'
        },
        "shipping_information": {
          "first_name": "Cats",
          "last_name": "Meow",
          "street_name1": "123 street",
          "street_name2": "apt 101",
          "city": "Chicago",
          "state": "ma",
          "zipcode": "02210"
        },
        "email": "meow@cats.com",
      })
  })
 })
}
)

0 个答案:

没有答案