Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5323 from novuhq/add-custom-step
feat(wip): add custom step
- Loading branch information
Showing
20 changed files
with
441 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Submodule .source
updated
from 9b5c34 to 2b9927
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,29 @@ | ||
import * as http from 'http'; | ||
import * as express from 'express'; | ||
import { serve } from '@novu/echo/express'; | ||
import { Echo } from '@novu/echo'; | ||
|
||
class EchoServer { | ||
private server: express.Express; | ||
private app: http.Server; | ||
private port = 9999; | ||
public echo = new Echo({ devModeBypassAuthentication: true }); | ||
|
||
get serverPath() { | ||
return `http://localhost:${this.port}`; | ||
} | ||
|
||
async start() { | ||
this.server = express(); | ||
this.server.use(express.json()); | ||
this.server.use(serve({ client: this.echo })); | ||
|
||
this.app = await this.server.listen(this.port); | ||
} | ||
|
||
async stop() { | ||
await this.app.close(); | ||
} | ||
} | ||
|
||
export const echoServer = new EchoServer(); |
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
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
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,102 @@ | ||
import axios from 'axios'; | ||
import { expect } from 'chai'; | ||
import { UserSession, SubscribersService } from '@novu/testing'; | ||
import { MessageRepository, SubscriberEntity, NotificationTemplateRepository } from '@novu/dal'; | ||
import { StepTypeEnum } from '@novu/shared'; | ||
import { echoServer } from '../../../../e2e/echo.server'; | ||
|
||
const eventTriggerPath = '/v1/events/trigger'; | ||
|
||
describe('Echo Trigger ', async () => { | ||
let session: UserSession; | ||
const messageRepository = new MessageRepository(); | ||
const workflowsRepository = new NotificationTemplateRepository(); | ||
let subscriber: SubscriberEntity; | ||
let subscriberService: SubscribersService; | ||
|
||
beforeEach(async () => { | ||
session = new UserSession(); | ||
await session.initialize(); | ||
subscriberService = new SubscribersService(session.organization._id, session.environment._id); | ||
subscriber = await subscriberService.createSubscriber(); | ||
}); | ||
|
||
it('should trigger the echo workflow', async () => { | ||
const workflowId = 'hello-world'; | ||
await echoServer.echo.workflow( | ||
workflowId, | ||
async ({ step, payload }) => { | ||
await step.email( | ||
'send-email', | ||
async (inputs) => { | ||
return { | ||
subject: 'This is an email subject ' + inputs.name, | ||
body: 'Body result ' + payload.name, | ||
}; | ||
}, | ||
{ | ||
inputSchema: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string', default: 'TEST' }, | ||
}, | ||
} as const, | ||
} | ||
); | ||
}, | ||
{ | ||
payloadSchema: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string', default: 'default_name' }, | ||
}, | ||
required: [], | ||
additionalProperties: false, | ||
} as const, | ||
} | ||
); | ||
|
||
const resultDiscover = await axios.get(echoServer.serverPath + '/echo?action=discover'); | ||
|
||
await session.testAgent.post(`/v1/echo/sync`).send({ | ||
chimeraUrl: echoServer.serverPath + '/echo', | ||
workflows: resultDiscover.data.workflows, | ||
}); | ||
|
||
const workflow = await workflowsRepository.findByTriggerIdentifier(session.environment._id, workflowId); | ||
expect(workflow).to.be.ok; | ||
|
||
if (!workflow) { | ||
throw new Error('Workflow not found'); | ||
} | ||
|
||
await axios.post( | ||
`${session.serverUrl}${eventTriggerPath}`, | ||
{ | ||
name: workflowId, | ||
to: { | ||
subscriberId: subscriber.subscriberId, | ||
email: '[email protected]', | ||
}, | ||
payload: { | ||
name: 'test_name', | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
authorization: `ApiKey ${session.apiKey}`, | ||
}, | ||
} | ||
); | ||
await session.awaitRunningJobs(workflow._id); | ||
|
||
const messagesAfter = await messageRepository.find({ | ||
_environmentId: session.environment._id, | ||
_subscriberId: subscriber._id, | ||
channel: StepTypeEnum.EMAIL, | ||
}); | ||
|
||
expect(messagesAfter.length).to.be.eq(1); | ||
expect(messagesAfter[0].subject).to.include('This is an email subject TEST'); | ||
}); | ||
}); |
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
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
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
37 changes: 37 additions & 0 deletions
37
apps/web/src/pages/templates/components/custom-editor/TemplateCustomEditor.tsx
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,37 @@ | ||
import { Controller, useFormContext } from 'react-hook-form'; | ||
import { StepSettings } from '../../workflow/SideBar/StepSettings'; | ||
import { useStepFormPath } from '../../hooks/useStepFormPath'; | ||
import { useState } from 'react'; | ||
import { Grid, Stack } from '@mantine/core'; | ||
import { InputVariablesForm } from '../InputVariablesForm'; | ||
|
||
export function TemplateCustomEditor() { | ||
const stepFormPath = useStepFormPath(); | ||
const { control } = useFormContext(); | ||
|
||
const [inputVariables, setInputVariables] = useState(); | ||
|
||
return ( | ||
<> | ||
<StepSettings /> | ||
<Grid gutter={24}> | ||
<Grid.Col span={'auto'}> | ||
<Controller | ||
name={`${stepFormPath}.template.content` as any} | ||
defaultValue="" | ||
control={control} | ||
render={({ field }) => ( | ||
<Stack spacing={8}> | ||
<InputVariablesForm | ||
onChange={(values) => { | ||
setInputVariables(values); | ||
}} | ||
/> | ||
</Stack> | ||
)} | ||
/> | ||
</Grid.Col> | ||
</Grid> | ||
</> | ||
); | ||
} |
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
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
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
Oops, something went wrong.