Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more query tests #27

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
73cd014
feat: Updated tests/unit/queries/query.test.ts
sweep-ai[bot] Nov 1, 2023
d29d060
feat: Updated tests/mocks/data.tql
sweep-ai[bot] Nov 1, 2023
4351d2b
Merge main into sweep/add-query-tests
sweep-ai[bot] Nov 2, 2023
7b04551
Merge main into sweep/add-query-tests
sweep-ai[bot] Nov 3, 2023
ead09fb
Merge main into sweep/add-query-tests
sweep-ai[bot] Nov 6, 2023
f301c01
Merge main into sweep/add-query-tests
sweep-ai[bot] Nov 8, 2023
5de7b7a
Merge main into sweep/add-query-tests
sweep-ai[bot] Nov 10, 2023
3f94fa5
Merge main into sweep/add-query-tests
sweep-ai[bot] Nov 10, 2023
2998ae8
Merge main into sweep/add-query-tests
sweep-ai[bot] Nov 13, 2023
2af7b9d
Merge main into sweep/add-query-tests
sweep-ai[bot] Nov 13, 2023
8c222cf
Merge main into sweep/add-query-tests
sweep-ai[bot] Nov 13, 2023
6bba21a
Merge main into sweep/add-query-tests
sweep-ai[bot] Nov 17, 2023
06fefc8
Merge main into sweep/add-query-tests
sweep-ai[bot] Jan 26, 2024
c276803
Merge main into sweep/add-query-tests
sweep-ai[bot] Jan 26, 2024
dfb8839
Merge main into sweep/add-query-tests
sweep-ai[bot] Jan 30, 2024
21739b6
Merge main into sweep/add-query-tests
sweep-ai[bot] Jan 30, 2024
48f61c6
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 1, 2024
9991a8c
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 1, 2024
d2f875a
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 3, 2024
e911d6b
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 3, 2024
592ff26
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 4, 2024
f30064a
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 5, 2024
7335b83
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 5, 2024
d5c6a7e
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 8, 2024
4111fb5
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 8, 2024
7f4bc30
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 8, 2024
8758b81
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 8, 2024
163ee04
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 8, 2024
c527df8
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 9, 2024
8817cf9
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 12, 2024
b38e9b4
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 12, 2024
bcd181c
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 14, 2024
307eff3
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 15, 2024
e62d216
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 15, 2024
947b601
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 26, 2024
aa5c345
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 26, 2024
d656616
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 26, 2024
28c3813
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 26, 2024
b88b777
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 27, 2024
a9bc921
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 27, 2024
7d1302f
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 27, 2024
3944629
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 28, 2024
af7807a
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 28, 2024
ef3efe0
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 28, 2024
d06a732
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 28, 2024
3841389
Merge main into sweep/add-query-tests
sweep-ai[bot] Feb 28, 2024
2324916
Merge main into sweep/add-query-tests
sweep-ai[bot] Mar 12, 2024
4eed529
Merge main into sweep/add-query-tests
sweep-ai[bot] Mar 12, 2024
c86b734
Merge main into sweep/add-query-tests
sweep-ai[bot] Mar 13, 2024
5ba6607
Merge main into sweep/add-query-tests
sweep-ai[bot] Mar 13, 2024
d689995
Merge main into sweep/add-query-tests
sweep-ai[bot] Mar 17, 2024
6047726
Merge main into sweep/add-query-tests
sweep-ai[bot] Mar 17, 2024
65358fc
Merge main into sweep/add-query-tests
sweep-ai[bot] Mar 24, 2024
4d7666f
Merge main into sweep/add-query-tests
sweep-ai[bot] Mar 24, 2024
680fc69
Merge main into sweep/add-query-tests
sweep-ai[bot] Apr 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tests/mocks/data.tql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ $user-2 isa User, has id "user2", has name "Loic", has User·email "[email protected]
$user-3 isa User, has id "user3", has name "Ann", has User·email "[email protected]";
$user-4 isa User, has id "user4", has name "Ben";
$user-5 isa User, has id "user5", has name "Charlize", has User·email "[email protected]";
$user-6 isa User, has id "user6", has name "John", has User·email "[email protected]";
$user-7 isa User, has id "user7", has name "Jane", has User·email "[email protected]";
$user-8 isa User, has id "user8", has name "Bob", has User·email "[email protected]";
$user-9 isa User, has id "user9", has name "Alice", has User·email "[email protected]";
$user-10 isa User, has id "user10", has name "Charlie", has User·email "[email protected]";

