Skip to content

Commit

Permalink
♻️ refactor(form-actions): split integrations API from form-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Jan 19, 2024
1 parent c7c3607 commit 18694fc
Show file tree
Hide file tree
Showing 78 changed files with 350 additions and 385 deletions.
14 changes: 7 additions & 7 deletions src/__tests__/_/forCodeCoverage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { FOR_CODE_COV as $8 } from "shared/types/db";
import { FOR_CODE_COV as $9 } from "shared/types/ui";
import { FOR_CODE_COV as $10 } from "backend/data/types";
import { FOR_CODE_COV as $11 } from "backend/lib/request/validations/implementations/types";
import { FOR_CODE_COV as $12 } from "backend/actions/integrations/mailgun/types";
import { FOR_CODE_COV as $13 } from "backend/actions/integrations/postmark/types";
import { FOR_CODE_COV as $14 } from "backend/actions/integrations/sendgrid/types";
import { FOR_CODE_COV as $15 } from "backend/actions/integrations/sendinblue/types";
import { FOR_CODE_COV as $16 } from "backend/actions/integrations/slack/types";
import { FOR_CODE_COV as $17 } from "backend/actions/integrations/smtp/types";
import { FOR_CODE_COV as $18 } from "backend/actions/integrations/twilio/types";
import { FOR_CODE_COV as $12 } from "backend/integrations/libs/mailgun/types";
import { FOR_CODE_COV as $13 } from "backend/integrations/libs/postmark/types";
import { FOR_CODE_COV as $14 } from "backend/integrations/libs/sendgrid/types";
import { FOR_CODE_COV as $15 } from "backend/integrations/libs/sendinblue/types";
import { FOR_CODE_COV as $16 } from "backend/integrations/libs/slack/types";
import { FOR_CODE_COV as $17 } from "backend/integrations/libs/smtp/types";
import { FOR_CODE_COV as $18 } from "backend/integrations/libs/twilio/types";
import { FOR_CODE_COV as $19 } from "backend/storage/types";
import { FOR_CODE_COV as $21 } from "shared/form-schemas/roles/permissions/base";
import { FOR_CODE_COV as $22 } from "backend/lib/config-persistence/portal/index";
Expand Down
16 changes: 15 additions & 1 deletion src/__tests__/admin/[entity]/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,21 @@ describe("pages/admin/[entity]/index", () => {
expect(await getTableRows(screen.getByRole("table")))
.toMatchInlineSnapshot(`
[
"Entity 1 Id FieldEntity 1 Reference FieldEntity 1 String FieldEntity 1 Number FieldEntity 1 Boolean FieldEntity 1 Date FieldEntity 1 Enum FieldActions",
"Entity 1 Id Field
Entity 1 Reference Field
Entity 1 String Field
Entity 1 Number Field
Entity 1 Boolean Field
Entity 1 Date Field
Entity 1 Enum Field
Actions",
"187‌hello > p-1,t=15,o=d < 347th May 2022foo",
"188‌there > p-1,t=15,o=d < 217th May 2021foo",
"189‌today > p-1,t=15,o=d < 187th Feb 2022bar",
Expand Down
14 changes: 0 additions & 14 deletions src/__tests__/admin/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,6 @@ describe("pages/admin", () => {
"Some SVG Here"
);

// expect(within(widget).getByLabelText("New Summary Card Icon").innerHTML)
// .toBe(`<svg fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
// <path fill="none" stroke-linejoin="round" stroke-linecap="round" stroke-width="2" stroke="currentColor" d="M10 21a1 1 0 11-2 0 1 1 0 012 0zM21 21a1 1 0 11-2 0 1 1 0 012 0zM1 1h4l2.68 13.39c.188.925.995 1.61 1.962 1.61h.04-.002H19.438a2 2 0 001.959-1.597l.002-.013 1.6-8.39h-17"></path>
// </svg>`);

expect(within(widget).getByLabelText("Bar Card Icon")).toHaveAttribute(
"color",
"#FF165D"
);
expect(within(widget).getByLabelText("Total Count")).toHaveTextContent(
"10"
);
Expand All @@ -113,11 +104,6 @@ describe("pages/admin", () => {
"#03d87f"
);

expect(within(widget).getByLabelText("Bar Card Icon")).toHaveAttribute(
"color",
"#FF165D"
);

expect(within(widget).getByRole("link", { name: "View" })).toHaveAttribute(
"href",
"/admin/entity-1"
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/api/_test-utils/_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { setupSchemaTestData } from "./_schema";
import { setupUsersTestData } from "./_users";
import { setupIntegrationsEnvTestData } from "./_integrations-env";
import { setupActivatedIntegrationsTestData } from "./_activated-integrations";
import { setupActionInstanceTestData } from "./_action-instances";
import { setupFormActionsTestData } from "./_form-actions";
import { setupTestDatabaseData } from "./_data";
import { portalTestData } from "./portal";
import { setupUserPreferencesTestData } from "./_user-preferences";
Expand All @@ -26,7 +26,7 @@ export const setupAllTestData = async (domains: DomainTypes[]) => {
["schema", setupSchemaTestData],
["data", setupTestDatabaseData],
["activated-integrations", setupActivatedIntegrationsTestData],
["action-instances", setupActionInstanceTestData],
["form-actions", setupFormActionsTestData],
["constants", setupIntegrationsConstantsTestData],
["environment-variables", setupIntegrationsEnvTestData],
["credentials", setupCredentialsTestData],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createConfigDomainPersistenceService } from "backend/lib/config-persistence";
import { ActionIntegrations, IActionInstance } from "shared/types/actions";
import { ActionIntegrations, IFormAction } from "shared/types/actions";
import { DataEventActions } from "shared/types/data";

const TEST_ACTION_INSTANCES: IActionInstance[] = [
const TEST_FORM_ACTIONS: IFormAction[] = [
{
instanceId: "instance-id-1",
id: "form-action-id-1",
integration: ActionIntegrations.SMTP,
entity: "base-model",
action: "SEND_MESSAGE",
Expand All @@ -14,7 +14,7 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [
},
},
{
instanceId: "instance-id-2",
id: "form-action-id-2",
integration: ActionIntegrations.HTTP,
entity: "secondary-model",
action: "POST",
Expand All @@ -25,11 +25,11 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [
},
];

export const setupActionInstanceTestData = async (
testActionInstances: IActionInstance[] = TEST_ACTION_INSTANCES
export const setupFormActionsTestData = async (
formActions: IFormAction[] = TEST_FORM_ACTIONS
) => {
const configPersistenceService =
createConfigDomainPersistenceService<IActionInstance>("action-instances");
createConfigDomainPersistenceService<IFormAction>("form-actions");

await configPersistenceService.resetState("instanceId", testActionInstances);
await configPersistenceService.resetState("id", formActions);
};
2 changes: 1 addition & 1 deletion src/__tests__/api/data/[entity]/[id]/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("/api/data/[entity]/[id]/index", () => {
"credentials",
"app-config",
"data",
"action-instances",
"form-actions",
]);
});

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/api/data/[entity]/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("/api/data/[entity]/index", () => {
"credentials",
"app-config",
"data",
"action-instances",
"form-actions",
]);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import handler from "pages/api/integrations/actions/instances/[key]";
import { ActionIntegrations, IActionInstance } from "shared/types/actions";
import handler from "pages/api/form-actions/[key]";
import { ActionIntegrations, IFormAction } from "shared/types/actions";
import {
createAuthenticatedMocks,
setupAllTestData,
} from "__tests__/api/_test-utils";
import { setupActionInstanceTestData } from "__tests__/api/_test-utils/_action-instances";
import { setupFormActionsTestData } from "__tests__/api/_test-utils/_form-actions";
import { DataEventActions } from "shared/types/data";

const TEST_ACTION_INSTANCES: IActionInstance[] = [
const TEST_FORM_ACTIONS: IFormAction[] = [
{
instanceId: "instance-id-1",
id: "form-action-id-1",
integration: ActionIntegrations.SMTP,
entity: "base-model",
action: "SEND_MESSAGE",
Expand All @@ -19,7 +19,7 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [
},
},
{
instanceId: "instance-id-2",
id: "form-action-id-2",
integration: ActionIntegrations.SMTP,
entity: "base-model",
action: "SEND_MESSAGE",
Expand All @@ -29,7 +29,7 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [
},
},
{
instanceId: "instance-id-3",
id: "form-action-id-3",
integration: ActionIntegrations.SMTP,
entity: "base-model",
action: "SEND_MESSAGE",
Expand All @@ -39,7 +39,7 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [
},
},
{
instanceId: "instance-id-4",
id: "form-action-id-4",
integration: ActionIntegrations.HTTP,
entity: "secondary-model",
action: "POST",
Expand All @@ -50,13 +50,13 @@ const TEST_ACTION_INSTANCES: IActionInstance[] = [
},
];

describe("/api/integrations/actions/instances/[key]", () => {
describe("/api/form-action/[key]", () => {
beforeAll(async () => {
await setupAllTestData(["activated-integrations"]);
await setupActionInstanceTestData(TEST_ACTION_INSTANCES);
await setupFormActionsTestData(TEST_FORM_ACTIONS);
});

it("should show entity action instances", async () => {
it("should show entity form actions", async () => {
const { req, res } = createAuthenticatedMocks({
method: "GET",
query: {
Expand All @@ -74,7 +74,7 @@ describe("/api/integrations/actions/instances/[key]", () => {
"foo": "bar",
},
"entity": "base-model",
"instanceId": "instance-id-1",
"id": "form-action-id-1",
"integration": "smtp",
"trigger": "create",
},
Expand All @@ -84,7 +84,7 @@ describe("/api/integrations/actions/instances/[key]", () => {
"foo1": "bar1",
},
"entity": "base-model",
"instanceId": "instance-id-2",
"id": "form-action-id-2",
"integration": "smtp",
"trigger": "delete",
},
Expand All @@ -94,19 +94,19 @@ describe("/api/integrations/actions/instances/[key]", () => {
"foo2": "bar2",
},
"entity": "base-model",
"instanceId": "instance-id-3",
"id": "form-action-id-3",
"integration": "smtp",
"trigger": "update",
},
]
`);
});

it("should delete action instances", async () => {
it("should delete form actions", async () => {
const { req, res } = createAuthenticatedMocks({
method: "DELETE",
query: {
key: "instance-id-3",
key: "form-action-id-3",
},
});
await handler(req, res);
Expand All @@ -125,11 +125,11 @@ describe("/api/integrations/actions/instances/[key]", () => {
expect(getRes._getJSONData()).toHaveLength(2);
});

it("should patch action instances", async () => {
it("should patch form action", async () => {
const { req, res } = createAuthenticatedMocks({
method: "PATCH",
query: {
key: "instance-id-2",
key: "form-action-id-2",
},
body: {
integration: "slack",
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("/api/integrations/actions/instances/[key]", () => {
"foo": "bar",
},
"entity": "base-model",
"instanceId": "instance-id-1",
"id": "form-action-id-1",
"integration": "smtp",
"trigger": "create",
},
Expand All @@ -174,7 +174,7 @@ describe("/api/integrations/actions/instances/[key]", () => {
"you": "are",
},
"entity": "base-model",
"instanceId": "instance-id-2",
"id": "form-action-id-2",
"integration": "slack",
"trigger": "update",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import handler from "pages/api/integrations/actions/instances/index";
import getHandler from "pages/api/integrations/actions/instances/[key]";
import handler from "pages/api/form-actions/index";
import getHandler from "pages/api/form-actions/[key]";
import {
createAuthenticatedMocks,
setupAllTestData,
Expand All @@ -12,9 +12,9 @@ jest.mock("nanoid", () => ({
.mockReturnValueOnce("nano-id-2"),
}));

describe("/api/integrations/actions/instances/index", () => {
describe("/api/form-actions/index", () => {
beforeAll(async () => {
await setupAllTestData(["action-instances", "activated-integrations"]);
await setupAllTestData(["form-actions", "activated-integrations"]);
});

it("should instantiate actions", async () => {
Expand Down Expand Up @@ -59,35 +59,7 @@ describe("/api/integrations/actions/instances/index", () => {
expect(res._getStatusCode()).toBe(201);
});

it("should not instantiate action for un-activated integration", async () => {
const { req, res } = createAuthenticatedMocks({
method: "POST",
body: {
integration: "postmark",
entity: "test-entity-2",
action: "GET",
trigger: "update",
configuration: {
bad: '{"request": "hello"}',
},
},
});

await handler(req, res);

expect(res._getStatusCode()).toBe(400);
expect(res._getJSONData()).toMatchInlineSnapshot(`
{
"message": "The integration for 'postmark' has not yet been activated",
"method": "POST",
"name": "BadRequestError",
"path": "",
"statusCode": 400,
}
`);
});

it("should show all the added action instances", async () => {
it("should show all the added form actions", async () => {
const { req, res } = createAuthenticatedMocks({
method: "GET",
query: {
Expand All @@ -107,7 +79,7 @@ describe("/api/integrations/actions/instances/index", () => {
"to": "me",
},
"entity": "test-entity",
"instanceId": "nano-id-1",
"id": "nano-id-1",
"integration": "smtp",
"trigger": "update",
},
Expand All @@ -119,7 +91,7 @@ describe("/api/integrations/actions/instances/index", () => {
"url": "/some-where",
},
"entity": "test-entity",
"instanceId": "nano-id-2",
"id": "nano-id-2",
"integration": "http",
"trigger": "create",
},
Expand Down
Loading

0 comments on commit 18694fc

Please sign in to comment.