Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 39 additions & 95 deletions packages/entities/entities-plugins/src/components/PluginForm.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const baseConfigKonnect: KonnectPluginFormConfig = {
cancelRoute: { name: 'home' },
}

const baseConfigKM:KongManagerPluginFormConfig = {
const baseConfigKM: KongManagerPluginFormConfig = {
app: 'kongManager',
workspace: 'default',
apiBaseUrl: '/kong-manager',
Expand Down Expand Up @@ -78,25 +78,6 @@ describe('<PluginForm />', () => {
).as(params?.alias ?? 'createPlugin')
}

const interceptKMValidatePlugin = (params?: {
mockData?: object
alias?: string
status?: number
}): void => {
const url = `${baseConfigKM.apiBaseUrl}/${baseConfigKM.workspace}/schemas/plugins/validate`

cy.intercept(
{
method: 'POST',
url,
},
{
statusCode: params?.status ?? 200,
body: params?.mockData ?? plugin1,
},
).as(params?.alias ?? 'validatePlugin')
}

/**
* Intercepts requests for a specific scoped entity and prefetched data
* For instance, if some `service` was selected, thus we are in edit mode, this intercepts the given `entityType=service`.
Expand Down Expand Up @@ -574,7 +555,6 @@ describe('<PluginForm />', () => {

it('should pick correct url while creating plugin', () => {
interceptKMSchema()
interceptKMValidatePlugin()
interceptKMCreatePlugin()
const pluginType = 'cors'

Expand All @@ -601,7 +581,7 @@ describe('<PluginForm />', () => {
cy.get('#tags').type('tag1,tag2')

cy.getTestId('plugin-create-form-submit').click()
cy.wait(['@validatePlugin', '@createPlugin'])
cy.wait('@createPlugin')
})

it('should pick correct url while creating plugin credential', () => {
Expand Down Expand Up @@ -696,7 +676,6 @@ describe('<PluginForm />', () => {
entityId: scopedService.id,
entityType: 'services',
})
interceptKMValidatePlugin()
interceptKMOperatePlugin({
method: 'PATCH',
alias: 'updatePlugin',
Expand Down Expand Up @@ -731,7 +710,7 @@ describe('<PluginForm />', () => {

cy.getTestId('plugin-edit-form-submit').click()

cy.wait(['@validatePlugin', '@updatePlugin'])
cy.wait('@updatePlugin')
})
})

Expand Down Expand Up @@ -886,28 +865,22 @@ describe('<PluginForm />', () => {

it('should handle error state - validation error', () => {
interceptKMSchema({ mockData: schemaMocking })
cy.intercept(
{
method: 'POST',
url: `${baseConfigKM.apiBaseUrl}/${baseConfigKM.workspace}/schemas/plugins/validate`,
},
{
statusCode: 400,
body: {
code: 3,
message: 'validation error',
details: [
{
'@type': 'type.googleapis.com/kong.admin.model.v1.ErrorDetail',
type: 'ERROR_TYPE_ENTITY',
messages: [
"at least one of these fields must be non-empty: 'config.api_specification_filename', 'config.api_specification'",
],
},
],
},
interceptKMCreatePlugin({
status: 400,
mockData: {
code: 3,
message: 'validation error',
details: [
{
'@type': 'type.googleapis.com/kong.admin.model.v1.ErrorDetail',
type: 'ERROR_TYPE_ENTITY',
messages: [
"at least one of these fields must be non-empty: 'config.api_specification_filename', 'config.api_specification'",
],
},
],
},
).as('validate')
})
const pluginType = 'mocking'

cy.mount(PluginForm, {
Expand All @@ -922,7 +895,7 @@ describe('<PluginForm />', () => {
cy.get('.kong-ui-entities-plugin-form-container').should('be.visible')

cy.getTestId('plugin-create-form-submit').click()
cy.wait('@validate')
cy.wait('@createPlugin')

cy.getTestId('form-error').should('be.visible')
})
Expand All @@ -931,7 +904,6 @@ describe('<PluginForm />', () => {
const config = { ...baseConfigKM, entityId: scopedService.id, entityType: 'services' }
interceptKMSchema()
interceptKMOperatePlugin({ method: 'GET', alias: 'getPlugin', id: plugin1.id })
interceptKMValidatePlugin()
interceptKMOperatePlugin({ method: 'PATCH', alias: 'updatePlugin', id: plugin1.id })
const pluginType = 'cors'
const stubbedAliases = interceptKMScopedEntity({ entityType: config.entityType }, pluginType)
Expand Down Expand Up @@ -963,7 +935,7 @@ describe('<PluginForm />', () => {

cy.getTestId('plugin-edit-form-submit').click()

cy.wait(['@validatePlugin', '@updatePlugin']).then(() => {
cy.wait('@updatePlugin').then(() => {
cy.get('@onUpdateSpy').should('have.been.calledOnce')
})
})
Expand Down Expand Up @@ -1012,25 +984,6 @@ describe('<PluginForm />', () => {
).as(params?.alias ?? 'createPlugin')
}

const interceptKonnectValidatePlugin = (params?: {
mockData?: object
alias?: string
status?: number
}): void => {
const url = `${baseConfigKonnect.apiBaseUrl}/v2/control-planes/${baseConfigKonnect.controlPlaneId}/core-entities/v1/schemas/json/plugin/validate`

cy.intercept(
{
method: 'POST',
url,
},
{
statusCode: params?.status ?? 200,
body: params?.mockData ?? plugin1,
},
).as(params?.alias ?? 'validatePlugin')
}

const interceptKonnectScopedEntity = (params: {
entityType: string
mockData?: object
Expand Down Expand Up @@ -1492,7 +1445,6 @@ describe('<PluginForm />', () => {

it('should pick correct url while creating plugin', () => {
interceptKonnectSchema()
interceptKonnectValidatePlugin()
interceptKonnectCreatePlugin()
const pluginType = 'cors'

Expand All @@ -1519,7 +1471,7 @@ describe('<PluginForm />', () => {
cy.get('#tags').type('tag1,tag2')

cy.getTestId('plugin-create-form-submit').click()
cy.wait(['@validatePlugin', '@createPlugin'])
cy.wait('@createPlugin')
})

it('should pick correct url while creating plugin credential', () => {
Expand Down Expand Up @@ -1610,7 +1562,6 @@ describe('<PluginForm />', () => {
entityId: scopedService.id,
entityType: 'services',
})
interceptKonnectValidatePlugin()
interceptKonnectOperatePlugin({
method: 'PUT',
alias: 'updatePlugin',
Expand Down Expand Up @@ -1645,7 +1596,7 @@ describe('<PluginForm />', () => {

cy.getTestId('plugin-edit-form-submit').click()

cy.wait(['@validatePlugin', '@updatePlugin'])
cy.wait('@updatePlugin')
})
})

Expand Down Expand Up @@ -1799,28 +1750,22 @@ describe('<PluginForm />', () => {

it('should handle error state - validation error', () => {
interceptKonnectSchema({ mockData: schemaMocking })
cy.intercept(
{
method: 'POST',
url: `${baseConfigKonnect.apiBaseUrl}/v2/control-planes/${baseConfigKonnect.controlPlaneId}/core-entities/v1/schemas/json/plugin/validate`,
},
{
statusCode: 400,
body: {
code: 3,
message: 'validation error',
details: [
{
'@type': 'type.googleapis.com/kong.admin.model.v1.ErrorDetail',
type: 'ERROR_TYPE_ENTITY',
messages: [
"at least one of these fields must be non-empty: 'config.api_specification_filename', 'config.api_specification'",
],
},
],
},
interceptKonnectCreatePlugin({
status: 400,
mockData: {
code: 3,
message: 'validation error',
details: [
{
'@type': 'type.googleapis.com/kong.admin.model.v1.ErrorDetail',
type: 'ERROR_TYPE_ENTITY',
messages: [
"at least one of these fields must be non-empty: 'config.api_specification_filename', 'config.api_specification'",
],
},
],
},
).as('validate')
})
const pluginType = 'mocking'

cy.mount(PluginForm, {
Expand All @@ -1835,7 +1780,7 @@ describe('<PluginForm />', () => {
cy.get('.kong-ui-entities-plugin-form-container').should('be.visible')

cy.getTestId('plugin-create-form-submit').click()
cy.wait('@validate')
cy.wait('@createPlugin')

cy.getTestId('form-error').should('be.visible')
})
Expand All @@ -1844,7 +1789,6 @@ describe('<PluginForm />', () => {
const config = { ...baseConfigKonnect, entityId: scopedService.id, entityType: 'services' }
interceptKonnectSchema()
interceptKonnectOperatePlugin({ method: 'GET', alias: 'getPlugin', id: plugin1.id })
interceptKonnectValidatePlugin()
interceptKonnectOperatePlugin({ method: 'PUT', alias: 'updatePlugin', id: plugin1.id })
const pluginType = 'cors'
interceptKonnectScopedEntity({ entityType: config.entityType }, pluginType)
Expand Down Expand Up @@ -1876,7 +1820,7 @@ describe('<PluginForm />', () => {

cy.getTestId('plugin-edit-form-submit').click()

cy.wait(['@validatePlugin', '@updatePlugin']).then(() => {
cy.wait('@updatePlugin').then(() => {
cy.get('@onUpdateSpy').should('have.been.calledOnce')
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1260,24 +1260,6 @@ const handleClickCancel = (): void => {
* ---------------
*/

/**
* Build the validate URL. Currently doesn't work for credentials.
*/
const validateSubmitUrl = computed((): string => {
let url = `${props.config.apiBaseUrl}${endpoints.form[props.config.app].validate}`

if (props.config.app === 'konnect') {
url = url.replace(/{controlPlaneId}/gi, props.config.controlPlaneId || '')
} else if (props.config.app === 'kongManager') {
url = url.replace(/\/{workspace}/gi, props.config.workspace ? `/${props.config.workspace}` : '')
}

// Always replace the id when editing
url = url.replace(/{id}/gi, props.pluginId)

return url
})

/**
* Build the submit URL
*/
Expand Down Expand Up @@ -1371,12 +1353,6 @@ const saveFormData = async (): Promise<void> => {
})
}

