mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 03:25:57 +00:00
fix(plugin-workflow-request): fix params processing (#5204)
This commit is contained in:
parent
a4eb04e459
commit
a726cab92c
@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import axios, { AxiosRequestConfig } from 'axios';
|
import axios, { AxiosRequestConfig } from 'axios';
|
||||||
|
import { trim } from 'lodash';
|
||||||
|
|
||||||
import { Processor, Instruction, JOB_STATUS, FlowNodeModel } from '@nocobase/plugin-workflow';
|
import { Processor, Instruction, JOB_STATUS, FlowNodeModel } from '@nocobase/plugin-workflow';
|
||||||
|
|
||||||
@ -38,14 +39,14 @@ async function request(config) {
|
|||||||
// default headers
|
// default headers
|
||||||
const { url, method = 'POST', contentType = 'application/json', data, timeout = 5000 } = config;
|
const { url, method = 'POST', contentType = 'application/json', data, timeout = 5000 } = config;
|
||||||
const headers = (config.headers ?? []).reduce((result, header) => {
|
const headers = (config.headers ?? []).reduce((result, header) => {
|
||||||
const name = header.name?.trim();
|
const name = trim(header.name);
|
||||||
if (name.toLowerCase() === 'content-type') {
|
if (name.toLowerCase() === 'content-type') {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return Object.assign(result, { [name]: header.value?.trim() });
|
return Object.assign(result, { [name]: trim(header.value) });
|
||||||
}, {});
|
}, {});
|
||||||
const params = (config.params ?? []).reduce(
|
const params = (config.params ?? []).reduce(
|
||||||
(result, param) => Object.assign(result, { [param.name]: param.value?.trim() }),
|
(result, param) => Object.assign(result, { [param.name]: trim(param.value) }),
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ async function request(config) {
|
|||||||
headers['Content-Type'] = contentType;
|
headers['Content-Type'] = contentType;
|
||||||
|
|
||||||
return axios.request({
|
return axios.request({
|
||||||
url: url?.trim(),
|
url: trim(url),
|
||||||
method,
|
method,
|
||||||
headers,
|
headers,
|
||||||
params,
|
params,
|
||||||
|
@ -143,6 +143,26 @@ describe('workflow > instructions > request', () => {
|
|||||||
await app.destroy();
|
await app.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('params processing', () => {
|
||||||
|
it('trim should not crash', async () => {
|
||||||
|
await workflow.createNode({
|
||||||
|
type: 'request',
|
||||||
|
config: {
|
||||||
|
url: api.URL_DATA,
|
||||||
|
method: 'GET',
|
||||||
|
params: [{ name: 'id', value: '{{$context.data.id}}' }],
|
||||||
|
} as RequestConfig,
|
||||||
|
});
|
||||||
|
|
||||||
|
await PostRepo.create({ values: { title: 't1' } });
|
||||||
|
|
||||||
|
await sleep(500);
|
||||||
|
|
||||||
|
const [execution] = await workflow.getExecutions();
|
||||||
|
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('request static app routes', () => {
|
describe('request static app routes', () => {
|
||||||
it('get data (legacy)', async () => {
|
it('get data (legacy)', async () => {
|
||||||
await workflow.createNode({
|
await workflow.createNode({
|
||||||
|
Loading…
Reference in New Issue
Block a user