Skip to content
New issue

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

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

Already on GitHub? # to your account

filter org grants #33

Merged
merged 16 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
139 changes: 95 additions & 44 deletions integration-tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import * as orgsWithGrants from './test-queries/orgs-with-grants';
import * as someNews from './test-queries/some-news';
import * as boardTerms from './test-queries/board-terms';
import * as moreMeta from './test-queries/more-meta';
import * as orgNameLike from './test-queries/org-name-like';
import * as sortOrgGrantsByDate from './test-queries/sort-org-grants-by-date';

const createServerInstance = async () => {
const db = dbFactory();
Expand Down Expand Up @@ -67,18 +69,18 @@ test('organization_meta updates automatically', async () => {
const { uri, instance, db } = await createServerInstance();
const query = `
query foo {
giver: organizationMetas(id: 3) {
countGrantsTo
countGrantsFrom
countDistinctFunders
countDistinctRecipients
}
receiver: organizationMetas(id: 91) {
countGrantsTo
countGrantsFrom
countDistinctFunders
countDistinctRecipients
}
giver: organization(id: 3) {
countGrantsTo
countGrantsFrom
countDistinctFunders
countDistinctRecipients
}
receiver: organization(id: 91) {
countGrantsTo
countGrantsFrom
countDistinctFunders
countDistinctRecipients
}
}`;

const resBefore = await request(uri, query);
Expand All @@ -98,40 +100,89 @@ query foo {

// Assert
expect(resBefore).toEqual({
giver: [
{
countGrantsTo: 0,
countGrantsFrom: 0,
countDistinctFunders: 0,
countDistinctRecipients: 0,
},
],
receiver: [
{
countGrantsTo: 17,
countGrantsFrom: 17,
countDistinctFunders: 17,
countDistinctRecipients: 17,
},
],
giver: {
countGrantsTo: 0,
countGrantsFrom: 0,
countDistinctFunders: 0,
countDistinctRecipients: 0,
},
receiver: {
countGrantsTo: 17,
countGrantsFrom: 17,
countDistinctFunders: 17,
countDistinctRecipients: 17,
},
});
expect(resAfter).toEqual({
giver: [
{
countGrantsTo: 0,
countGrantsFrom: 1,
countDistinctFunders: 0,
countDistinctRecipients: 1,
},
],
receiver: [
{
countGrantsTo: 18,
countGrantsFrom: 17,
countDistinctFunders: 18,
countDistinctRecipients: 17,
},
],
giver: {
countGrantsTo: 0,
countGrantsFrom: 1,
countDistinctFunders: 0,
countDistinctRecipients: 1,
},
receiver: {
countGrantsTo: 18,
countGrantsFrom: 17,
countDistinctFunders: 18,
countDistinctRecipients: 17,
},
});

instance.close();
});

test('filters organizations by name', async () => {
const { uri, instance } = await createServerInstance();

const res = await request(uri, orgNameLike.query);

expect(res).toEqual(orgNameLike.expected.data);

instance.close();
});

test('sorts organization grants by date', async () => {
const { uri, instance } = await createServerInstance();

const res = await request(uri, sortOrgGrantsByDate.query);

expect(res).toEqual(sortOrgGrantsByDate.expected.data);

instance.close();
});

test('filter organization grants funded/received by name', async () => {
const { uri, instance } = await createServerInstance();

const res = await request(
uri,
`
query filterOrganizationGrants {
organization(id: 91) {
grantsFunded(
limit: 10,
orderByDirection: ASC,
orderBy: dateFrom,
textLike: { description: "grant 2 description" }
) {
description
}
}
}
`
);

expect(res).toEqual({
organization: {
grantsFunded: [
{
description: 'grant 2 description',
},
{
description: 'grant 2 description',
},
],
},
});

instance.close();
Expand Down
19 changes: 7 additions & 12 deletions integration-tests/test-queries/more-meta.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
export const query = `
query foo {
organizationMetas(
organizations(
limit: 2
offset: 1
orderByMulti: [["countGrantsTo", "DESC"], ["id", "ASC"]]
orderBy: countGrantsTo
orderByDirection: DESC
) {
countGrantsTo
countGrantsFrom
countDistinctFunders
countDistinctRecipients
organization {
name
}
name
}
}
`;

export const expected = {
data: {
organizationMetas: [
organizations: [
{
countGrantsTo: 16,
countGrantsFrom: 16,
countDistinctFunders: 16,
countDistinctRecipients: 16,
organization: {
name: 'test organization 89',
},
name: 'test organization 89',
},
{
countGrantsTo: 16,
countGrantsFrom: 16,
countDistinctFunders: 16,
countDistinctRecipients: 16,
organization: {
name: 'test organization 91',
},
name: 'test organization 91',
},
],
},
Expand Down
25 changes: 25 additions & 0 deletions integration-tests/test-queries/org-name-like.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const query = `
query orgNameLike {
organizations(nameLike: "%organization 9%", limit: 11) {
name
}
}
`;

export const expected = {
data: {
organizations: [
{ name: 'test organization 9' },
{ name: 'test organization 90' },
{ name: 'test organization 91' },
{ name: 'test organization 92' },
{ name: 'test organization 93' },
{ name: 'test organization 94' },
{ name: 'test organization 95' },
{ name: 'test organization 96' },
{ name: 'test organization 97' },
{ name: 'test organization 98' },
{ name: 'test organization 99' },
],
},
};
Loading