Skip to content

Commit

Permalink
♻️ refactor(actions): use better keys for action instances
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Jan 12, 2024
1 parent 06319f3 commit 7c18bc2
Show file tree
Hide file tree
Showing 27 changed files with 251 additions and 261 deletions.
14 changes: 7 additions & 7 deletions src/__tests__/api/_test-utils/_action-instances.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { createConfigDomainPersistenceService } from "backend/lib/config-persistence";
import { ActionIntegrationKeys, IActionInstance } from "shared/types/actions";
import { ActionIntegrations, IActionInstance } from "shared/types/actions";
import { DataEventActions } from "shared/types/data";

const TEST_ACTION_INSTANCES: IActionInstance[] = [
{
instanceId: "instance-id-1",
integrationKey: ActionIntegrationKeys.SMTP,
integration: ActionIntegrations.SMTP,
entity: "base-model",
implementationKey: "SEND_MESSAGE",
formAction: DataEventActions.Create,
action: "SEND_MESSAGE",
trigger: DataEventActions.Create,
configuration: {
foo: "bar",
},
},
{
instanceId: "instance-id-2",
integrationKey: ActionIntegrationKeys.HTTP,
integration: ActionIntegrations.HTTP,
entity: "secondary-model",
implementationKey: "POST",
formAction: DataEventActions.Delete,
action: "POST",
trigger: DataEventActions.Delete,
configuration: {
bar: "foo",
},
Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/api/_test-utils/_activated-integrations.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { createKeyValueDomainPersistenceService } from "backend/lib/key-value";
import { ActionIntegrationKeys } from "shared/types/actions";
import { ActionIntegrations } from "shared/types/actions";

const TEST_ACTIVATED_ACTIONS: ActionIntegrationKeys[] = [
ActionIntegrationKeys.SMTP,
ActionIntegrationKeys.SLACK,
const TEST_ACTIVATED_ACTIONS: ActionIntegrations[] = [
ActionIntegrations.SMTP,
ActionIntegrations.SLACK,
];

export const setupActivatedIntegrationsTestData = async (
testActivatedActions: ActionIntegrationKeys[] = TEST_ACTIVATED_ACTIONS
testActivatedIntegrations: ActionIntegrations[] = TEST_ACTIVATED_ACTIONS
) => {
const activatedIntegrationsPersistenceService =
createKeyValueDomainPersistenceService<ActionIntegrationKeys[]>(
createKeyValueDomainPersistenceService<ActionIntegrations[]>(
"activated-integrations"
);

await activatedIntegrationsPersistenceService.persistItem(
testActivatedActions
testActivatedIntegrations
);
};
4 changes: 2 additions & 2 deletions src/__tests__/api/dashboards/[dashboardId]/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe("/api/dashboards/[dashboardId]/index generation", () => {
"color": "red",
"entity": "base-model",
"icon": "ShoppingCart",
"id": "2",
"id": "1",
"script": "const actual = await $.query(\`select count(*) as \`count\` from \`base-model\`\`);
const relative = await $.query(\`select count(*) as \`count\` from \`base-model\` where \`createdAt\` < '$.RELATIVE_TIME'\`);
Expand All @@ -224,7 +224,7 @@ describe("/api/dashboards/[dashboardId]/index generation", () => {
"color": "orange",
"entity": "secondary-model",
"icon": "Activity",
"id": "1",
"id": "2",
"script": "return await $.query(\`select count(*) as \`count\` from \`secondary-model\`\`)",
"title": "Secondary Model",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
setupAllTestData,
setupCredentialsTestData,
} from "__tests__/api/_test-utils";
import { ActionIntegrationKeys } from "shared/types/actions";
import { ActionIntegrations } from "shared/types/actions";

describe("/api/integrations/actions/[key]/credentials", () => {
beforeAll(async () => {
Expand All @@ -27,7 +27,7 @@ describe("/api/integrations/actions/[key]/credentials", () => {
const { req, res } = createAuthenticatedMocks({
method: "POST",
query: {
key: ActionIntegrationKeys.SMTP,
key: ActionIntegrations.SMTP,
},
body: {
_password: "invalid password",
Expand All @@ -51,7 +51,7 @@ describe("/api/integrations/actions/[key]/credentials", () => {
const { req, res } = createAuthenticatedMocks({
method: "POST",
query: {
key: ActionIntegrationKeys.SMTP,
key: ActionIntegrations.SMTP,
},
body: {
_password: "password",
Expand All @@ -73,7 +73,7 @@ describe("/api/integrations/actions/[key]/credentials", () => {
const { req, res } = createAuthenticatedMocks({
method: "POST",
query: {
key: ActionIntegrationKeys.HTTP,
key: ActionIntegrations.HTTP,
},
body: {
_password: "password",
Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/api/integrations/actions/[key]/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
setupAllTestData,
} from "__tests__/api/_test-utils";
import { setupActionInstanceTestData } from "__tests__/api/_test-utils/_action-instances";
import { ActionIntegrationKeys } from "shared/types/actions";
import { ActionIntegrations } from "shared/types/actions";
import { DataEventActions } from "shared/types/data";

jest.mock("nanoid", () => ({
Expand All @@ -22,20 +22,20 @@ describe("/api/integrations/actions/[key]/index", () => {
await setupActionInstanceTestData([
{
instanceId: "instance-id-1",
integrationKey: ActionIntegrationKeys.HTTP,
integration: ActionIntegrations.HTTP,
entity: "base-model",
implementationKey: "SEND_MESSAGE",
formAction: DataEventActions.Create,
action: "SEND_MESSAGE",
trigger: DataEventActions.Create,
configuration: {
foo: "bar",
},
},
{
instanceId: "instance-id-2",
integrationKey: ActionIntegrationKeys.SLACK,
integration: ActionIntegrations.SLACK,
entity: "secondary-model",
implementationKey: "POST",
formAction: DataEventActions.Delete,
action: "POST",
trigger: DataEventActions.Delete,
configuration: {
bar: "foo",
},
Expand Down
62 changes: 31 additions & 31 deletions src/__tests__/api/integrations/actions/instances/[key].spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import handler from "pages/api/integrations/actions/instances/[key]";
import { ActionIntegrationKeys, IActionInstance } from "shared/types/actions";
import { ActionIntegrations, IActionInstance } from "shared/types/actions";
import {
createAuthenticatedMocks,
setupAllTestData,
Expand All @@ -10,40 +10,40 @@ import { DataEventActions } from "shared/types/data";
const TEST_ACTION_INSTANCES: IActionInstance[] = [
{
instanceId: "instance-id-1",
integrationKey: ActionIntegrationKeys.SMTP,
integration: ActionIntegrations.SMTP,
entity: "base-model",
implementationKey: "SEND_MESSAGE",
formAction: DataEventActions.Create,
action: "SEND_MESSAGE",
trigger: DataEventActions.Create,
configuration: {
foo: "bar",
},
},
{
instanceId: "instance-id-2",
integrationKey: ActionIntegrationKeys.SMTP,
integration: ActionIntegrations.SMTP,
entity: "base-model",
implementationKey: "SEND_MESSAGE",
formAction: DataEventActions.Delete,
action: "SEND_MESSAGE",
trigger: DataEventActions.Delete,
configuration: {
foo1: "bar1",
},
},
{
instanceId: "instance-id-3",
integrationKey: ActionIntegrationKeys.SMTP,
integration: ActionIntegrations.SMTP,
entity: "base-model",
implementationKey: "SEND_MESSAGE",
formAction: DataEventActions.Update,
action: "SEND_MESSAGE",
trigger: DataEventActions.Update,
configuration: {
foo2: "bar2",
},
},
{
instanceId: "instance-id-4",
integrationKey: ActionIntegrationKeys.HTTP,
integration: ActionIntegrations.HTTP,
entity: "secondary-model",
implementationKey: "POST",
formAction: DataEventActions.Delete,
action: "POST",
trigger: DataEventActions.Delete,
configuration: {
bar: "foo",
},
Expand All @@ -69,34 +69,34 @@ describe("/api/integrations/actions/instances/[key]", () => {
expect(res._getJSONData()).toMatchInlineSnapshot(`
[
{
"action": "SEND_MESSAGE",
"configuration": {
"foo": "bar",
},
"entity": "base-model",
"formAction": "create",
"implementationKey": "SEND_MESSAGE",
"instanceId": "instance-id-1",
"integrationKey": "smtp",
"integration": "smtp",
"trigger": "create",
},
{
"action": "SEND_MESSAGE",
"configuration": {
"foo1": "bar1",
},
"entity": "base-model",
"formAction": "delete",
"implementationKey": "SEND_MESSAGE",
"instanceId": "instance-id-2",
"integrationKey": "smtp",
"integration": "smtp",
"trigger": "delete",
},
{
"action": "SEND_MESSAGE",
"configuration": {
"foo2": "bar2",
},
"entity": "base-model",
"formAction": "update",
"implementationKey": "SEND_MESSAGE",
"instanceId": "instance-id-3",
"integrationKey": "smtp",
"integration": "smtp",
"trigger": "update",
},
]
`);
Expand Down Expand Up @@ -132,10 +132,10 @@ describe("/api/integrations/actions/instances/[key]", () => {
key: "instance-id-2",
},
body: {
integrationKey: "slack",
integration: "slack",
entity: "base-model",
implementationKey: "SEND_MESSAGE_UPDATED",
formAction: "update",
action: "SEND_MESSAGE_UPDATED",
trigger: "update",
configuration: {
you: "are",
awe: "some",
Expand All @@ -158,25 +158,25 @@ describe("/api/integrations/actions/instances/[key]", () => {
expect(getRes._getJSONData()).toMatchInlineSnapshot(`
[
{
"action": "SEND_MESSAGE",
"configuration": {
"foo": "bar",
},
"entity": "base-model",
"formAction": "create",
"implementationKey": "SEND_MESSAGE",
"instanceId": "instance-id-1",
"integrationKey": "smtp",
"integration": "smtp",
"trigger": "create",
},
{
"action": "SEND_MESSAGE_UPDATED",
"configuration": {
"awe": "some",
"you": "are",
},
"entity": "base-model",
"formAction": "update",
"implementationKey": "SEND_MESSAGE_UPDATED",
"instanceId": "instance-id-2",
"integrationKey": "slack",
"integration": "slack",
"trigger": "update",
},
]
`);
Expand Down
30 changes: 15 additions & 15 deletions src/__tests__/api/integrations/actions/instances/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ describe("/api/integrations/actions/instances/index", () => {
method: "POST",
body: {
entity: "test-entity",
integrationKey: "smtp",
implementationKey: "SEND_MESSAGE",
formAction: "update",
integration: "smtp",
action: "SEND_MESSAGE",
trigger: "update",
configuration: {
to: "me",
subject: "something important",
Expand All @@ -43,9 +43,9 @@ describe("/api/integrations/actions/instances/index", () => {
method: "POST",
body: {
entity: "test-entity",
integrationKey: "http",
implementationKey: "PUT",
formAction: "create",
integration: "http",
action: "PUT",
trigger: "create",
configuration: {
url: "/some-where",
body: '{"me": "you"}',
Expand All @@ -63,10 +63,10 @@ describe("/api/integrations/actions/instances/index", () => {
const { req, res } = createAuthenticatedMocks({
method: "POST",
body: {
integrationKey: "postmark",
integration: "postmark",
entity: "test-entity-2",
implementationKey: "GET",
formAction: "update",
action: "GET",
trigger: "update",
configuration: {
bad: '{"request": "hello"}',
},
Expand Down Expand Up @@ -100,28 +100,28 @@ describe("/api/integrations/actions/instances/index", () => {
expect(res._getJSONData()).toMatchInlineSnapshot(`
[
{
"action": "SEND_MESSAGE",
"configuration": {
"body": "You are awesome",
"subject": "something important",
"to": "me",
},
"entity": "test-entity",
"formAction": "update",
"implementationKey": "SEND_MESSAGE",
"instanceId": "nano-id-1",
"integrationKey": "smtp",
"integration": "smtp",
"trigger": "update",
},
{
"action": "PUT",
"configuration": {
"body": "{"me": "you"}",
"headers": "{"me": "you"}",
"url": "/some-where",
},
"entity": "test-entity",
"formAction": "create",
"implementationKey": "PUT",
"instanceId": "nano-id-2",
"integrationKey": "http",
"integration": "http",
"trigger": "create",
},
]
`);
Expand Down
Loading

0 comments on commit 7c18bc2

Please sign in to comment.