Skip to content

Commit

Permalink
fix(frontend): fix test creation with curl command (#2463)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeepc committed May 1, 2023
1 parent 143fc39 commit 6852747
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
Expand Up @@ -20,26 +20,16 @@ const ImportCommand = () => {
[onNext]
);

const onRefreshData = useCallback(async () => {
useEffect(() => {
const {command} = draftTest as ICurlValues;
form.setFieldsValue({command});

try {
form.validateFields();
onIsFormValid(true);
} catch (err) {
onIsFormValid(false);
}
onIsFormValid(CurlService.getIsValidCommand(command));
}, [draftTest, form, onIsFormValid]);

useEffect(() => {
onRefreshData();
}, [onRefreshData]);

return (
<Step.Step>
<Step.FormContainer>
<Step.Title>Paste the CURL command</Step.Title>
<Step.Title>CURL command</Step.Title>
<Form<ICurlValues>
id={ComponentNames.ImportCommand}
autoComplete="off"
Expand Down
Expand Up @@ -10,14 +10,17 @@ const ImportCommandForm = () => {
return (
<S.InputContainer>
<Form.Item
label="Paste the CURL command"
name="command"
rules={[
{required: true, message: 'Please enter a command'},
{
validator: (_, command) => {
if (!CurlService.getIsValidCommand(command)) throw new Error('Invalid command');
if (!CurlService.getIsValidCommand(command)) {
return Promise.reject(new Error('Invalid CURL command'));
}

return Promise.resolve(true);
return Promise.resolve();
},
message: 'Invalid CURL command',
},
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Editor/CurlCommand/CurlCommand.tsx
Expand Up @@ -12,7 +12,7 @@ const CurlCommand = ({value, onChange}: IEditorProps) => {
basicSetup={{lineNumbers: true, indentOnInput: true}}
extensions={[StreamLanguage.define(shell)]}
spellCheck={false}
placeholder="Enter a curl command"
placeholder="curl -X POST http://site.com"
/>
);
};
Expand Down
2 changes: 1 addition & 1 deletion web/src/services/Triggers/Curl.service.ts
Expand Up @@ -18,7 +18,7 @@ const CurlTriggerService = (): ICurlTriggerService => ({

async validateDraft(draft) {
const {url, method} = draft as ICurlValues;
return Validator.required(url) && Validator.required(method) && Validator.url(url);
return Validator.required(url) && Validator.required(method);
},

getRequestFromCommand(command) {
Expand Down

0 comments on commit 6852747

Please sign in to comment.