Skip to content

Commit f25c8b7

Browse files
authored
Added unit test for a reference cycle (#1191)
1 parent 6e86958 commit f25c8b7

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

packages/memory/test/space-test.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,3 +1890,126 @@ test(
18901890
);
18911891
},
18921892
);
1893+
1894+
test(
1895+
"list fact with cycle using schema query returns",
1896+
DB,
1897+
async (session) => {
1898+
const v1 = Fact.assert({
1899+
the,
1900+
of: doc1,
1901+
is: {
1902+
"value": {
1903+
"first": "Bob",
1904+
},
1905+
},
1906+
});
1907+
1908+
const v2 = Fact.assert({
1909+
the,
1910+
of: doc2,
1911+
is: {
1912+
"value": {
1913+
"home": {
1914+
"name": {
1915+
"$alias": {
1916+
"cell": {
1917+
"/": doc1.slice(3), // strip off 'of:'
1918+
},
1919+
"path": [],
1920+
},
1921+
},
1922+
"street": "2466 Southridge Drive",
1923+
"city": "Palm Springs",
1924+
},
1925+
"work": {
1926+
"name": "Mr. Bob Hope",
1927+
"street": "2627 N Hollywood Way",
1928+
"city": "Burbank",
1929+
},
1930+
},
1931+
},
1932+
});
1933+
1934+
const v3 = Fact.assert({
1935+
the,
1936+
of: doc1,
1937+
is: {
1938+
"value": {
1939+
"first": "Bob",
1940+
"address": {
1941+
"$alias": {
1942+
"cell": {
1943+
"/": doc2.slice(3), // strip off 'of:'
1944+
},
1945+
"path": ["home"],
1946+
},
1947+
},
1948+
},
1949+
},
1950+
cause: v1,
1951+
});
1952+
1953+
const tr1 = Transaction.create({
1954+
issuer: alice.did(),
1955+
subject: space.did(),
1956+
changes: Changes.from([v1]),
1957+
});
1958+
const write1 = await session.transact(tr1);
1959+
assert(write1.ok);
1960+
const c1 = Commit.toRevision(write1.ok);
1961+
const tr2 = Transaction.create({
1962+
issuer: alice.did(),
1963+
subject: space.did(),
1964+
changes: Changes.from([v2]),
1965+
});
1966+
const write2 = await session.transact(tr2);
1967+
assert(write2.ok);
1968+
const c2 = Commit.toRevision(write2.ok);
1969+
const tr3 = Transaction.create({
1970+
issuer: alice.did(),
1971+
subject: space.did(),
1972+
changes: Changes.from([v3]),
1973+
});
1974+
const write3 = await session.transact(tr3);
1975+
assert(write3.ok);
1976+
const c3 = Commit.toRevision(write3.ok);
1977+
1978+
const schemaSelector: SchemaSelector = {
1979+
[doc1]: {
1980+
[the]: {
1981+
_: {
1982+
path: [],
1983+
schemaContext: {
1984+
schema: {
1985+
"type": "object",
1986+
},
1987+
rootSchema: {
1988+
"type": "object",
1989+
},
1990+
},
1991+
},
1992+
},
1993+
},
1994+
};
1995+
1996+
const result = session.querySchema({
1997+
cmd: "/memory/graph/query",
1998+
iss: alice.did(),
1999+
sub: space.did(),
2000+
args: {
2001+
selectSchema: schemaSelector,
2002+
},
2003+
prf: [],
2004+
});
2005+
2006+
assertExists(
2007+
getResultForDoc(result, space.did(), doc1),
2008+
"doc1 should be in the result",
2009+
);
2010+
assertExists(
2011+
getResultForDoc(result, space.did(), doc2),
2012+
"doc2 should be in the result",
2013+
);
2014+
},
2015+
);

0 commit comments

Comments
 (0)