Beispiel #1
0
            it("through successful, short-circuit, and broken references", function() {

                var cache = {};
                var version = 0;
                setPathValues(
                    getModel({ cache: cache, version: version++ }), [
                        $pathValue("grid", $ref("grids['id']")),
                        $pathValue("grids['id'][0]", $ref("lists['id']")),
                        $pathValue("lists['id'][0]", $ref("movies['pulp-fiction']")),
                        $pathValue("lists['id'][1]", $ref("movies['kill-bill-1']")),
                        $pathValue("lists['id'][2]", $ref("movies['reservior-dogs']")),
                        $pathValue("movies['kill-bill-1'].genres", $atom()),
                        $pathValue("grid[0][0, 1, 2].genres", $atom(["Crime", "Drama", "Thriller"]))
                    ]
                );

                expect(strip(cache)).to.deep.equal(strip({
                    grid: $ref("grids['id']"),
                    grids: { id: { 0: $ref("lists['id']") } },
                    lists: { id: {
                        0: $ref("movies['pulp-fiction']"),
                        1: $ref("movies['kill-bill-1']"),
                        2: $ref("movies['reservior-dogs']") }
                    },
                    movies: {
                        "pulp-fiction": { "genres": $atom(["Crime", "Drama", "Thriller"]) },
                        "kill-bill-1": { "genres": $atom(["Crime", "Drama", "Thriller"]) },
                        "reservior-dogs": { "genres": $atom(["Crime", "Drama", "Thriller"]) }
                    }
                }));
            });
Beispiel #2
0
 it('should have identical behavior when fetching a missing value or atom of undefined.', function() {
     getCoreRunner({
         input: [["lists", 2343, "0", "name"], ["lists", 2343, "1", "rating"]],
         output: {
             json: {
                 lists: {
                     2343: {
                         0: {},
                         1: {}
                     }
                 }
             }
         },
         cache: {
             lists: {
                 2343: {
                     0: jsonGraph.ref(["videos", 123]),
                     1: jsonGraph.ref(["videos", 123])
                 }
             },
             videos: {
                 123: {
                     name: atom()
                 }
             }
         }
     });
 });
Beispiel #3
0
            it("[length:3]", function() {

                var cache = {};
                var version = 0;
                setPathValues(
                    getModel({ cache: cache, version: version++ }), [
                        $pathValue("grid", $ref("grids['id']")),
                        $pathValue("grids['id'][0]", $ref("lists['id']")),
                        $pathValue("lists['id'][0]", $ref("movies['pulp-fiction']")),
                        $pathValue("lists['id'][1]", $ref("movies['kill-bill-1']")),
                        $pathValue("lists['id'][2]", $ref("movies['reservior-dogs']")),
                        $pathValue("movies['kill-bill-1'].genres", $atom()),
                        $pathValue(["grid", 0, [{length: 3}], "genres"], $atom(["Crime", "Drama", "Thriller"]))
                    ]
                );

                expect(strip(cache)).to.deep.equal(strip({
                    grid: $ref("grids['id']"),
                    grids: { id: { 0: $ref("lists['id']") } },
                    lists: { id: {
                        0: $ref("movies['pulp-fiction']"),
                        1: $ref("movies['kill-bill-1']"),
                        2: $ref("movies['reservior-dogs']") }
                    },
                    movies: {
                        "pulp-fiction": { "genres": $atom(["Crime", "Drama", "Thriller"]) },
                        "kill-bill-1": { "genres": $atom(["Crime", "Drama", "Thriller"]) },
                        "reservior-dogs": { "genres": $atom(["Crime", "Drama", "Thriller"]) }
                    }
                }));
            });
