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

Paginated, searchable people page with other enhancements #1345

Merged
merged 11 commits into from
May 28, 2020
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
90 changes: 89 additions & 1 deletion __test__/backend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@ import {
UserOrganization
} from "../src/server/models/";
import { resolvers as campaignResolvers } from "../src/server/api/campaign";
import { getContext, setupTest, cleanupTest } from "./test_helpers";
import {
setupTest,
cleanupTest,
getContext,
createUser as helperCreateUser,
createTexter as helperCreateTexter,
createOrganization as helperCreateOrganization,
createInvite as helperCreateInvite,
runGql
} from "./test_helpers";
import { makeExecutableSchema } from "graphql-tools";

import { editUserMutation } from "../src/containers/UserEdit.jsx";

const mySchema = makeExecutableSchema({
typeDefs: schema,
resolvers,
Expand Down Expand Up @@ -697,3 +708,80 @@ describe("Campaign", () => {
});
});
});

describe.only("editUser mutation", () => {
let testAdminUser;
let testTexter;
let testOrganization;
let organizationId;
let variables;

beforeEach(async () => {
await setupTest();
testAdminUser = await helperCreateUser();
testOrganization = await helperCreateOrganization(
testAdminUser,
await helperCreateInvite()
);
organizationId = testOrganization.data.createOrganization.id;
testTexter = await helperCreateTexter(testOrganization);

variables = {
organizationId,
userId: testTexter.id,
userData: null
};
}, global.DATABASE_SETUP_TEARDOWN_TIMEOUT);

afterEach(async () => {
await cleanupTest();
if (r.redis) r.redis.flushdb();
}, global.DATABASE_SETUP_TEARDOWN_TIMEOUT);

it("returns the user if it is called with a userId by no userData", async () => {
const result = await runGql(editUserMutation, variables, testAdminUser);
expect(result).toEqual({
data: {
editUser: {
id: "2",
firstName: "TestTexterFirst",
lastName: "TestTexterLast",
cell: "555-555-6666",
email: "testtexter@example.com"
}
}
});
});

it("updates the user if it is called with a userId and userData", async () => {
const userData = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amusing test user :)

firstName: "Jerry",
lastName: "Garcia",
email: "jerry@heaven.org",
cell: "4151111111"
};

variables.userData = userData;

// the mutation returns the right thing
const result = await runGql(editUserMutation, variables, testAdminUser);
expect(result).toEqual({
data: {
editUser: {
...userData,
id: testTexter.id.toString()
}
}
});

// it gets updated in the database
const updatedUser = await r.knex("user").where("id", testTexter.id);
expect(updatedUser[0]).toMatchObject({
first_name: userData.firstName,
last_name: userData.lastName,
email: userData.email,
cell: userData.cell,
id: testTexter.id
});
});
});
193 changes: 193 additions & 0 deletions __test__/server/api/organization.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/* eslint-disable no-unused-expressions, consistent-return */
import { r } from "../../../src/server/models/";
import { getCampaignsQuery } from "../../../src/containers/CampaignList";
import { GraphQLError } from "graphql/error";

import {
setupTest,
cleanupTest,
createUser,
createInvite,
createOrganization,
createCampaign,
createTexter,
runGql
} from "../../test_helpers";

