Skip to content

Commit

Permalink
All tests pass again. Maybe prevent test timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
lperson committed Apr 28, 2024
1 parent 3fbe2b1 commit 974a051
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
9 changes: 6 additions & 3 deletions __test__/extensions/action-handlers/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import each from "jest-each";
import {
setupTest,
cleanupTest,
createStartedCampaign
createStartedCampaign,
flushRedis
} from "../../test_helpers";
const ActionHandlers = require("../../../src/extensions/action-handlers");
const uuidv4 = require("uuid").v4;
const TestAction = require("../../../src/extensions/action-handlers/test-action");
const ComplexTestAction = require("../../../src/extensions/action-handlers/complex-test-action");
const log = require("../../../src/lib").log;
const { log } = require("../../../src/lib");

describe("action-handlers/index", () => {
let organization;
Expand Down Expand Up @@ -39,6 +40,8 @@ describe("action-handlers/index", () => {
});

afterEach(async () => {
jest.restoreAllMocks();
await flushRedis();
const toReset = ["CACHE_PREFIX", "ACTION_HANDLERS"];

toReset.forEach(thingToReset => {
Expand Down Expand Up @@ -693,7 +696,7 @@ describe("action-handlers/index", () => {

describe("when the items property is not an array", () => {
beforeEach(async () => {
fakeAction.getClientChoiceData = () => ({
fakeAction.getClientChoiceData = async () => ({
data: JSON.stringify({ items: {} }),
expiresSeconds: 77
});
Expand Down
11 changes: 6 additions & 5 deletions __test__/server/api/mutations/updateServiceVendorConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
createOrganization,
createUser,
ensureOrganizationTwilioWithMessagingService,
flushRedis,
runGql,
setupTest
} from "../../../test_helpers";
Expand Down Expand Up @@ -84,7 +85,7 @@ describe("updateServiceVendorConfig", () => {
const dbOrganization = await Organization.get(organization.id);
dbOrganization.features = null;
await dbOrganization.save();
if (r.redis) r.redis.FLUSHDB();
await flushRedis();
});
it("returns an error", async () => {
const gqlResult = await runGql(updateServiceVendorConfigGql, vars, user);
Expand Down Expand Up @@ -160,7 +161,7 @@ describe("updateServiceVendorConfig", () => {
dbOrganization = await Organization.get(organization.id);
dbOrganization.features = JSON.stringify({ service: "twilio" });
await dbOrganization.save();
if (r.redis) r.redis.FLUSHDB();
await flushRedis();

expectedFeatures = {
service,
Expand Down Expand Up @@ -218,7 +219,7 @@ describe("updateServiceVendorConfig", () => {
[configKey]: "it doesn't matter"
});
await dbOrganization.save();
if (r.redis) r.redis.FLUSHDB();
await flushRedis();
});
it("writes message service config in features.configKey", async () => {
const gqlResult = await runGql(
Expand Down Expand Up @@ -248,7 +249,7 @@ describe("updateServiceVendorConfig", () => {
TWILIO_MESSAGE_SERVICE_SID: "the_former_fake_message_service_sid"
});
await dbOrganization.save();
if (r.redis) r.redis.FLUSHDB();
await flushRedis();
});
it("writes individual config components to the top level of features", async () => {
const gqlResult = await runGql(
Expand Down Expand Up @@ -280,7 +281,7 @@ describe("updateServiceVendorConfig", () => {
TWILIO_MESSAGE_SERVICE_SID: "the_former_fake_message_service_sid"
});
await dbOrganization.save();
if (r.redis) r.redis.FLUSHDB();
await flushRedis();

extremelyFakeService = {
updateConfig: jest.fn().mockImplementation(() => {
Expand Down
18 changes: 10 additions & 8 deletions __test__/test_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ export async function setupTest() {
await createTables();
}

export async function cleanupTest() {
await dropTables();
export async function flushRedis() {
if (r.redis) {
let needFlush = false;
for await (const key of r.redis.scanIterator({ COUNT: 1 })) {
needFlush = true;
}
if (needFlush) {
await r.redis.FLUSHDB();
for await (const key of r.redis.scanIterator({ MATCH: "*", COUNT: 1 })) {
r.redis.FLUSHDB();
}
}
}

export async function cleanupTest(doFlushRedis = true) {
await dropTables();
if (doFlushRedis) {
await flushRedis();
}
}

export function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Expand Down
6 changes: 3 additions & 3 deletions src/extensions/action-handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ export async function getActionChoiceData(actionHandler, organization, user) {
parsedData = {};
}

let items = parsedData.items;
if (items && !(items instanceof Array)) {
let { items } = parsedData;
if (items && !Array.isArray(items)) {
log.error(
`Data received from ${actionHandler.name}.getClientChoiceData is not an array`
s`Data received from ${actionHandler.name}.getClientChoiceData is not an array`
);
items = undefined;
}
Expand Down

0 comments on commit 974a051

Please sign in to comment.