+
-
-
- {{ item.responseError }}
+ />
+
+
+
+
+
+
+
+
+
+ expand_more
+
+
+
+
+
+
+
+
+ {{ item.requestBodyError }}
+
+
+
+
+
+
+
+
+
+ expand_more
+
+
+
+
+
+
+
+
+ {{ item.responseError }}
+
@@ -2786,9 +2883,46 @@
}
}
- function createTestMockItemDraftState(item = {}) {
+ function createTestMockItemDraftState(item = {}, mode = 'rest') {
const source = isPlainObject(item) ? item : {}
+ if (mode === 'rpc') {
+ const responseMap = isPlainObject(source.response) ? source.response : {}
+ const [rpcCallName, rpcCallValue] = Object.entries(responseMap)[0] || ['', {}]
+ const rpcCall = isPlainObject(rpcCallValue) ? rpcCallValue : {}
+
+ return {
+ descriptionText:
+ typeof source.description === 'string' ? source.description : '',
+ skip: false,
+ hasSkipField: false,
+ requestType:
+ typeof rpcCall.request_type === 'string'
+ ? rpcCall.request_type
+ : 'function',
+ requestBodyText:
+ rpcCall.request_data !== undefined
+ ? safeStringify(rpcCall.request_data)
+ : '',
+ requestBodyError: '',
+ responseType:
+ typeof source.response_type === 'string'
+ ? source.response_type
+ : 'data',
+ responseText:
+ rpcCall.response !== undefined ? safeStringify(rpcCall.response) : '',
+ responseError: '',
+ rpcCallName,
+ rpcDescriptionText:
+ typeof rpcCall.description === 'string' ? rpcCall.description : '',
+ rpcResponseType:
+ typeof rpcCall.response_type === 'string'
+ ? rpcCall.response_type
+ : 'data',
+ error: ''
+ }
+ }
+
return {
descriptionText:
typeof source.description === 'string' ? source.description : '',
@@ -2946,6 +3080,21 @@
{ label: 'exception', value: 'exception' }
]
},
+ rpcTestMockRequestTypeOptions() {
+ return [
+ { label: 'function', value: 'function' },
+ { label: 'async-function', value: 'async-function' }
+ ]
+ },
+ rpcTestMockResponseTypeOptions() {
+ return [
+ { label: 'data', value: 'data' },
+ { label: 'json', value: 'json' },
+ { label: 'exception', value: 'exception' },
+ { label: 'function', value: 'function' },
+ { label: '__aiter__', value: '__aiter__' }
+ ]
+ },
restTestMockRequestTypeOptions() {
return [
{ label: 'data', value: 'data' },
@@ -3148,7 +3297,10 @@
.map(([key, value]) => ({
selectedMockName: key,
items: (Array.isArray(value) ? value : [value]).map(item =>
- createTestMockItemDraftState(item)
+ createTestMockItemDraftState(
+ item,
+ this.functionMockModeByName(key)
+ )
)
})),
error: ''
@@ -3762,6 +3914,68 @@
fundingSourceName
)
+ if (datasetKey === 'rpc') {
+ const template = {}
+ const sampleValue = isPlainObject(sample) ? sample : {}
+ const functionMockResponse = isPlainObject(functionMockValue?.response)
+ ? functionMockValue.response
+ : {}
+ const sampleResponse = isPlainObject(sampleValue.response)
+ ? sampleValue.response
+ : {}
+ const [sampleCallName, sampleCallValue] =
+ Object.entries(sampleResponse)[0] ||
+ Object.entries(functionMockResponse)[0] ||
+ ['some_rpc_call', {}]
+ const innerSample = isPlainObject(sampleCallValue)
+ ? sampleCallValue
+ : {}
+
+ if (Object.prototype.hasOwnProperty.call(sampleValue, 'description')) {
+ template.description = ''
+ }
+
+ template.response_type =
+ typeof sampleValue.response_type === 'string' &&
+ sampleValue.response_type.trim()
+ ? sampleValue.response_type
+ : 'data'
+
+ template.response = {
+ [sampleCallName || 'some_rpc_call']: {
+ ...(Object.prototype.hasOwnProperty.call(
+ innerSample,
+ 'description'
+ )
+ ? { description: '' }
+ : {}),
+ request_type:
+ typeof innerSample.request_type === 'string' &&
+ innerSample.request_type.trim()
+ ? innerSample.request_type
+ : 'function',
+ ...(Object.prototype.hasOwnProperty.call(
+ innerSample,
+ 'request_data'
+ )
+ ? { request_data: {} }
+ : {}),
+ response_type:
+ typeof innerSample.response_type === 'string' &&
+ innerSample.response_type.trim()
+ ? innerSample.response_type
+ : 'data',
+ response: Array.isArray(innerSample.response)
+ ? []
+ : innerSample.response === null
+ ? null
+ : {}
+ }
+ }
+
+ return template
+ }
+
if (isPlainObject(sample)) {
const template = {}
@@ -3911,10 +4125,13 @@
: items === undefined
? []
: [items]
+ const mode = this.functionMockModeByName(mockName)
return {
selectedMockName: mockName,
- items: normalizedItems.map(item => createTestMockItemDraftState(item))
+ items: normalizedItems.map(item =>
+ createTestMockItemDraftState(item, mode)
+ )
}
},
testMockBindingScopeKey(mockSet) {
@@ -4088,7 +4305,21 @@
this.persistTestMockSet(testEntry, mockSet)
},
addTestMockBindingItem(testEntry, mockSet, binding) {
- binding.items.push(createTestMockItemDraftState({}))
+ const functionMockValue =
+ this.datasets[this.selectedDatasetKey].data?.functions?.[
+ this.currentFunctionName
+ ]?.mocks?.[this.currentTestFundingSourceName]?.[
+ binding.selectedMockName
+ ] || {}
+ const mode = this.functionMockModeByName(binding.selectedMockName)
+ const template = this.createTestMockItemTemplate(
+ this.selectedDatasetKey,
+ this.currentFunctionName,
+ this.currentTestFundingSourceName,
+ functionMockValue
+ )
+
+ binding.items.push(createTestMockItemDraftState(template, mode))
this.persistTestMockSet(testEntry, mockSet)
},
removeTestMockBindingItem(testEntry, mockSet, binding, itemIndex) {
@@ -4437,11 +4668,14 @@
const item = binding.items[itemIndex]
const nextItem = {}
- if ((item.descriptionText || '').trim() !== '') {
+ if (
+ bindingMode === 'rest' &&
+ (item.descriptionText || '').trim() !== ''
+ ) {
nextItem.description = item.descriptionText.trim()
}
- if (item.hasSkipField || item.skip === true) {
+ if (bindingMode === 'rest' && (item.hasSkipField || item.skip === true)) {
nextItem.skip = Boolean(item.skip)
}
@@ -4476,11 +4710,17 @@
}
}
- if ((item.responseType || '').trim() !== '') {
+ if (
+ bindingMode === 'rest' &&
+ (item.responseType || '').trim() !== ''
+ ) {
nextItem.response_type = item.responseType.trim()
}
- if ((item.responseText || '').trim() !== '') {
+ if (
+ bindingMode === 'rest' &&
+ (item.responseText || '').trim() !== ''
+ ) {
try {
nextItem.response = this.parseEditableTestJson(
item.responseText,
@@ -4501,6 +4741,101 @@
}
}
+ if (bindingMode !== 'rest') {
+ if ((item.descriptionText || '').trim() !== '') {
+ nextItem.description = item.descriptionText.trim()
+ }
+
+ if ((item.responseType || '').trim() !== '') {
+ nextItem.response_type = item.responseType.trim()
+ }
+
+ const rpcCallName = (item.rpcCallName || '').trim()
+ const rpcCallHasValues = Boolean(
+ rpcCallName ||
+ (item.rpcDescriptionText || '').trim() ||
+ (item.requestType || '').trim() ||
+ (item.requestBodyText || '').trim() ||
+ (item.rpcResponseType || '').trim() ||
+ (item.responseText || '').trim()
+ )
+
+ if (!rpcCallName && rpcCallHasValues) {
+ item.error = 'Enter the RPC call name before editing its mock data.'
+ mockSet.error = item.error
+ if (!options.silent) {
+ this.notify(
+ 'Could not save test mock definition.',
+ 'negative',
+ mockSet.error
+ )
+ }
+ return
+ }
+
+ if (rpcCallName) {
+ const rpcCall = {}
+
+ if ((item.rpcDescriptionText || '').trim() !== '') {
+ rpcCall.description = item.rpcDescriptionText.trim()
+ }
+
+ if ((item.requestType || '').trim() !== '') {
+ rpcCall.request_type = item.requestType.trim()
+ }
+
+ if ((item.requestBodyText || '').trim() !== '') {
+ try {
+ rpcCall.request_data = this.parseEditableTestJson(
+ item.requestBodyText,
+ `${mockName} request_data ${itemIndex + 1}`
+ )
+ } catch (error) {
+ item.requestBodyError =
+ error instanceof Error ? error.message : String(error)
+ mockSet.error = item.requestBodyError
+ if (!options.silent) {
+ this.notify(
+ 'Could not save test mock definition.',
+ 'negative',
+ mockSet.error
+ )
+ }
+ return
+ }
+ }
+
+ if ((item.rpcResponseType || '').trim() !== '') {
+ rpcCall.response_type = item.rpcResponseType.trim()
+ }
+
+ if ((item.responseText || '').trim() !== '') {
+ try {
+ rpcCall.response = this.parseEditableTestJson(
+ item.responseText,
+ `${mockName} response ${itemIndex + 1}`
+ )
+ } catch (error) {
+ item.responseError =
+ error instanceof Error ? error.message : String(error)
+ mockSet.error = item.responseError
+ if (!options.silent) {
+ this.notify(
+ 'Could not save test mock definition.',
+ 'negative',
+ mockSet.error
+ )
+ }
+ return
+ }
+ }
+
+ nextItem.response = {
+ [rpcCallName]: rpcCall
+ }
+ }
+ }
+
parsedItems.push(nextItem)
}