$thing1 isa Thing, has id "thing1", has Thing·stuff "A";
$thing2 isa Thing, has id "thing2", has Thing·stuff "B";
Expand Down Expand Up @@ -63,6 +68,21 @@ $user-account-1-2 (user: $user-1, accounts: $account-1-2) isa User-Accounts, has
$user-account-1-3 (user: $user-1, accounts: $account-1-3) isa User-Accounts, has id 'ua1-3';
$user-account-2-1 (user: $user-2, accounts: $account-2-1) isa User-Accounts, has id 'ua2-1';
$user-account-3-1 (user: $user-3, accounts: $account-3-1) isa User-Accounts, has id 'ua3-1';
$account-4-1 isa Account, has id "account4-1", has Account·provider "google";
$account-5-1 isa Account, has id "account5-1", has Account·provider "facebook";
$account-6-1 isa Account, has id "account6-1", has Account·provider "github";
$account-7-1 isa Account, has id "account7-1", has Account·provider "google";
$account-8-1 isa Account, has id "account8-1", has Account·provider "facebook";
$account-9-1 isa Account, has id "account9-1", has Account·provider "github";
$account-10-1 isa Account, has id "account10-1", has Account·provider "google";

$user-account-4-1 (user: $user-4, accounts: $account-4-1) isa User-Accounts, has id 'ua4-1';
$user-account-5-1 (user: $user-5, accounts: $account-5-1) isa User-Accounts, has id 'ua5-1';
$user-account-6-1 (user: $user-6, accounts: $account-6-1) isa User-Accounts, has id 'ua6-1';
$user-account-7-1 (user: $user-7, accounts: $account-7-1) isa User-Accounts, has id 'ua7-1';
$user-account-8-1 (user: $user-8, accounts: $account-8-1) isa User-Accounts, has id 'ua8-1';
$user-account-9-1 (user: $user-9, accounts: $account-9-1) isa User-Accounts, has id 'ua9-1';
$user-account-10-1 (user: $user-10, accounts: $account-10-1) isa User-Accounts, has id 'ua10-1';


$space-1 isa Space, has id "space-1", has name "Production";
Expand All @@ -87,6 +107,19 @@ $tag-4 (users: $user-2) isa UserTag, has id 'tag-4';

$group-1 (tags: $tag-1, tags: $tag-2, color: $yellow) isa UserTagGroup, has id 'utg-1';
$group-2 (tags: $tag-3, color:$blue, space: $space-3) isa UserTagGroup, has id 'utg-2';
$tag-5 (users: $user-4) isa UserTag, has id 'tag-5';
$tag-6 (users: $user-5, users: $user-6) isa UserTag, has id 'tag-6';
$tag-7 (users: $user-7) isa UserTag, has id 'tag-7';
$tag-8 (users: $user-8) isa UserTag, has id 'tag-8';

$group-3 (tags: $tag-5, tags: $tag-6, color: $yellow) isa UserTagGroup, has id 'utg-3';
$group-4 (tags: $tag-7, color:$blue, space: $space-3) isa UserTagGroup, has id 'utg-4';

(users: $user-4, spaces: $space-1) isa Space-User, has id 'u4-s1';
(users: $user-5, spaces: $space-2) isa Space-User, has id 'u5-s2';
(users: $user-6, spaces: $space-1) isa Space-User, has id 'u6-s1';
(users: $user-7, spaces: $space-2) isa Space-User, has id 'u7-s2';
(users: $user-8, spaces: $space-2, power: $power1) isa Space-User, has id 'u8-s2';

