Robust framework-agnostic in-memory data store.
js-data robust framework-agnostic in-memory data store.
We use js-data
and js-data-angular
in our project.
I have the following model:
(function () {
'use strict';
angular.module('dash.models')
.factory('Diagnosis', ['DS', function (DS) {
function transform(resourcename, attrs, cb) {
attrs.icd9codes.forEach(function (el) {
delete el.add;
});
cb(null, attrs);
}
this.transform = transform;
return DS.defineResource({
name: 'diagnosis',
idAttribute: 'id',
endpoint: '/diagnosis',
baseUrl: '/api',
beforeCreate: transform,
beforeUpdate: transform
});
}]);
}());
And the following call to said model:
var startEditing = self.startEditing = function(parentScope, diagnosis) {
Diagnosis.findAll({
deep:true
}, {
endpoint: '/diagnosis/' + diagnosis.id
}).then(function(d) {
$scope.diagnosis = d;
$scope.inScope = true;
});
};
In my unit test, I mock the call like this:
var diagDeferred = _$q_.defer();
diagDeferred.resolve({
'name': 'Breast',
'categories': null,
'id': '026c7cd0-14ef-4312-a8f1-2092107b0e50',
'icd9codes': [{id: '1', code: '001', description: 'ICD9 Code'}]
});
spyOn(Diagnosis, 'findAll').and.returnValue(diagDeferred.promise);
And the actual call is mocked, what doesn't get executed (and I can't find any reliable information on how to get this done) is the function inside the .then
of the Diagnosis.findAll
I know the code works, but I need to cover it with unit tests and I'm coming up dry.
Thanks.
Source: (StackOverflow)
I'm using js-data (and js-data-angular) in conjunction with sockets via sails.js. When a new item is created/updated via sockets I want to call attention to it in my ui.
I'd like to add an "updated" property to the object, but don't want to inadvertently persist it to the DB.
Is there a way to hang non-persisting properties on a js-data object?
Source: (StackOverflow)
I have a problem with my controller. I use ionic (angular) and js-data. when I add a new item via addItem()
I will only when see it if I reload the page via F5.
Here is my code:
.controller('FooCtrl', function($scope, $ionicPlatform, foo) {
$ionicPlatform.ready(function() {
foo.findAll().then(function (items) {
$scope.items = items;
});
});
$scope.item = {};
$scope.addItem = function () {
foo.create({ name: $scope.item.name });
};
})
what I have to do to see the new element withous first pressing F5 in my browser window?
Source: (StackOverflow)