ember.js - serializer in unit test doesn't process json -


the serializer in unit test not processing json @ all, works expected in application. yeah, wrote afterwards, question - why it's not working? tried create in place, inherit restserializer, create models in place, none of worked.

maybe can give clue?

update looks begins in

 isprimarytype: function (store, typename, primarytypeclass) {     var typeclass = store.modelfor(typename);     return typeclass.modelname === primarytypeclass.modelname;   }, 

last string returns false, because of primarytypeclass.modelname undefined

serializer unit test

import ds 'ember-data'; import { moduleformodel, test } 'ember-qunit'; import setupstore 'app/tests/helpers/setup-store'; import profile 'app/models/profile'; import email 'app/models/email'; import address 'app/models/address'; import profileserializer 'app/serializers/profile';   var env;  moduleformodel('profile', 'unit | serializer | profile', {   needs: ['serializer:profile', 'serializer:email', 'serializer:address', 'model:contactable', 'model:email', 'model:address'],    beforeeach: function () {     env = setupstore({       profile: profile,       email: email,       address: address     });     env.registry.register('serializer:profile', profileserializer);     env.profileserializer = env.container.lookup('serializer:profile');   },    teardown: function() {     ember.run(env.store, 'destroy');   } });  test('it converts embedded records attributes', function(assert) {   // expect(3);   let payload = {     id: 1,     first_name: "carlo",     last_name: "schuppe",     company: "metz-witting",     birthday: "01-10-1985",     photo: null,     emails: [{address: "foo@bar.baz", id: 1, type: "main"}],     addresses: [{city: "brooklyn", id: 1,  type: "main"}]   },   parsed = {     "data":     {       "id":"1",       "type":"profile",       "attributes": { "firstname":"carlo","lastname":"schuppe","company":"metz-witting","birthday":"01-10-1985","photo":null },       "relationships": {         "emails": { "data": [{"id":"1","type":"email"}] },         "addresses": { "data": [{"id":"1","type":"address"}] }       }     },     "included":[       {"id":"1","type":"email","attributes":{"address":"foo@bar.baz", "kind": "main"},"relationships":{"contactable":{"data":{"type":"profile","id":"1"}}}},       {"id":"1","type":"address","attributes":{"city":"brooklyn", "kind": "main"},"relationships":{"contactable":{"data":{"type":"profile","id":"1"}}}}     ]   },   find, update, findallrecordsjson;    ember.run(function() {     find = env.profileserializer.normalizeresponse(env.store, profile, payload, '1', 'findrecord');     // update = env.profileserializer.normalizeresponse(env.store, profile, payload, '1', 'updaterecord');     // findallrecordsjson = env.profileserializer.normalizeresponse(env.store, profile, payload, '1', 'findall');   });    assert.deepequal(find, parsed);   // assert.deepequal(update, parsed);   // assert.deepequal(findallrecordsjson, parsed); }); 

setup_store.js

import ember 'ember'; import ds 'ember-data'; // import activemodeladapter 'active-model-adapter'; // import activemodelserializer 'active-model-adapter/active-model-serializer';  export default function setupstore(options) {   var container, registry;   var env = {};   options = options || {};    if (ember.registry) {     registry = env.registry = new ember.registry();     container = env.container = registry.container();   } else {     container = env.container = new ember.container();     registry = env.registry = container;   }    env.replacecontainernormalize = function replacecontainernormalize(fn) {     if (env.registry) {       env.registry.normalize = fn;     } else {       env.container.normalize = fn;     }   };    var adapter = env.adapter = (options.adapter || '-default');   delete options.adapter;    if (typeof adapter !== 'string') {     env.registry.register('adapter:-ember-data-test-custom', adapter);     adapter = '-ember-data-test-custom';   }    (var prop in options) {     registry.register('model:' + ember.string.dasherize(prop), options[prop]);   }    registry.register('store:main', ds.store.extend({     adapter: adapter   }));    registry.optionsfortype('serializer', { singleton: false });   registry.optionsfortype('adapter', { singleton: false });   registry.register('adapter:-default', ds.adapter);    registry.register('serializer:-default', ds.jsonserializer);   registry.register('serializer:-rest', ds.restserializer);   registry.register('serializer:-rest-new', ds.restserializer.extend({ isnewserializerapi: true }));    registry.register('adapter:-active-model', ds.activemodeladapter);   registry.register('serializer:-active-model', ds.activemodelserializer.extend({isnewserializerapi: true}));    registry.register('adapter:-rest', ds.restadapter);    registry.injection('serializer', 'store', 'store:main');   registry.register('transform:string', ds.stringtransform);   registry.register('transform:number', ds.numbertransform);   registry.register('transform:date', ds.datetransform);   registry.register('transform:main', ds.transform);    env.serializer = container.lookup('serializer:-default');   env.restserializer = container.lookup('serializer:-rest');   env.restnewserializer = container.lookup('serializer:-rest-new');   env.store = container.lookup('store:main');   env.adapter = env.store.get('defaultadapter');    env.registry.register('serializer:-active-model', ds.activemodelserializer.extend({isnewserializerapi: true}));   env.registry.register('adapter:-active-model', ds.activemodeladapter);   env.registry.register('serializer:application', ds.activemodelserializer.extend({isnewserializerapi: true}));     return env; } 

output

{   "data": null,   "included": [] } 


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -