Skip to content

Commit

Permalink
test(core): add ref tests
Browse files Browse the repository at this point in the history
  • Loading branch information
binier committed Aug 6, 2020
1 parent b8e28df commit a6f127d
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/core/test/ref.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { query, edge } from '../src';
import { uid } from '../src/operators';

// does not test formatting
describe('Ref test', () => {
it('another query uid', () => {
const q1 = query().func(uid('0x2'));
const q2 = query()
.func(uid(q1))
.filter(uid(q1))
.project({
id: 1,
name: 1,
});
const qStr = q2.build().toString();

expect(qStr).toMatch(/v1 as var\(func: uid\(0x2\)\)/);
expect(qStr).toMatch(/q1\(func: uid\(v1\)\)/);
});

it('another query nested uid', () => {
const q1 = query()
.func(uid('0x2'))
.project({
posts: edge({}).filter(uid('0x3', '0x4', '0x5')),
});

const q2 = query()
.func(uid(q1))
.project({
id: 1,
name: 1,
posts: edge({
id: 1,
})
.filter(uid(q1.ref('posts'))),
});
const qStr = q2.build().toString();

expect(qStr).toMatch(/v2 as var\(func: uid\(0x2\)\)/);
expect(qStr).toMatch(/v1 as posts @filter\(uid\(0x3, 0x4, 0x5\)\)/);
expect(qStr).toMatch(/q1\(func: uid\(v2\)\)/);
expect(qStr).toMatch(/posts @filter\(uid\(v1\)\)/);
});
});

0 comments on commit a6f127d

Please sign in to comment.