Skip to content

Commit

Permalink
Remove support for running integration tests as smoke tests against a…
Browse files Browse the repository at this point in the history
… configured ORGANIZATION_ID. Explicitly create test data in test setup.
  • Loading branch information
asalant committed Nov 13, 2020
1 parent 45b44aa commit 81be36b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 49 deletions.
7 changes: 5 additions & 2 deletions __test__/cypress/integration/basic-campaign-e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import TestData from "../fixtures/test-data";

describe("End-to-end campaign flow", () => {
before(() => {
// ensure texter one exists so they can be assigned
cy.task("createOrUpdateUser", TestData.users.texter1);
cy.task("getOrCreateTestOrganization").then(org => {
cy.task("createOrUpdateUser", { userData: TestData.users.admin1, org });
// ensure texter one exists so they can be assigned
cy.task("createOrUpdateUser", { userData: TestData.users.texter1, org });
});
});

it("with an assigned texter", () => {
Expand Down
14 changes: 10 additions & 4 deletions __test__/cypress/integration/phone-inventory.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import TestData from "../fixtures/test-data";

if (Cypress.env("DEFAULT_SERVICE") === "fakeservice") {
describe("Phone number management screen in the Admin interface", () => {
const testAreaCode = "212";

beforeEach(() => {
cy.task("clearTestOrgPhoneNumbers", testAreaCode);
cy.login("admin1");
cy.visit("/admin/1/phone-numbers");
before(() => {
cy.task("getOrCreateTestOrganization").then(org => {
cy.task("createOrUpdateUser", { userData: TestData.users.admin1, org });
cy.task("clearTestOrgPhoneNumbers", { areaCode: testAreaCode, org });
});
});

it("shows numbers by area code and allows OWNERs to buy more", () => {
cy.login("admin1");
cy.visit("/admin/1/phone-numbers");

cy.get("th").contains("Area Code");
cy.get("th").contains("Allocated");
cy.get("th").contains("Available");
Expand Down
14 changes: 9 additions & 5 deletions __test__/cypress/integration/user-edit.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import testData from "../fixtures/test-data";
import TestData from "../fixtures/test-data";

describe("The user edit screen", () => {
beforeEach(() => {
cy.login("admin1");
cy.visit("/");
before(() => {
cy.task("getOrCreateTestOrganization").then(org => {
cy.task("createOrUpdateUser", { userData: TestData.users.admin1, org });
});
});

it("displays the current user's and allows them to edit it", () => {
const userDetails = testData.users.admin1;
cy.login("admin1");
cy.visit("/");

const userDetails = TestData.users.admin1;
cy.get("[data-test=userMenuButton]").click();
cy.get("[data-test=userMenuDisplayName]").click();
cy.get("input[data-test=email]").should("have.value", userDetails.email);
Expand Down
6 changes: 0 additions & 6 deletions __test__/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ if (process.env.DB_TYPE !== "pg") {
}

const makeTasks = require("./tasks").makeTasks;
const utils = require("./utils");

module.exports = async (on, config) => {
if (!config.env.TEST_ORGANIZATION_ID) {
const org = await utils.getOrCreateTestOrganization();
config.env.TEST_ORGANIZATION_ID = org.id;
}

// TODO: use the API to determine what service is being used rather
// than relying on .env.
config.env.DEFAULT_SERVICE = process.env.DEFAULT_SERVICE;
Expand Down
31 changes: 25 additions & 6 deletions __test__/cypress/plugins/tasks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uuid from "uuid";
import { r, User } from "../../../src/server/models";
import AuthHasher from "passport-local-authenticate";

Expand All @@ -8,10 +9,28 @@ import AuthHasher from "passport-local-authenticate";
*/
export function makeTasks(config) {
return {
getOrCreateTestOrganization: async () => {
const defaultOrganizationName = "E2E Test Organization";
let org = await r
.knex("organization")
.where("name", defaultOrganizationName)
.first();

if (org) return org;

await r.knex("organization").insert({
name: defaultOrganizationName,
uuid: uuid.v4(),
features: JSON.stringify({ EXPERIMENTAL_PHONE_INVENTORY: true })
});

return await getOrCreateTestOrganization();
},

/**
* Create a user and add it to the test organization with the specified role.
*/
createOrUpdateUser: async userData => {
createOrUpdateUser: async ({ userData, org }) => {
let user = await r
.knex("user")
.where("email", userData.email)
Expand Down Expand Up @@ -39,34 +58,34 @@ export function makeTasks(config) {
const role = await r
.knex("user_organization")
.where({
organization_id: config.env.TEST_ORGANIZATION_ID,
organization_id: org.id,
user_id: user.id
})
.first();

if (!role) {
await r.knex("user_organization").insert({
user_id: user.id,
organization_id: config.env.TEST_ORGANIZATION_ID,
organization_id: org.id,
role: userData.role
});
}

if (role !== userData.role) {
await r
.knex("user_organization")
.where({ organization_id: config.env.TEST_ORGANIZATION_ID })
.where({ organization_id: org.id })
.update({ role: userData.role });
}

return user.id;
},

clearTestOrgPhoneNumbers: async areaCode => {
clearTestOrgPhoneNumbers: async ({ areaCode, org }) => {
await r
.knex("owned_phone_number")
.where({
organization_id: config.env.TEST_ORGANIZATION_ID,
organization_id: org.id,
service: "fakeservice",
area_code: areaCode
})
Expand Down
21 changes: 0 additions & 21 deletions __test__/cypress/plugins/utils.js

This file was deleted.

1 change: 0 additions & 1 deletion __test__/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Cypress.Commands.add("login", testDataId => {
throw Error(`Unknown test user ${testDataId}`);
}

cy.task("createOrUpdateUser", userData);
cy.request("POST", "/login-callback", {
nextUrl: "/",
authType: "login",
Expand Down
5 changes: 1 addition & 4 deletions cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@
"pluginsFile": "__test__/cypress/plugins/index.js",
"supportFile": "__test__/cypress/support/index.js",
"testFiles": "*.test.js",
"video": true,
"env": {
"TEST_ORGANIZATION_ID": null
}
"video": true
}

0 comments on commit 81be36b

Please sign in to comment.