-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support function in params and commonParms
- Loading branch information
Showing
13 changed files
with
122 additions
and
21 deletions.
There are no files selected for viewing
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,32 @@ | ||
export default { | ||
// 该参数表示请求的公用服务器地址。 | ||
baseUrl: 'http://example-base.com/', | ||
|
||
// 请求的中间路径,建议与文件同名,以便后期维护。 | ||
prefix: 'fake-fn', | ||
|
||
// 所有请求都需要携带的参数 | ||
commonParams: (args) => ({ | ||
...args, | ||
c: Math.random(), | ||
}), | ||
|
||
reqType: 'axios', | ||
|
||
// 接口地址数组 | ||
pathList: [ | ||
/** | ||
* fn-params | ||
*/ | ||
{ | ||
name: 'fp', | ||
path: 'fn-params', | ||
method: 'post', | ||
params: ({ param1, param2 }) => ({ | ||
t: Math.random(), | ||
p1: param1, | ||
p2: param2, | ||
}), | ||
}, | ||
], | ||
} |
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
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
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
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,31 @@ | ||
import axios from 'axios' | ||
import MockAdapter from 'axios-mock-adapter' | ||
|
||
import fakeFnConfig from '@examples/apis-web/fake-fn' | ||
import { fakeFnApi } from '@examples/apis-web/' | ||
|
||
const mock = new MockAdapter(axios) | ||
|
||
const params = { param1: 'steve', param2: 'young' } | ||
const reqFPUrl = 'http://example-base.com/fake-fn/fn-params' | ||
|
||
describe('function params', () => { | ||
beforeEach(() => { | ||
// @ts-ignore | ||
mock.resetHistory() | ||
}) | ||
|
||
test('should support function type params', async () => { | ||
Math.random = jest.fn(() => 'foo') | ||
mock.onPost(reqFPUrl).reply(200, {}) | ||
await fakeFnApi.fp(params) | ||
|
||
const { data } = mock.history.post[0] | ||
expect(data).toEqual(JSON.stringify({ | ||
...fakeFnConfig.commonParams(params), | ||
t: 'foo', | ||
p1: params.param1, | ||
p2: params.param2, | ||
})) | ||
}); | ||
}); |