1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var inMemoryCache_1 = require("../inMemoryCache");
|
4 | var objectCache_1 = require("../objectCache");
|
5 | describe('OptimisticCacheLayer', function () {
|
6 | function makeLayer(root) {
|
7 | return new inMemoryCache_1.OptimisticCacheLayer('whatever', root, function () { });
|
8 | }
|
9 | describe('returns correct values during recording', function () {
|
10 | var data = {
|
11 | Human: { __typename: 'Human', name: 'Mark' },
|
12 | Animal: { __typename: 'Mouse', name: '🐭' },
|
13 | };
|
14 | var dataToRecord = {
|
15 | Human: { __typename: 'Human', name: 'John' },
|
16 | };
|
17 | var underlyingCache = new objectCache_1.ObjectCache(data);
|
18 | var cache = makeLayer(underlyingCache);
|
19 | beforeEach(function () {
|
20 | cache = makeLayer(underlyingCache);
|
21 | });
|
22 | it('should passthrough values if not defined in recording', function () {
|
23 | expect(cache.get('Human')).toBe(data.Human);
|
24 | expect(cache.get('Animal')).toBe(data.Animal);
|
25 | });
|
26 | it('should return values defined during recording', function () {
|
27 | cache.set('Human', dataToRecord.Human);
|
28 | expect(cache.get('Human')).toBe(dataToRecord.Human);
|
29 | expect(underlyingCache.get('Human')).toBe(data.Human);
|
30 | });
|
31 | it('should return undefined for values deleted during recording', function () {
|
32 | expect(cache.get('Animal')).toBe(data.Animal);
|
33 | cache.delete('Animal');
|
34 | expect(cache.get('Animal')).toBeUndefined();
|
35 | expect(cache.toObject()).toHaveProperty('Animal');
|
36 | expect(underlyingCache.get('Animal')).toBe(data.Animal);
|
37 | });
|
38 | });
|
39 | describe('returns correct result of a recorded transaction', function () {
|
40 | var data = {
|
41 | Human: { __typename: 'Human', name: 'Mark' },
|
42 | Animal: { __typename: 'Mouse', name: '🐭' },
|
43 | };
|
44 | var dataToRecord = {
|
45 | Human: { __typename: 'Human', name: 'John' },
|
46 | };
|
47 | var underlyingCache = new objectCache_1.ObjectCache(data);
|
48 | var cache = makeLayer(underlyingCache);
|
49 | var recording;
|
50 | beforeEach(function () {
|
51 | cache = makeLayer(underlyingCache);
|
52 | cache.set('Human', dataToRecord.Human);
|
53 | cache.delete('Animal');
|
54 | recording = cache.toObject();
|
55 | });
|
56 | it('should contain the property indicating deletion', function () {
|
57 | expect(recording).toHaveProperty('Animal');
|
58 | });
|
59 | it('should have recorded the changes made during recording', function () {
|
60 | expect(recording).toEqual({
|
61 | Human: dataToRecord.Human,
|
62 | Animal: undefined,
|
63 | });
|
64 | });
|
65 | it('should keep the original data unaffected', function () {
|
66 | expect(underlyingCache.toObject()).toEqual(data);
|
67 | });
|
68 | });
|
69 | });
|
70 |
|
\ | No newline at end of file |