Skip to content

Commit

Permalink
Merge pull request #275 from weni-ai/tests/webhook-router
Browse files Browse the repository at this point in the history
[CFE-437] tests: add webhook router tests
  • Loading branch information
paulobernardoaf authored Nov 1, 2024
2 parents 216ba42 + 2bdb834 commit a7fe963
Show file tree
Hide file tree
Showing 5 changed files with 1,488 additions and 86 deletions.
95 changes: 91 additions & 4 deletions src/components/flow/routers/webhook/WebhookRouterForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,79 @@ describe(WebhookRouterForm.name, () => {

// add http header
fireEvent.click(getByText('HTTP Headers'));
const headerName = getAllByTestId('Ex: Accept')[0];
const headerValue = getAllByTestId('Ex: application/json')[0];
let headerName = getAllByTestId('Ex: Accept')[0];
let headerValue = getAllByTestId('Ex: application/json')[0];

fireEvent.change(headerName, 'Content-type');
fireEvent.change(headerValue, 'application/json');
await act(async () => {
fireUnnnicInputChangeText(headerName, 'Content-type');
fireUnnnicInputChangeText(headerValue, 'application/json');
});

fireEvent.click(okButton);
expect(webhookForm.updateRouter).toBeCalled();
expect(webhookForm.updateRouter).toMatchSnapshot();

fireEvent.click(getByText('General'));

// change to the same method and save
await act(async () => {
userEvent.click(getByText('POST'));
});

fireEvent.click(okButton);
expect(webhookForm.updateRouter).toBeCalled();
expect(webhookForm.updateRouter).toMatchSnapshot();

// test the GET method
await act(async () => {
userEvent.click(getByText('GET'));
});

// set a get body
fireEvent.click(getByText('GET Body'));
const getBody = getByTestId('GET Body');

await act(async () => {
fireUnnnicTextAreaChangeText(getBody, 'Updated get body');
});

fireEvent.click(okButton);
expect(webhookForm.updateRouter).toBeCalled();
expect(webhookForm.updateRouter).toMatchSnapshot();

// Manually add content-type header and change back to POST
fireEvent.click(getByText('HTTP Headers'));
headerName = getAllByTestId('Ex: Accept')[0];
headerValue = getAllByTestId('Ex: application/json')[0];

fireUnnnicInputChangeText(headerName, 'Content-type');
fireUnnnicInputChangeText(headerValue, 'application/json');

fireEvent.click(getByText('General'));

// change to the same method and save
await act(async () => {
userEvent.click(getByText('POST'));
});

// remonve an http header
await act(async () => {
fireEvent.click(getByText('HTTP Headers'));
});

const deleteButton = getAllByTestId('remove-icon')[0];
fireEvent.click(deleteButton);

fireEvent.click(okButton);
expect(webhookForm.updateRouter).toBeCalled();
expect(webhookForm.updateRouter).toMatchSnapshot();

fireEvent.click(getByText('General'));

// go back to GET and save
await act(async () => {
userEvent.click(getByText('GET'));
});

fireEvent.click(okButton);
expect(webhookForm.updateRouter).toBeCalled();
Expand Down Expand Up @@ -131,4 +199,23 @@ describe(WebhookRouterForm.name, () => {
expect(webhookForm.updateRouter).toBeCalled();
});
});

it("should render a split_by_webhook's original action", () => {
const webhookForm = getRouterFormProps({
node: {
...createWebhookRouterNode({
'Content-Type': 'application/json',
}),
},
ui: { type: Types.split_by_webhook },
} as RenderNode);

const { setup } = composeComponentTestUtils<RouterFormProps>(
WebhookRouterForm,
webhookForm,
);
const { wrapper } = setup(true);

expect(shallowToJson(wrapper)).toMatchSnapshot();
});
});
Loading

0 comments on commit a7fe963

Please sign in to comment.