describe("organization", async () => {
let testTexterUser;
let testAdminUser;
let testInvite;
let testOrganization;
let testCampaign;
let organizationId;

beforeEach(async () => {
// Set up an entire working campaign
await setupTest();
testAdminUser = await createUser();
testInvite = await createInvite();
testOrganization = await createOrganization(testAdminUser, testInvite);
organizationId = testOrganization.data.createOrganization.id;
testCampaign = await createCampaign(
testAdminUser,
testOrganization,
"Apples",
{ dueBy: new Date(2019, 11, 31) }
);
testTexterUser = await createTexter(testOrganization);
}, global.DATABASE_SETUP_TEARDOWN_TIMEOUT);

afterEach(async () => {
await cleanupTest();
if (r.redis) r.redis.flushdb();
}, global.DATABASE_SETUP_TEARDOWN_TIMEOUT);

describe("organization.campaigns", async () => {
let testCampaign2;
let testCampaign3;
let testCampaign4;
let variables;
let cursor;

beforeEach(async () => {
testCampaign2 = await createCampaign(
testAdminUser,
testOrganization,
"Oranges",
{ dueBy: new Date(2019, 11, 30) }
);
testCampaign3 = await createCampaign(
testAdminUser,
testOrganization,
"Apples and Oranges",
{ dueBy: new Date(2019, 11, 29) }
);
testCampaign4 = await createCampaign(
testAdminUser,
testOrganization,
"Banana",
{ dueBy: new Date(2019, 11, 28) }
);

cursor = {
offset: 0,
limit: 1000
};

variables = {
cursor,
organizationId
};
});

it("filters by a single campaign id", async () => {
const campaignsFilter = {
campaignId: testCampaign.id
};
variables.campaignsFilter = campaignsFilter;

const result = await runGql(getCampaignsQuery, variables, testAdminUser);
expect(result.data.organization.campaigns.campaigns.length).toEqual(1);
expect(result.data.organization.campaigns.campaigns[0].id).toEqual(
testCampaign.id
);
});

it("filter by more than one campaign id", async () => {
const campaignsFilter = {
campaignIds: [testCampaign.id, testCampaign2.id]
};
variables.campaignsFilter = campaignsFilter;

const result = await runGql(getCampaignsQuery, variables, testAdminUser);
expect(result.data.organization.campaigns.campaigns.length).toEqual(2);

const returnedIds = result.data.organization.campaigns.campaigns.map(
campaign => campaign.id
);
expect(returnedIds).toContain(testCampaign.id);
expect(returnedIds).toContain(testCampaign2.id);
});

it("filters by search string", async () => {
const campaignsFilter = {
searchString: "oranges"
};
variables.campaignsFilter = campaignsFilter;

const result = await runGql(getCampaignsQuery, variables, testAdminUser);
expect(result.data.organization.campaigns.campaigns.length).toEqual(2);

const returnedIds = result.data.organization.campaigns.campaigns.map(
campaign => campaign.id
);
expect(returnedIds).toContain(testCampaign2.id);
expect(returnedIds).toContain(testCampaign3.id);
});

it("regular texters don't have permission", async () => {
const result = await runGql(getCampaignsQuery, variables, testTexterUser);
expect(result.errors).toEqual([
new GraphQLError("You are not authorized to access that resource.")
]);
});

describe("sorts", async () => {
const runTest = async (sortBy, expectedOrderedIds) => {
variables.sortBy = sortBy;
const result = await runGql(
getCampaignsQuery,
variables,
testAdminUser
);
expect(result.data.organization.campaigns.campaigns.length).toEqual(4);
const returnedIds = result.data.organization.campaigns.campaigns.map(
campaign => campaign.id
);
expect(returnedIds).toEqual(expectedOrderedIds);
};

it("sorts by due date ascending", async () => {
await runTest("DUE_DATE_ASC", [
testCampaign4.id,
testCampaign3.id,
testCampaign2.id,
testCampaign.id
]);
});
it("sorts by due date descending", async () => {
await runTest("DUE_DATE_DESC", [
testCampaign.id,
testCampaign2.id,
testCampaign3.id,
testCampaign4.id
]);
});
it("sorts by id ascending", async () => {
await runTest("ID_ASC", [
testCampaign.id,
testCampaign2.id,
testCampaign3.id,
testCampaign4.id
]);
});
it("sorts by id desc", async () => {
await runTest("ID_DESC", [
testCampaign4.id,
testCampaign3.id,
testCampaign2.id,
testCampaign.id
]);
});
it("sorts by title", async () => {
await runTest("TITLE", [
testCampaign.id,
testCampaign3.id,
testCampaign4.id,
testCampaign2.id
]);
});
});
});
});
Loading