#$red isa Color, has Color·name 'red';
#$blue isa Color, has Color·name 'blue';
Expand All @@ -99,6 +132,12 @@ $self1 (space:$space-2) isa Self, has id 'self1';
$self2 (space:$space-2, owner: $self1) isa Self, has id 'self2';
$self3 (space:$space-2, owner: $self2) isa Self, has id 'self3';
$self4 (space:$space-2, owner: $self2) isa Self, has id 'self4';
$kind-magazine (space: $space-2) isa Kind, has id 'kind-magazine', has Kind·name 'magazine';

$self5 (space:$space-2) isa Self, has id 'self5';
$self6 (space:$space-2, owner: $self5) isa Self, has id 'self6';
$self7 (space:$space-2, owner: $self6) isa Self, has id 'self7';
$self8 (space:$space-2, owner: $self6) isa Self, has id 'self8';

$hook1 isa Hook, has id 'hook1', has Hook·requiredOption 'a';
$hook2 isa Hook, has id 'hook2', has Hook·requiredOption 'b';
Expand Down
89 changes: 89 additions & 0 deletions tests/unit/queries/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2109,3 +2109,92 @@ describe('Query', () => {
await cleanup(bormClient, dbName);
});
});
it('test1[entity,filter] - $filter by non-unique field', async () => {
expect(client).toBeDefined();
const res = await client.query({
$entity: 'User',
$filter: { name: 'Antoine' },
$fields: ['id'],
});
expect(res).toBeDefined();
expect(res).not.toBeInstanceOf(String);

expect(deepSort(res)).toEqual([
{ $entity: 'User', $id: 'user1', id: 'user1' },
]);
});

it('test2[entity,filter] - $filter by multiple fields', async () => {
expect(client).toBeDefined();
const res = await client.query({
$entity: 'User',
$filter: { name: 'Antoine', email: '[email protected]' },
$fields: ['id'],
});
expect(res).toBeDefined();
expect(res).not.toBeInstanceOf(String);

expect(deepSort(res)).toEqual([
{ $entity: 'User', $id: 'user1', id: 'user1' },
]);
});

it('test3[entity,filter] - $filter by nested field', async () => {
expect(client).toBeDefined();
const res = await client.query({
$entity: 'User',
$filter: { 'accounts.provider': 'github' },
$fields: ['id'],
});
expect(res).toBeDefined();
expect(res).not.toBeInstanceOf(String);

expect(deepSort(res)).toEqual([
{ $entity: 'User', $id: 'user1', id: 'user1' },
]);
});

it('test4[entity,filter] - $filter by multiple nested fields', async () => {
expect(client).toBeDefined();
const res = await client.query({
$entity: 'User',
$filter: { 'accounts.provider': 'github', 'spaces.id': 'space-1' },
$fields: ['id'],
});
expect(res).toBeDefined();
expect(res).not.toBeInstanceOf(String);

expect(deepSort(res)).toEqual([
{ $entity: 'User', $id: 'user1', id: 'user1' },
]);
});

it('test5[entity,filter] - $filter by array field', async () => {
expect(client).toBeDefined();
const res = await client.query({
$entity: 'User',
$filter: { 'spaces.id': { $in: ['space-1', 'space-2'] } },
$fields: ['id'],
});
expect(res).toBeDefined();
expect(res).not.toBeInstanceOf(String);

expect(deepSort(res)).toEqual([
{ $entity: 'User', $id: 'user1', id: 'user1' },
]);
});

it('test6[entity,filter] - $filter by nested array field', async () => {
expect(client).toBeDefined();
const res = await client.query({
$entity: 'User',
$filter: { 'accounts.provider': { $in: ['github', 'google'] } },
$fields: ['id'],
});
expect(res).toBeDefined();
expect(res).not.toBeInstanceOf(String);

expect(deepSort(res)).toEqual([
{ $entity: 'User', $id: 'user1', id: 'user1' },
]);
});