-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
387 additions
and
22 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...ty-front/src/modules/workflow/search-variables/utils/__tests__/getTriggerStepName.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { getTriggerStepName } from '../getTriggerStepName'; | ||
|
||
it('returns the expected name for a DATABASE_EVENT trigger', () => { | ||
expect( | ||
getTriggerStepName({ | ||
type: 'DATABASE_EVENT', | ||
name: '', | ||
settings: { | ||
eventName: 'company.created', | ||
outputSchema: {}, | ||
}, | ||
}), | ||
).toBe('Company is Created'); | ||
}); | ||
|
||
it('returns the expected name for a MANUAL trigger without a defined objectType', () => { | ||
expect( | ||
getTriggerStepName({ | ||
type: 'MANUAL', | ||
name: '', | ||
settings: { | ||
objectType: undefined, | ||
outputSchema: {}, | ||
}, | ||
}), | ||
).toBe('Manual trigger'); | ||
}); | ||
|
||
it('returns the expected name for a MANUAL trigger with a defined objectType', () => { | ||
expect( | ||
getTriggerStepName({ | ||
type: 'MANUAL', | ||
name: '', | ||
settings: { | ||
objectType: 'company', | ||
outputSchema: {}, | ||
}, | ||
}), | ||
).toBe('Manual trigger for Company'); | ||
}); | ||
|
||
it('throws when an unknown trigger type is provided', () => { | ||
expect(() => { | ||
getTriggerStepName({ | ||
type: 'unknown' as any, | ||
name: '', | ||
settings: { | ||
objectType: 'company', | ||
outputSchema: {}, | ||
}, | ||
}); | ||
}).toThrow(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/twenty-front/src/modules/workflow/utils/__tests__/assertUnreachable.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { assertUnreachable } from '@/workflow/utils/assertUnreachable'; | ||
|
||
it('throws when argument is not never', () => { | ||
expect(() => { | ||
assertUnreachable(42 as never); | ||
}).toThrow(); | ||
}); | ||
|
||
it('throws with the provided error message when argument is not never', () => { | ||
expect(() => { | ||
assertUnreachable(42 as never, 'Custom error!'); | ||
}).toThrow('Custom error!'); | ||
}); |
16 changes: 16 additions & 0 deletions
16
...nt/src/modules/workflow/utils/__tests__/assertWorkflowWithCurrentVersionIsDefined.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow'; | ||
import { assertWorkflowWithCurrentVersionIsDefined } from '../assertWorkflowWithCurrentVersionIsDefined'; | ||
|
||
it('throws when provided workflow is undefined', () => { | ||
expect(() => { | ||
assertWorkflowWithCurrentVersionIsDefined(undefined); | ||
}).toThrow(); | ||
}); | ||
|
||
it("throws when provided workflow's current version is undefined", () => { | ||
expect(() => { | ||
assertWorkflowWithCurrentVersionIsDefined( | ||
{} as unknown as WorkflowWithCurrentVersion, | ||
); | ||
}).toThrow(); | ||
}); |
26 changes: 26 additions & 0 deletions
26
...twenty-front/src/modules/workflow/utils/__tests__/getManualTriggerDefaultSettings.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems'; | ||
import { getManualTriggerDefaultSettings } from '../getManualTriggerDefaultSettings'; | ||
|
||
it('returns settings for a manual trigger that can be activated from any where', () => { | ||
expect( | ||
getManualTriggerDefaultSettings({ | ||
availability: 'EVERYWHERE', | ||
activeObjectMetadataItems: generatedMockObjectMetadataItems, | ||
}), | ||
).toStrictEqual({ | ||
objectType: undefined, | ||
outputSchema: {}, | ||
}); | ||
}); | ||
|
||
it('returns settings for a manual trigger that can be activated from any where', () => { | ||
expect( | ||
getManualTriggerDefaultSettings({ | ||
availability: 'WHEN_RECORD_SELECTED', | ||
activeObjectMetadataItems: generatedMockObjectMetadataItems, | ||
}), | ||
).toStrictEqual({ | ||
objectType: generatedMockObjectMetadataItems[0].nameSingular, | ||
outputSchema: {}, | ||
}); | ||
}); |
120 changes: 120 additions & 0 deletions
120
packages/twenty-front/src/modules/workflow/utils/__tests__/getStepDefaultDefinition.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems'; | ||
import { getStepDefaultDefinition } from '../getStepDefaultDefinition'; | ||
|
||
it('returns a valid definition for CODE actions', () => { | ||
expect( | ||
getStepDefaultDefinition({ | ||
type: 'CODE', | ||
activeObjectMetadataItems: generatedMockObjectMetadataItems, | ||
}), | ||
).toStrictEqual({ | ||
id: expect.any(String), | ||
name: 'Code', | ||
type: 'CODE', | ||
valid: false, | ||
settings: { | ||
input: { | ||
serverlessFunctionId: '', | ||
serverlessFunctionVersion: '', | ||
serverlessFunctionInput: {}, | ||
}, | ||
outputSchema: {}, | ||
errorHandlingOptions: { | ||
continueOnFailure: { | ||
value: false, | ||
}, | ||
retryOnFailure: { | ||
value: false, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('returns a valid definition for SEND_EMAIL actions', () => { | ||
expect( | ||
getStepDefaultDefinition({ | ||
type: 'SEND_EMAIL', | ||
activeObjectMetadataItems: generatedMockObjectMetadataItems, | ||
}), | ||
).toStrictEqual({ | ||
id: expect.any(String), | ||
name: 'Send Email', | ||
type: 'SEND_EMAIL', | ||
valid: false, | ||
settings: { | ||
input: { | ||
connectedAccountId: '', | ||
email: '', | ||
subject: '', | ||
body: '', | ||
}, | ||
outputSchema: {}, | ||
errorHandlingOptions: { | ||
continueOnFailure: { | ||
value: false, | ||
}, | ||
retryOnFailure: { | ||
value: false, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('returns a valid definition for RECORD_CRUD.CREATE actions', () => { | ||
expect( | ||
getStepDefaultDefinition({ | ||
type: 'RECORD_CRUD.CREATE', | ||
activeObjectMetadataItems: generatedMockObjectMetadataItems, | ||
}), | ||
).toStrictEqual({ | ||
id: expect.any(String), | ||
name: 'Create Record', | ||
type: 'RECORD_CRUD', | ||
valid: false, | ||
settings: { | ||
input: { | ||
type: 'CREATE', | ||
objectName: generatedMockObjectMetadataItems[0].nameSingular, | ||
objectRecord: {}, | ||
}, | ||
outputSchema: {}, | ||
errorHandlingOptions: { | ||
continueOnFailure: { | ||
value: false, | ||
}, | ||
retryOnFailure: { | ||
value: false, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it("throws for RECORD_CRUD.DELETE actions as it's not implemented yet", () => { | ||
expect(() => { | ||
getStepDefaultDefinition({ | ||
type: 'RECORD_CRUD.DELETE', | ||
activeObjectMetadataItems: generatedMockObjectMetadataItems, | ||
}); | ||
}).toThrow('Not implemented yet'); | ||
}); | ||
|
||
it("throws for RECORD_CRUD.UPDATE actions as it's not implemented yet", () => { | ||
expect(() => { | ||
getStepDefaultDefinition({ | ||
type: 'RECORD_CRUD.UPDATE', | ||
activeObjectMetadataItems: generatedMockObjectMetadataItems, | ||
}); | ||
}).toThrow('Not implemented yet'); | ||
}); | ||
|
||
it('throws when providing an unknown type', () => { | ||
expect(() => { | ||
getStepDefaultDefinition({ | ||
type: 'unknown' as any, | ||
activeObjectMetadataItems: generatedMockObjectMetadataItems, | ||
}); | ||
}).toThrow('Unknown type: unknown'); | ||
}); |
50 changes: 50 additions & 0 deletions
50
...ges/twenty-front/src/modules/workflow/utils/__tests__/getTriggerDefaultDefinition.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems'; | ||
import { getTriggerDefaultDefinition } from '../getTriggerDefaultDefinition'; | ||
|
||
it('throws if the activeObjectMetadataItems list is empty', () => { | ||
expect(() => { | ||
getTriggerDefaultDefinition({ | ||
type: 'DATABASE_EVENT', | ||
activeObjectMetadataItems: [], | ||
}); | ||
}).toThrow(); | ||
}); | ||
|
||
it('returns a valid configuration for DATABASE_EVENT trigger type', () => { | ||
expect( | ||
getTriggerDefaultDefinition({ | ||
type: 'DATABASE_EVENT', | ||
activeObjectMetadataItems: generatedMockObjectMetadataItems, | ||
}), | ||
).toStrictEqual({ | ||
type: 'DATABASE_EVENT', | ||
settings: { | ||
eventName: `${generatedMockObjectMetadataItems[0].nameSingular}.created`, | ||
outputSchema: {}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('returns a valid configuration for MANUAL trigger type', () => { | ||
expect( | ||
getTriggerDefaultDefinition({ | ||
type: 'MANUAL', | ||
activeObjectMetadataItems: generatedMockObjectMetadataItems, | ||
}), | ||
).toStrictEqual({ | ||
type: 'MANUAL', | ||
settings: { | ||
objectType: generatedMockObjectMetadataItems[0].nameSingular, | ||
outputSchema: {}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('throws when providing an unknown trigger type', () => { | ||
expect(() => { | ||
getTriggerDefaultDefinition({ | ||
type: 'unknown' as any, | ||
activeObjectMetadataItems: generatedMockObjectMetadataItems, | ||
}); | ||
}).toThrow('Unknown type: unknown'); | ||
}); |
79 changes: 79 additions & 0 deletions
79
...es/twenty-front/src/modules/workflow/utils/__tests__/isWorkflowRecordCreateAction.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { | ||
WorkflowCodeAction, | ||
WorkflowRecordCRUDAction, | ||
} from '@/workflow/types/Workflow'; | ||
import { isWorkflowRecordCreateAction } from '../isWorkflowRecordCreateAction'; | ||
|
||
it('returns false when providing an action that is not Record Create', () => { | ||
const codeAction: WorkflowCodeAction = { | ||
type: 'CODE', | ||
id: '', | ||
name: '', | ||
settings: { | ||
errorHandlingOptions: { | ||
continueOnFailure: { | ||
value: false, | ||
}, | ||
retryOnFailure: { | ||
value: false, | ||
}, | ||
}, | ||
input: { | ||
serverlessFunctionId: '', | ||
serverlessFunctionVersion: '', | ||
serverlessFunctionInput: {}, | ||
}, | ||
outputSchema: {}, | ||
}, | ||
valid: true, | ||
}; | ||
|
||
expect(isWorkflowRecordCreateAction(codeAction)).toBe(false); | ||
}); | ||
|
||
it('returns false for Record Update', () => { | ||
const codeAction: WorkflowRecordCRUDAction = { | ||
type: 'RECORD_CRUD', | ||
id: '', | ||
name: '', | ||
settings: { | ||
errorHandlingOptions: { | ||
continueOnFailure: { value: false }, | ||
retryOnFailure: { value: false }, | ||
}, | ||
input: { | ||
type: 'UPDATE', | ||
objectName: '', | ||
objectRecord: {}, | ||
objectRecordId: '', | ||
}, | ||
outputSchema: {}, | ||
}, | ||
valid: true, | ||
}; | ||
|
||
expect(isWorkflowRecordCreateAction(codeAction)).toBe(false); | ||
}); | ||
|
||
it('returns true for Record Create', () => { | ||
const codeAction: WorkflowRecordCRUDAction = { | ||
type: 'RECORD_CRUD', | ||
id: '', | ||
name: '', | ||
settings: { | ||
errorHandlingOptions: { | ||
continueOnFailure: { value: false }, | ||
retryOnFailure: { value: false }, | ||
}, | ||
input: { | ||
type: 'CREATE', | ||
objectName: '', | ||
objectRecord: {}, | ||
}, | ||
outputSchema: {}, | ||
}, | ||
valid: true, | ||
}; | ||
|
||
expect(isWorkflowRecordCreateAction(codeAction)).toBe(true); | ||
}); |
Oops, something went wrong.