Skip to content

Commit

Permalink
Merge pull request #33 from detroitledger/32-filter-org-grants
Browse files Browse the repository at this point in the history
filter org grants
  • Loading branch information
bnchdrff authored Sep 20, 2019
2 parents 5dc6f8f + 537bf90 commit df50e84
Show file tree
Hide file tree
Showing 17 changed files with 1,696 additions and 873 deletions.
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

0 comments on commit df50e84

Please # to comment.