dimanche 23 avril 2017

Object mock using data factory guy addon

I am new to Embebr js and using ember-data-factory addon to mock ajax response however having trouble mocking below response.

 {
      "employee/profile": {
        "id": 60799,
        "gender": "Male",
        "fname": "Mick",
        "lname": "Hussey",
        "addresses": [
          "50345"      
        ]   
      },
      "employee/addresses": [
        {
          "id": "50345",
          "addressState": "GA",
          "zip": "30004"  
        }     
      ] 

    } 

To achieve this i have created both profile and address model in tests/factories/ directory. employee/profile Model

import FactoryGuy from 'ember-data-factory-guy';

FactoryGuy.define('employee/profile', {
  default: {    
    id: 60799,
    gender: 'Male',
    fname: 'Mick',
    lname: 'Hussey',
    addresses:  FactoryGuy.hasMany('employee/addresses')  
  } 
});

Address Model:

import FactoryGuy from 'ember-data-factory-guy';

FactoryGuy.define('employee/address', {
  default: {   
    id: '50345',
    addressState: 'GA',
    zip: '300014'   
    customer: FactoryGuy.belongsTo('employee/profile'),

  }
});

And when i try to build profile object using below code snippet, all the fields except addresses is getting populated.

let profile = this.build('customer/profile');

can anybody please help me understand whats going wrong.

Thanks Gautam




Aucun commentaire:

Enregistrer un commentaire