Skip to content

Commit

Permalink
added tests for MaxRetryExceededError during set,
Browse files Browse the repository at this point in the history
and better tests for get
  • Loading branch information
asyncanup committed Sep 11, 2017
1 parent 24fa846 commit 20aad1b
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 24 deletions.
66 changes: 42 additions & 24 deletions test/falcor/get/get.dataSource-only.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var falcor = require("./../../../lib/");
var falcor = require('./../../../lib/');
var Model = falcor.Model;
var Rx = require('rx');
var noOp = function() {};
var LocalDataSource = require('../../data/LocalDataSource');
var ErrorDataSource = require('../../data/ErrorDataSource');
var asyncifyDataSource = require('../../data/asyncifyDataSource')
var isPathValue = require("./../../../lib/support/isPathValue");
var expect = require("chai").expect;
var isPathValue = require('./../../../lib/support/isPathValue');
var expect = require('chai').expect;
var sinon = require('sinon');
var cacheGenerator = require('./../../CacheGenerator');
var atom = require('falcor-json-graph').atom;
Expand Down Expand Up @@ -90,13 +90,13 @@ describe('DataSource Only', function() {
it('should get a directly referenced value from falcor.', function(done) {
var cache = {
reference: {
$type: "ref",
value: ["foo", "bar"]
$type: 'ref',
value: ['foo', 'bar']
},
foo: {
bar: {
$type: "atom",
value: "value"
$type: 'atom',
value: 'value'
}
}
};
Expand All @@ -106,7 +106,7 @@ describe('DataSource Only', function() {
get(['reference', null])).
doAction(onNext, noOp, function() {
expect(strip(onNext.getCall(0).args[0])).to.deep.equals({
json: {reference: "value"}
json: {reference: 'value'}
});
}).
subscribe(noOp, done, done);
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('DataSource Only', function() {
doAction(noOp, function(err) {
outputError = err;
expect(err).to.deep.equals({
$type: "error",
$type: 'error',
value: {
message: 'Oops!',
status: 500
Expand All @@ -190,31 +190,31 @@ describe('DataSource Only', function() {
}
});
});
it("should get all missing paths in a single request", function(done) {
it('should get all missing paths in a single request', function(done) {
var serviceCalls = 0;
var cacheModel = new Model({
cache: {
lolomo: {
summary: {
$type: "atom",
value: "hello"
$type: 'atom',
value: 'hello'
},
0: {
summary: {
$type: "atom",
value: "hello-0"
$type: 'atom',
value: 'hello-0'
}
},
1: {
summary: {
$type: "atom",
value: "hello-1"
$type: 'atom',
value: 'hello-1'
}
},
2: {
summary: {
$type: "atom",
value: "hello-2"
$type: 'atom',
value: 'hello-2'
}
}
}
Expand All @@ -230,7 +230,7 @@ describe('DataSource Only', function() {

var onNext = sinon.spy();
toObservable(model.
get("lolomo.summary", "lolomo[0..2].summary")).
get('lolomo.summary', 'lolomo[0..2].summary')).
doAction(onNext, noOp, function() {
var data = onNext.getCall(0).args[0];
var json = data.json;
Expand Down Expand Up @@ -342,20 +342,38 @@ describe('DataSource Only', function() {
}, done.bind('should not complete'));
});

it('should return missing paths with MaxRetryExceededError', function(done) {
var model = new Model({ source: asyncifyDataSource(new LocalDataSource({})) });
it('should return missing optimized paths with MaxRetryExceededError', function(done) {
var model = new Model({
source: asyncifyDataSource(new LocalDataSource({})),
cache: {
lolomo: {
0: {
$type: 'ref',
value: ['videos', 1]
}
},
videos: {
0: {
title: 'Revolutionary Road'
}
}
}
});
toObservable(model.
get(['videos', 0, 'title'], 'hall[0].ween')).
get(['lolomo', 0, 'title'], 'videos[0].title', 'hall[0].ween')).
doAction(noOp, function(e) {
expect(MaxRetryExceededError.is(e), 'MaxRetryExceededError expected.').to.be.ok;
expect(e.missingPaths).to.deep.equals([['videos', 0, 'title'], ['hall', 0, 'ween']]);
expect(e.missingOptimizedPaths).to.deep.equals([
['videos', 1, 'title'],
['hall', 0, 'ween']
]);
}).
subscribe(noOp, function(e) {
if (isAssertionError(e)) {
return done(e);
}
return done();
}, done.bind('should not complete'));
}, done.bind(null, new Error('should not complete')));
});
});

Expand Down
46 changes: 46 additions & 0 deletions test/falcor/set/set.dataSource-only.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var sinon = require('sinon');
var LocalDataSource = require('./../../data/LocalDataSource');
var Cache = require('./../../data/Cache');
var strip = require('./../../cleanData').stripDerefAndVersionKeys;
var MaxRetryExceededError = require('./../../../lib/errors/MaxRetryExceededError');

describe('DataSource.', function() {
it('should validate args are sent to the dataSource collapsed.', function(done) {
Expand Down Expand Up @@ -194,4 +195,49 @@ describe('DataSource.', function() {
}).
subscribe(noOp, done, done);
});

it('should return missing optimized paths with a MaxRetryExceededError.', function(done) {
var onSet = function(source, tmpGraph, jsonGraphFromSet) {
model.invalidate('videos[1234].title');
return {
jsonGraph: {
videos: {
1234: {}
}
},
paths: []
};
};
var dataSource = new LocalDataSource(Cache(), {
onSet: onSet
});
var model = new Model({
source: dataSource
});

toObservable(model.
set({
json: {
videos: {
1234: {
title: 'Nowhere to be found'
}
}
}
})).
doAction(noOp, function(e) {
expect(MaxRetryExceededError.is(err), 'MaxRetryExceededError expected').to.be.ok;
expect(err.missingOptimizedPaths).to.deep.equal([['videos', '1234', 'title']]);
}).
subscribe(noOp, function(e) {
if (isAssertionError(e)) {
return done(e);
}
return done();
}, done.bind(null, new Error('should not complete')));
});
});

function isAssertionError(e) {
return e.hasOwnProperty('expected') && e.hasOwnProperty('actual');
}

0 comments on commit 20aad1b

Please sign in to comment.