From 9ce5253f1769a1500e8e530d331821bfc6f4db5a Mon Sep 17 00:00:00 2001 From: Kathy Nguyen Date: Mon, 14 Nov 2022 14:39:37 -0800 Subject: [PATCH] Update jest --- .babelrc | 1 + __test__/backend.test.js | 4 ++-- .../AssignmentTexter/ContactController.test.js | 2 +- .../ConversationPreviewModal.test.js | 4 ++-- __test__/components/ScriptEditor.test.js | 2 +- .../integration/basic-campaign-e2e.test.js | 2 +- .../action-handlers/action-network.test.js | 2 +- .../action-handlers/ngpvan-action.test.js | 2 +- .../action-handlers/zapier-action.test.js | 4 ++-- .../contact-loaders/csv-upload.test.js | 4 ++-- __test__/server/api/campaign/campaign.test.js | 16 ++++++++-------- .../campaign/updateQuestionResponses.test.js | 6 +++--- __test__/server/api/editOrganization.test.js | 2 +- __test__/server/api/organization.test.js | 6 +++--- __test__/server/api/people.test.js | 10 +++++----- __test__/server/api/user.test.js | 2 +- __test__/server/lib/http-request.test.js | 14 ++++++++------ .../models/cacheable_queries/user.test.js | 2 +- .../server/models/question-response.test.js | 2 +- __test__/server/texter.test/common.js | 4 +--- __test__/workers/parse_csv.test.js | 17 +++++++++-------- jest.config.js | 2 +- .../20210220144200_organization_contacts.js | 2 +- package.json | 6 ++++-- .../AssignmentTexter/ContactController.jsx | 8 ++++---- src/containers/TexterTodo.jsx | 2 -- src/network/apollo-client-singleton.js | 1 + 27 files changed, 66 insertions(+), 63 deletions(-) diff --git a/.babelrc b/.babelrc index db06a8066..ec06c8d2a 100644 --- a/.babelrc +++ b/.babelrc @@ -2,6 +2,7 @@ "presets": ["@babel/preset-react", "@babel/preset-env", ["@babel/preset-typescript", { "allExtensions": true, "isTSX": true }]], "only": ["./**/*.js", "./**/*.jsx"], "plugins": [ + "@babel/plugin-proposal-export-default-from", ["@babel/plugin-transform-runtime", { "regenerator": true }] diff --git a/__test__/backend.test.js b/__test__/backend.test.js index c306c3c1b..8d7737bc0 100644 --- a/__test__/backend.test.js +++ b/__test__/backend.test.js @@ -175,7 +175,7 @@ async function createCampaign(user, title, description, organizationId) { // graphQL tests -describe("graphql test suite", async () => { +describe("graphql test suite", () => { beforeAll( async () => await setupTest(), global.DATABASE_SETUP_TEARDOWN_TIMEOUT @@ -352,7 +352,7 @@ describe("graphql test suite", async () => { }).save(); }); - describe("contacts", async () => { + describe("contacts", () => { let campaigns; let contacts; beforeEach(async () => { diff --git a/__test__/components/AssignmentTexter/ContactController.test.js b/__test__/components/AssignmentTexter/ContactController.test.js index b9e95e3d5..80d3267a4 100644 --- a/__test__/components/AssignmentTexter/ContactController.test.js +++ b/__test__/components/AssignmentTexter/ContactController.test.js @@ -62,7 +62,7 @@ function genComponent(assignment, propertyOverrides = {}) { return wrapper; } -describe("ContactController process flows", async () => { +describe("ContactController process flows", () => { it("Normal nondynamic assignment queue", async () => { const assignment = genAssignment( false, diff --git a/__test__/components/IncomingMessageList/ConversationPreviewModal.test.js b/__test__/components/IncomingMessageList/ConversationPreviewModal.test.js index 35c257b60..ebf6018ad 100644 --- a/__test__/components/IncomingMessageList/ConversationPreviewModal.test.js +++ b/__test__/components/IncomingMessageList/ConversationPreviewModal.test.js @@ -24,7 +24,7 @@ import { createStartedCampaign } from "../../test_helpers"; -describe.skip("ConversationPreviewModal", async () => { +describe.skip("ConversationPreviewModal", () => { let startedCampaign; let optOutContact; let optOut; @@ -80,7 +80,7 @@ describe.skip("ConversationPreviewModal", async () => { if (r.redis) r.redis.flushdb(); }, global.DATABASE_SETUP_TEARDOWN_TIMEOUT); - describe("when a message review user opts out a user", async () => { + describe("when a message review user opts out a user", () => { beforeAll(async () => { const root = document.createElement("div"); document.body.appendChild(root); diff --git a/__test__/components/ScriptEditor.test.js b/__test__/components/ScriptEditor.test.js index 99148f115..c932cf72f 100644 --- a/__test__/components/ScriptEditor.test.js +++ b/__test__/components/ScriptEditor.test.js @@ -5,7 +5,7 @@ import { Editor } from "draft-js"; import ScriptEditor from "../../src/components/ScriptEditor"; import { sleep } from "../test_helpers"; -describe("ScriptEditor component", async () => { +describe("ScriptEditor component", () => { test("re-encodes unicode easy-wins for GSM", () => { const wrapper = shallow( { }); cy.get("button[data-test=send]") .eq(0) - .click(); + .click({ waitForAnimations: false }); // Turn off animation wait to prevent false positive error // Shows we're done and click back to /todos cy.get("body").contains("You've messaged all your assigned contacts."); diff --git a/__test__/extensions/action-handlers/action-network.test.js b/__test__/extensions/action-handlers/action-network.test.js index 271054bbb..7eeccf79c 100644 --- a/__test__/extensions/action-handlers/action-network.test.js +++ b/__test__/extensions/action-handlers/action-network.test.js @@ -36,7 +36,7 @@ describe("action-network", () => { }; }); - describe("#getClientChoiceData", async () => { + describe("#getClientChoiceData", () => { let makeGetEventsNock; let makeGetTagsNock; let getEventsNock; diff --git a/__test__/extensions/action-handlers/ngpvan-action.test.js b/__test__/extensions/action-handlers/ngpvan-action.test.js index 02a4a9ee7..4f5e5fbaf 100644 --- a/__test__/extensions/action-handlers/ngpvan-action.test.js +++ b/__test__/extensions/action-handlers/ngpvan-action.test.js @@ -34,7 +34,7 @@ describe("ngpvn-action", () => { ).not.toThrowError(); }); - describe("#getClientChoiceData", async () => { + describe("#getClientChoiceData", () => { let makeGetSurveyQuestionsNock; let makeGetActivistCodesNock; let makeGetCanvassResponsesResultCodesNock; diff --git a/__test__/extensions/action-handlers/zapier-action.test.js b/__test__/extensions/action-handlers/zapier-action.test.js index 696565904..f2bf0cef8 100644 --- a/__test__/extensions/action-handlers/zapier-action.test.js +++ b/__test__/extensions/action-handlers/zapier-action.test.js @@ -54,7 +54,7 @@ describe("zapier-action", () => { expect(ret2.result).toBe(true); }); - describe("#onTagUpdate", async () => { + describe("#onTagUpdate", () => { it("should bail if ZAPIER_WEBHOOK_URL is undefined", async () => { process.env.ZAPIER_WEBHOOK_URL = undefined; const ret = await ZapierAction.onTagUpdate(null, null, null, null, null); @@ -375,7 +375,7 @@ describe("zapier-action", () => { }); }); - describe("#processAction", async () => { + describe("#processAction", () => { let questionResponse; let interactionStep; let campaignContactId; diff --git a/__test__/extensions/contact-loaders/csv-upload.test.js b/__test__/extensions/contact-loaders/csv-upload.test.js index fe41548c4..9556837f5 100644 --- a/__test__/extensions/contact-loaders/csv-upload.test.js +++ b/__test__/extensions/contact-loaders/csv-upload.test.js @@ -68,7 +68,7 @@ const dupeContacts = [ } ]; -describe("ingest-contact-loader method: csv-upload backend", async () => { +describe("ingest-contact-loader method: csv-upload backend", () => { let testAdminUser; let testInvite; let testOrganization; @@ -141,7 +141,7 @@ describe("ingest-contact-loader method: csv-upload backend", async () => { }); }); -describe("ingest-contact-loader method: csv-upload frontend", async () => { +describe("ingest-contact-loader method: csv-upload frontend", () => { let didSubmit = false; let changeData = null; const onSubmit = () => { diff --git a/__test__/server/api/campaign/campaign.test.js b/__test__/server/api/campaign/campaign.test.js index dd7ebbac8..7dd6f5a7b 100644 --- a/__test__/server/api/campaign/campaign.test.js +++ b/__test__/server/api/campaign/campaign.test.js @@ -407,7 +407,7 @@ it("should save campaign canned responses across copies and match saved data", a } }); -describe("Caching", async () => { +describe("Caching", () => { if (r.redis && getConfig("REDIS_CONTACT_CACHE")) { it("should not have any selects on a cached campaign when message sending", async () => { await createScript(testAdminUser, testCampaign); @@ -433,7 +433,7 @@ describe("Caching", async () => { } }); -describe("Reassignments", async () => { +describe("Reassignments", () => { it("should allow reassignments before campaign start", async () => { // - user gets assignment todos // - assignments are changed in different ways (with different mutations) @@ -843,7 +843,7 @@ describe("Reassignments", async () => { }, 10000); // long test can exceed default 5seconds }); -describe("Bulk Send", async () => { +describe("Bulk Send", () => { const OLD_ENV = process.env; beforeEach(async () => { @@ -1016,7 +1016,7 @@ describe("Bulk Send", async () => { }); }); -describe("campaigns query", async () => { +describe("campaigns query", () => { let testCampaign2; const cursor = { @@ -1212,7 +1212,7 @@ describe("all interaction steps fields travel round trip", () => { }); }); -describe("useOwnMessagingService", async () => { +describe("useOwnMessagingService", () => { const oldEnv = process.env; beforeEach(async () => { await ensureOrganizationTwilioWithMessagingService( @@ -1290,7 +1290,7 @@ describe("useOwnMessagingService", async () => { }); }); -describe("per-campaign phone numbers", async () => { +describe("per-campaign phone numbers", () => { const oldEnv = process.env; beforeAll(() => { process.env = { @@ -1306,7 +1306,7 @@ describe("per-campaign phone numbers", async () => { }); it("allocates numbers to a campaign and creates a messaging service on start", async () => { - const [phoneId] = await r.knex("owned_phone_number").insert( + const [res] = await r.knex("owned_phone_number").insert( { organization_id: organizationId, service: "fakeservice", @@ -1327,7 +1327,7 @@ describe("per-campaign phone numbers", async () => { const phoneNumber = await r .knex("owned_phone_number") - .where("id", phoneId) + .where("id", res.id) .first(); expect(phoneNumber.allocated_to).toEqual("campaign"); expect(phoneNumber.allocated_to_id).toEqual(testCampaign.id.toString()); diff --git a/__test__/server/api/campaign/updateQuestionResponses.test.js b/__test__/server/api/campaign/updateQuestionResponses.test.js index 081456da7..7073188a5 100644 --- a/__test__/server/api/campaign/updateQuestionResponses.test.js +++ b/__test__/server/api/campaign/updateQuestionResponses.test.js @@ -641,7 +641,7 @@ describe("mutations.updateQuestionResponses", () => { }); }); - describe("when some of the steps have an action handler", async () => { + describe("when some of the steps have an action handler", () => { beforeEach(async () => { expect.extend({ objectWithId: (received, expectedObject) => { @@ -703,7 +703,7 @@ describe("mutations.updateQuestionResponses", () => { expect(ActionHandlers.rawAllActionHandlers).toHaveBeenCalledTimes(1); expect(ActionHandlers.rawAllActionHandlers.mock.results).toEqual([ { - isThrow: false, + type: "return", value: { "complex-test-action": expect.objectContaining({ name: "complex-test-action" @@ -958,7 +958,7 @@ describe("mutations.updateQuestionResponses", () => { }); }); - describe("when no action handlers are configured", async () => { + describe("when no action handlers are configured", () => { beforeEach(async () => { ({ interactionSteps, diff --git a/__test__/server/api/editOrganization.test.js b/__test__/server/api/editOrganization.test.js index 6b17043e7..e244cebc6 100644 --- a/__test__/server/api/editOrganization.test.js +++ b/__test__/server/api/editOrganization.test.js @@ -12,7 +12,7 @@ import { setupTest } from "../../test_helpers"; -describe("editOrganization", async () => { +describe("editOrganization", () => { let startedCampaign; beforeEach(async () => { diff --git a/__test__/server/api/organization.test.js b/__test__/server/api/organization.test.js index a54411c7d..d75c116cf 100644 --- a/__test__/server/api/organization.test.js +++ b/__test__/server/api/organization.test.js @@ -22,7 +22,7 @@ import * as serviceMap from "../../../src/extensions/service-vendors/service_map const ActionHandlerFramework = require("../../../src/extensions/action-handlers"); -describe("organization", async () => { +describe("organization", () => { let testTexterUser; let testAdminUser; let testInvite; @@ -52,7 +52,7 @@ describe("organization", async () => { if (r.redis) r.redis.flushdb(); }, global.DATABASE_SETUP_TEARDOWN_TIMEOUT); - describe("organization query", async () => { + describe("organization query", () => { let testCampaign2; let testCampaign3; let testCampaign4; @@ -141,7 +141,7 @@ describe("organization", async () => { ]); }); - describe("sorts", async () => { + describe("sorts", () => { const runTest = async (sortBy, expectedOrderedIds) => { variables.sortBy = sortBy; const result = await runGql( diff --git a/__test__/server/api/people.test.js b/__test__/server/api/people.test.js index aef026ef3..3496f4209 100644 --- a/__test__/server/api/people.test.js +++ b/__test__/server/api/people.test.js @@ -17,7 +17,7 @@ import { runGql } from "../../test_helpers"; -describe("people", async () => { +describe("people", () => { let testTexterUsers; let testAdminUsers; let testContacts; @@ -189,7 +189,7 @@ describe("people", async () => { if (r.redis) r.redis.flushdb(); }, global.DATABASE_SETUP_TEARDOWN_TIMEOUT); - describe("filtering", async () => { + describe("filtering", () => { const testFiltering = async (result, expectedUsers) => { expect(result.data.people.users.length).toEqual(expectedUsers.length); @@ -356,7 +356,7 @@ describe("people", async () => { }); }); - describe("sorting", async () => { + describe("sorting", () => { const testSortResults = async (result, expectedUsers) => { expect(result.data.people.users.length).toEqual(expectedUsers.length); @@ -422,7 +422,7 @@ describe("people", async () => { }); }); - describe("pagination", async () => { + describe("pagination", () => { beforeEach(async () => { cursor = { offset: 0, @@ -471,7 +471,7 @@ describe("people", async () => { }); }); - describe("permissions", async () => { + describe("permissions", () => { it("doesn't allow texter users to retrieve people", async () => { const result = await runGql(getUsersGql, variables, testTexterUsers[0]); expect(result.errors).toEqual([ diff --git a/__test__/server/api/user.test.js b/__test__/server/api/user.test.js index 687e13861..d3f1391fa 100644 --- a/__test__/server/api/user.test.js +++ b/__test__/server/api/user.test.js @@ -27,7 +27,7 @@ describe("User", () => { }).save(); }); - describe("getUsers", async () => { + describe("getUsers", () => { it("returns pageInfo.total == user.length when there's a cursor", async () => { const users = [ await new User({ diff --git a/__test__/server/lib/http-request.test.js b/__test__/server/lib/http-request.test.js index 4cef8a749..f1a4694c8 100644 --- a/__test__/server/lib/http-request.test.js +++ b/__test__/server/lib/http-request.test.js @@ -3,7 +3,7 @@ import nock from "nock"; import requestWithRetry from "../../../src/server/lib/http-request.js"; -describe("requestWithRetry", async () => { +describe("requestWithRetry", () => { let url; let path; let headers; @@ -51,7 +51,7 @@ describe("requestWithRetry", async () => { nocked.done(); }); - describe("validate status", async () => { + describe("validate status", () => { let nocked; beforeEach(async () => { nocked = nock(url, { @@ -62,7 +62,7 @@ describe("requestWithRetry", async () => { .reply(201, "Nevertheless it was persisted."); }); - describe("successful status validation", async () => { + describe("successful status validation", () => { it("validStatuses is provided", async () => { const result = await requestWithRetry(`${url}${path}`, { method: "POST", @@ -90,7 +90,7 @@ describe("requestWithRetry", async () => { }); }); - describe("unsuccessful status validation", async () => { + describe("unsuccessful status validation", () => { it("validStatuses is provided", async () => { let error; @@ -137,7 +137,7 @@ describe("requestWithRetry", async () => { }); }); - describe("when the request times out", async () => { + describe("when the request times out", () => { it("retries", async () => { let error; const nocked = nock(url) @@ -199,10 +199,11 @@ describe("requestWithRetry", async () => { /Error: Request id .+ failed; timeout after 500ms/ ); nocked.done(); + nock.abortPendingRequests(); // Close open Jest handle due to timeout } }); - describe("when retries is 0", async () => { + describe("when retries is 0", () => { let error; it("it doesn't retry", async () => { const nocked = nock(url) @@ -241,6 +242,7 @@ describe("requestWithRetry", async () => { /Error: Request id .+ failed; timeout after 100ms/ ); nocked.done(); + nock.abortPendingRequests(); // Close open Jest handle due to timeout } }); }); diff --git a/__test__/server/models/cacheable_queries/user.test.js b/__test__/server/models/cacheable_queries/user.test.js index 4045725ef..664327324 100644 --- a/__test__/server/models/cacheable_queries/user.test.js +++ b/__test__/server/models/cacheable_queries/user.test.js @@ -9,7 +9,7 @@ import { import { r, cacheableData } from "../../../../src/server/models"; -describe("cacheable_queries.user", async () => { +describe("cacheable_queries.user", () => { let queryLog; let testAdminUser; let testInvite; diff --git a/__test__/server/models/question-response.test.js b/__test__/server/models/question-response.test.js index a637d347a..69fbc256c 100644 --- a/__test__/server/models/question-response.test.js +++ b/__test__/server/models/question-response.test.js @@ -7,7 +7,7 @@ import { } from "../../test_helpers"; import { r, cacheableData } from "../../../src/server/models"; -describe("questionResponse cacheableData methods", async () => { +describe("questionResponse cacheableData methods", () => { let initData; beforeEach(async () => { await setupTest(); diff --git a/__test__/server/texter.test/common.js b/__test__/server/texter.test/common.js index 11cb212db..8b5fd6f86 100644 --- a/__test__/server/texter.test/common.js +++ b/__test__/server/texter.test/common.js @@ -58,7 +58,5 @@ export { testTexterUser2, testContacts, testContact, - assignmentId, - beforeEach, - afterEach + assignmentId }; diff --git a/__test__/workers/parse_csv.test.js b/__test__/workers/parse_csv.test.js index c1887faa1..af76aeb5b 100644 --- a/__test__/workers/parse_csv.test.js +++ b/__test__/workers/parse_csv.test.js @@ -34,14 +34,15 @@ describe("#parseCSVAsync", () => { "givenName,surName,mobile,postal\r\nJerome,Garcia,14155551212,94970"; }); - it("throws an exception", async done => { - try { - await parseCSVAsync(csv); - } catch (error) { - expect(error).toEqual("Missing fields: firstName, lastName, cell"); - return done(); - } - return done("didn't raise an error"); // this will cause the test to fail + it("throws an exception", done => { + parseCSVAsync(csv) + .then(() => { + return done("didn't raise an error"); // this will cause the test to fail + }) + .catch(error => { + expect(error).toEqual("Missing fields: firstName, lastName, cell"); + return done(); + }); }); }); }); diff --git a/jest.config.js b/jest.config.js index d95f42db7..288827de3 100644 --- a/jest.config.js +++ b/jest.config.js @@ -46,7 +46,7 @@ module.exports = { "!**/deploy/**", "!**/coverage/**" ], - setupTestFrameworkScriptFile: "/__test__/setup.js", + setupFilesAfterEnv: ["/__test__/setup.js"], testPathIgnorePatterns: [ "/node_modules/", "/__test__/cypress/" diff --git a/migrations/20210220144200_organization_contacts.js b/migrations/20210220144200_organization_contacts.js index 4c7857698..47a6e53f4 100644 --- a/migrations/20210220144200_organization_contacts.js +++ b/migrations/20210220144200_organization_contacts.js @@ -29,7 +29,7 @@ exports.up = async function up(knex) { t.integer("last_error_code"); t.text("carrier"); t.timestamp("created_at").defaultTo(knex.fn.now()); - t.timestamp("last_lookup").defaultTo(); + t.timestamp("last_lookup").defaultTo(null); t.text("lookup_name"); t.index( diff --git a/package.json b/package.json index 60b9225a7..ef6ecd249 100644 --- a/package.json +++ b/package.json @@ -107,6 +107,7 @@ "babel-polyfill": "^6.26.0", "babel-runtime": "^6.26.0", "body-parser": "^1.15.2", + "browserify": "^17.0.0", "camelcase-keys": "^4.1.0", "color-difference": "^0.3.4", "cookie-session": "^2.0.0-alpha.1", @@ -169,7 +170,8 @@ }, "devDependencies": { "@babel/eslint-parser": "^7.19.1", - "babel-jest": "^23.4.2", + "@babel/plugin-proposal-export-default-from": "^7.18.10", + "babel-jest": "^29.3.1", "babel-preset-es2017": "^6.24.1", "cypress": "5.6.0", "cypress-file-upload": "^4.0.6", @@ -193,7 +195,7 @@ "nodemon": "^2.0.2", "prettier": "^1.18.2", "react-hot-loader": "4.13.0", - "react-scripts": "^2.1.3", + "react-scripts": "^5.0.1", "react-test-renderer": "16", "regenerator-runtime": "^0.10.5", "selenium-webdriver": "^3.6.0", diff --git a/src/components/AssignmentTexter/ContactController.jsx b/src/components/AssignmentTexter/ContactController.jsx index 7203077f3..d505f8d8d 100644 --- a/src/components/AssignmentTexter/ContactController.jsx +++ b/src/components/AssignmentTexter/ContactController.jsx @@ -1,3 +1,4 @@ +import AssignmentTexterContact from "../../containers/AssignmentTexterContact"; import PropTypes from "prop-types"; import theme from "../../styles/theme"; import React from "react"; @@ -382,7 +383,7 @@ export class ContactController extends React.Component { } renderTexter(enabledSideboxes) { - const { assignment, campaign, ChildComponent } = this.props; + const { assignment, campaign } = this.props; const { texter } = assignment; const contact = this.currentContact(); const navigationToolbarChildren = this.getNavigationToolbarChildren(); @@ -439,9 +440,9 @@ export class ContactController extends React.Component { }, self.state.reloadDelay); return ; } - // ChildComponent is AssignmentTexterContact except for demo/testing + return ( - diff --git a/src/network/apollo-client-singleton.js b/src/network/apollo-client-singleton.js index b5aae6d00..d100c3e29 100644 --- a/src/network/apollo-client-singleton.js +++ b/src/network/apollo-client-singleton.js @@ -8,6 +8,7 @@ import { getMainDefinition } from "apollo-utilities"; import omitDeep from "omit-deep-lodash"; const httpLink = createHttpLink({ + fetch: fetch, uri: (typeof window === "undefined" ? process.env : window).GRAPHQL_URL || "/graphql",