@graphistry/falcor
Version:
A JavaScript library for efficient data fetching.
83 lines (68 loc) • 2.75 kB
JavaScript
var $ref = require('@graphistry/falcor-json-graph').ref;
var strip = require('../support/strip');
var $atom = require('@graphistry/falcor-json-graph').atom;
var $pathValue = require('@graphistry/falcor-json-graph').pathValue;
var expect = require('chai').expect;
var getModel = require('../support/getModel');
var setPathValues = require('../../../lib/cache/set/setPathValues');
describe('an expired value', function() {
it('converts a negative $expires value to an absolute time', function() {
var cache = {};
var version = 0;
setPathValues(
getModel({ cache: cache, version: version++ }), [
$pathValue('grid', $ref('grids["id"]')),
$pathValue('grids["id"][0]', $ref('lists["id"]', {
$expires: -1000
}))
]
);
var value = cache.grids.id[0];
var expires = value.$expires;
expect(expires > Date.now()).to.be.true;
expect(strip(cache)).to.deep.equal(strip({
grid: $ref('grids["id"]'),
grids: { id: { 0: $ref('lists["id"]') } }
}));
});
it('sets through an immediately expired reference', function() {
var startTime = Date.now();
var cache = {};
var version = 0;
var expired = [];
setPathValues(
getModel({ cache: cache, expired: expired, version: version++ }), [
$pathValue('grid', $ref('grids["id"]')),
$pathValue('grids["id"][0]', $ref('lists["id"]', {
$expires: 0
})),
$pathValue('grid[0][0].title', 'Pulp Fiction')
]);
expect(expired.length).to.equal(1);
expect(strip(cache)).to.deep.equal(strip({
grid: $ref('grids["id"]'),
grids: { id: { 0: $ref('lists["id"]') } },
lists: { id: { 0: { title: $atom('Pulp Fiction') } } }
}));
});
it('sets through an already expired reference', function() {
var startTime = Date.now();
var cache = {};
var version = 0;
var expired = [];
setPathValues(
getModel({ cache: cache, expired: expired, version: version++ }), [
$pathValue('grid', $ref('grids["id"]')),
$pathValue('grids["id"][0]', $ref('lists["id"]', {
$expires: startTime - 10
})),
$pathValue('grid[0][0].title', 'Pulp Fiction')
]
);
expect(expired.length).to.equal(1);
expect(strip(cache)).to.deep.equal(strip({
grid: $ref('grids["id"]'),
grids: { id: { 0: { 0: { title: $atom('Pulp Fiction') } } } }
}));
});
});