Beispiel #4
0
            it("[length:3]", function() {

                var cache = {};
                var version = 0;
                setPathMaps(
                    getModel({ cache: cache, version: version++ }), [
                        $pathMapEnvelope("grid", $ref("grids['id']")),
                        $pathMapEnvelope("grids['id'][0]", $ref("lists['id']")),
                        $pathMapEnvelope("lists['id'][0]", $ref("movies['pulp-fiction']")),
                        $pathMapEnvelope("lists['id'][1]", $ref("movies['kill-bill-1']")),
                        $pathMapEnvelope("lists['id'][2]", $ref("movies['reservior-dogs']")),
                        $pathMapEnvelope("movies['kill-bill-1'].director", $atom()),
                        $pathMapEnvelope(["grid", 0, [{length: 3}], "director"], "Quentin Tarantino")
                    ]
                );

                expect(strip(cache)).to.deep.equal(strip({
                    grid: $ref("grids['id']"),
                    grids: { id: { 0: $ref("lists['id']") } },
                    lists: { id: {
                        0: $ref("movies['pulp-fiction']"),
                        1: $ref("movies['kill-bill-1']"),
                        2: $ref("movies['reservior-dogs']") }
                    },
                    movies: {
                        "pulp-fiction": { "director": $atom("Quentin Tarantino") },
                        "kill-bill-1": { "director": $atom("Quentin Tarantino") },
                        "reservior-dogs": { "director": $atom("Quentin Tarantino") }
                    }
                }));
            });
Beispiel #5
0
            it("through successful, short-circuit, and broken references", function() {

                var cache = {};
                var version = 0;
                setPathMaps(
                    getModel({ cache: cache, version: version++ }), [
                        $pathMapEnvelope("grid", $ref("grids['id']")),
                        $pathMapEnvelope("grids['id'][0]", $ref("lists['id']")),
                        $pathMapEnvelope("lists['id'][0]", $ref("movies['pulp-fiction']")),
                        $pathMapEnvelope("lists['id'][1]", $ref("movies['kill-bill-1']")),
                        $pathMapEnvelope("lists['id'][2]", $ref("movies['reservior-dogs']")),
                        $pathMapEnvelope("movies['kill-bill-1'].director", $atom()),
                        $pathMapEnvelope("grid[0][0, 1, 2].director", "Quentin Tarantino")
                    ]
                );

                expect(strip(cache)).to.deep.equal(strip({
                    grid: $ref("grids['id']"),
                    grids: { id: { 0: $ref("lists['id']") } },
                    lists: { id: {
                        0: $ref("movies['pulp-fiction']"),
                        1: $ref("movies['kill-bill-1']"),
                        2: $ref("movies['reservior-dogs']") }
                    },
                    movies: {
                        "pulp-fiction": { "director": $atom("Quentin Tarantino") },
                        "kill-bill-1": { "director": $atom("Quentin Tarantino") },
                        "reservior-dogs": { "director": $atom("Quentin Tarantino") }
                    }
                }));
            });
Beispiel #6
0
            it("from:1, length:2", function() {

                var cache = {};
                var version = 0;
                setPathValues(
                    getModel({ cache: cache, version: version++ }), [
                        $pathValue("grid", $ref("grids['id']")),
                        $pathValue("grids['id'][0]", $ref("lists['id']")),
                        $pathValue("lists['id'][1]", $ref("movies['kill-bill-1']")),
                        $pathValue("lists['id'][2]", $ref("movies['reservior-dogs']")),
                        $pathValue("movies['kill-bill-1'].director", $atom()),
                        $pathValue(["grid", 0, {from: 1, length: 2}, "director"], "Quentin Tarantino")
                    ]
                );

                expect(strip(cache)).to.deep.equal(strip({
                    grid: $ref("grids['id']"),
                    grids: { id: { 0: $ref("lists['id']") } },
                    lists: { id: {
                        1: $ref("movies['kill-bill-1']"),
                        2: $ref("movies['reservior-dogs']") }
                    },
                    movies: {
                        "kill-bill-1": { "director": $atom("Quentin Tarantino") },
                        "reservior-dogs": { "director": $atom("Quentin Tarantino") }
                    }
                }));
            });
Beispiel #7
0
 it('should not get references.', function() {
     getCoreRunner({
         input: [["lists", 2343, "0"]],
         output: {
             json: {
                 lists: {
                     2343: {
                     }
                 }
             }
         },
         cache: {
             lists: {
                 2343: {
                     0: jsonGraph.ref(["videos", 123])
                 }
             },
             videos: {
                 123: {
                     name: atom("House of cards")
                 }
             }
         }
     });
 });