// TODO: determine validate URL for credentials
// don't validate custom plugins
if (!treatAsCredential.value && !isCustomPlugin.value) {
await axiosInstance.post(validateSubmitUrl.value, payload)
}

if (formType.value === 'create') {
response = await axiosInstance.post(submitUrl.value, payload)
} else if (formType.value === 'edit') {
Expand Down
2 changes: 0 additions & 2 deletions packages/entities/entities-plugins/src/plugins-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export default {
edit: `${konnectBaseApiUrl}/{resourceEndpoint}/{id}`,
},
credentialSchema: '/v2/control-planes/{controlPlaneId}/schemas/core-entities/{plugin}',
validate: `${konnectBaseApiUrl}/v1/schemas/json/plugin/validate`,
// VFG endpoints24
entityGetOne: `${konnectBaseApiUrl}/{entity}/{id}`,
entityGetAll: `${konnectBaseApiUrl}/{entity}`,
Expand All @@ -61,7 +60,6 @@ export default {
edit: `${KMBaseApiUrl}/{resourceEndpoint}/{id}`,
},
credentialSchema: `${KMBaseApiUrl}/schemas/{plugin}`,
validate: `${KMBaseApiUrl}/schemas/plugins/validate`,
// VFG endpoints
entityGetOne: `${KMBaseApiUrl}/{entity}/{id}`,
entityGetAll: `${KMBaseApiUrl}/{entity}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,23 +236,6 @@ const onCancel = (): void => {
* ---------------
*/

/**
* Build the validate and submit URL
*/

const validateSubmitUrl = computed((): string => {
let url = `${props.config.apiBaseUrl}${endpoints.form[props.config.app].validate}`

if (props.config.app === 'konnect') {
url = url.replace(/{controlPlaneId}/gi, props.config?.controlPlaneId || '')
} else if (props.config.app === 'kongManager') {
url = url.replace(/\/{workspace}/gi, props.config?.workspace ? `/${props.config.workspace}` : '')
}
// Always replace the id when editing
url = url.replace(/{id}/gi, props.targetId)
return url
})

/**
* Build the submit URL
*/
Expand Down Expand Up @@ -288,8 +271,6 @@ const saveFormData = async (): Promise<void> => {

let response: AxiosResponse | undefined

await axiosInstance.post(validateSubmitUrl.value, requestBody.value)

if (formType.value === 'create') {
response = await axiosInstance.post(submitUrl.value, requestBody.value)
} else if (formType.value === 'edit') {
Expand Down
Loading
Loading