Beispiel #8
0
 return function() {
     getCoreRunner({
         input: paths,
         output: {
             json: {
                 lists: {
                     2343: {
                         0: {
                             name: 'House of cards'
                         }
                     }
                 }
             }
         },
         cache: {
             lists: {
                 2343: {
                     0: jsonGraph.ref(["videos", 123])
                 }
             },
             videos: {
                 123: {
                     name: atom("House of cards")
                 }
             }
         }
     });
 };
Beispiel #9
0
 it('should get JSONGraph allow for a null at the end to get a value behind a reference.', function() {
     getCoreRunner({
         input: [['reference', null]],
         isJSONG: true,
         output: {
             jsonGraph: {
                 "reference": {
                     "$type": "ref",
                     "value": ["foo", "bar"]
                 },
                 "foo": {
                     "bar": {
                         "$type": "atom",
                         "value": "value"
                     }
                 }
             },
             paths: [
                 ["reference", null]
             ]
         },
         cache: {
             reference: jsonGraph.ref(['foo', 'bar']),
             foo: {
                 bar: atom('value')
             }
         }
     });
 });
Beispiel #10
0
    it("through a reference", function() {

        var lru = new Object();
        var cache = {};
        var version = 0;
        setPathMaps(
            getModel({ lru: lru, cache: cache, version: version++ }), [
                $pathMapEnvelope("grid", $ref("grids['id']")),
                $pathMapEnvelope("grids['id'][0]", $ref("lists['id']")),
                $pathMapEnvelope("lists['id'][0]", $ref("movies['pulp-fiction']")),
                $pathMapEnvelope("movies['pulp-fiction']", "Pulp Fiction")
            ]
        );

        setPathMaps(
            getModel({ lru: lru, cache: cache, version: version++ }), [
                $pathMapEnvelope("grid[0][0].title", "Pulp Fiction")
            ]
        );

        expect(strip(cache)).to.deep.equal(strip({
            grid: $ref("grids['id']"),
            grids: { id: { 0: $ref("lists['id']") } },
            lists: { id: { 0: $ref("movies['pulp-fiction']") } },
            movies: {
                "pulp-fiction": {
                    title: $atom("Pulp Fiction")
                }
            }
        }));
    });
Beispiel #11
0
    it("through a reference that lands on an atom", function() {

        var cache = {};
        var version = 0;

        setPathValues(
            getModel({ cache: cache, version: version++ }), [
                $pathValue("grid", $ref("grids['id']")),
                $pathValue("grids['id'][0]", $ref("lists['id']")),
                $pathValue("lists['id'][1]", $ref("movies['kill-bill-1']")),
                $pathValue("movies['kill-bill-1'].summary", $atom()),
                $pathValue("grid[0][1].summary", $atom({
                    title: "Kill Bill: Vol. 1",
                    url: "/movies/id/kill-bill-1"
                }))
            ]
        );

        expect(strip(cache)).to.deep.equal(strip({
            grid: $ref("grids['id']"),
            grids: { id: { 0: $ref("lists['id']") } },
            lists: { id: { 1: $ref("movies['kill-bill-1']") } },
            movies: {
                "kill-bill-1": {
                    summary: $atom({
                        title: "Kill Bill: Vol. 1",
                        url: "/movies/id/kill-bill-1"
                    })
                }
            }
        }));
    });
Beispiel #12
0
    it("through a reference with a null last key", function() {

        var cache = {};
        var version = 0;

        setPathValues(
            getModel({ cache: cache, version: version++ }), [
                $pathValue("grid", $ref("grids['id']")),
                $pathValue("grids['id'][0]", $ref("lists['id']")),
                $pathValue("lists['id'][2]", $ref("movies['reservior-dogs']")),
                $pathValue(["grid", 0, 2, null], $atom({
                    title: "Reservior Dogs",
                    url: "/movies/id/reservior-dogs"
                }))
            ]
        );

        expect(strip(cache)).to.deep.equal(strip({
            grid: $ref("grids['id']"),
            grids: { id: { 0: $ref("lists['id']") } },
            lists: { id: { 2: $ref("movies['reservior-dogs']") } },
            movies: { "reservior-dogs": $atom({
                title: "Reservior Dogs",
                url: "/movies/id/reservior-dogs"
            }) }
        }));
    });
Beispiel #13
0
    it("through a reference that lands on an atom", function() {

        var cache = {};
        var version = 0;
        setPathMaps(
            getModel({ cache: cache, version: version++ }), [
                $pathMapEnvelope("grid", $ref("grids['id']")),
                $pathMapEnvelope("grids['id'][0]", $ref("lists['id']")),
                $pathMapEnvelope("lists['id'][1]", $ref("movies['kill-bill-1']")),
                $pathMapEnvelope("movies['kill-bill-1'].title", $atom()),
                $pathMapEnvelope("grid[0][1].title", "Kill Bill Vol. 1")
            ]
        );

        expect(strip(cache)).to.deep.equal(strip({
            grid: $ref("grids['id']"),
            grids: { id: { 0: $ref("lists['id']") } },
            lists: { id: { 1: $ref("movies['kill-bill-1']") } },
            movies: {
                "kill-bill-1": {
                    title: $atom("Kill Bill Vol. 1")
                }
            }
        }));
    });
Beispiel #14
0
    xit("through a reference with a null last key", function() {

        var cache = {};
        var version = 0;
        setPathMaps(
            getModel({ cache: cache, version: version++ }), [
                $pathMapEnvelope("grid", $ref("grids['id']")),
                $pathMapEnvelope("grids['id'][0]", $ref("lists['id']")),
                $pathMapEnvelope("lists['id'][0]", $ref("movies['pulp-fiction']")),
                $pathMapEnvelope("movies['pulp-fiction'].title", "Pulp Fiction")
            ]
        );

        setPathMaps(
            getModel({ cache: cache, version: version++ }), [
                $pathMapEnvelope(["grid", 0, 0, null], $error("oops"))
            ]
        );

        expect(strip(cache)).to.deep.equal(strip({
            grid: $ref("grids['id']"),
            grids: { id: { 0: $ref("lists['id']") } },
            lists: { id: { 0: $ref("movies['pulp-fiction']") } },
            movies: { "pulp-fiction": $error("oops") }
        }));
    });
Beispiel #15
0
    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']") } }
        }));
    });
Beispiel #16
0
    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") } } } }
        }));
    });
Beispiel #17
0
 it('should not get the value after the reference.', function() {
     getCoreRunner({
         input: [['lolomo']],
         output: {
             json: {}
         },
         cache: {
             lolomo: jsonGraph.ref(['test', 'value']),
             test: {
                 value: atom('value')
             }
         }
     });
 });
Beispiel #18
0
 it('should allow for a null at the end to get a value behind a reference.', function() {
     getCoreRunner({
         input: [['lolomo', null]],
         output: {
             json: {
                 lolomo: 'value'
             }
         },
         cache: {
             lolomo: jsonGraph.ref(['test', 'value']),
             test: {
                 value: atom('value')
             }
         }
     });
 });
Beispiel #19
0
 it('should get JSONGraph to get a reference.', function() {
     getCoreRunner({
         input: [['reference']],
         isJSONG: true,
         output: {
             jsonGraph: {
                 "reference": {
                     "$type": "ref",
                     "value": ["foo", "bar"]
                 }
             },
             paths: [
                 ["reference"]
             ]
         },
         cache: {
             reference: jsonGraph.ref(['foo', 'bar']),
             foo: {
                 bar: atom('value')
             }
         }
     });
 });
Beispiel #20
0
    it("through a broken reference", function() {

        var cache = {};
        var version = 0;
        setPathMaps(
            getModel({ cache: cache, version: version++ }), [
                $pathMapEnvelope("grid", $ref("grids['id']")),
                $pathMapEnvelope("grids['id'][0]", $ref("lists['id']")),
                $pathMapEnvelope("lists['id'][2]", $ref("movies['reservior-dogs']")),
                $pathMapEnvelope("grid[0][2].title", "Reservior Dogs")
            ]
        );

        expect(strip(cache)).to.deep.equal(strip({
            grid: $ref("grids['id']"),
            grids: { id: { 0: $ref("lists['id']") } },
            lists: { id: { 2: $ref("movies['reservior-dogs']") } },
            movies: {
                "reservior-dogs": {
                    title: $atom("Reservior Dogs")
                }
            }
        }));
    });