Skip to content

Commit

Permalink
Made changes w.r.t construct types for params
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaramakrishnan-techconative committed Nov 10, 2023
1 parent d12907c commit ff023cd
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 47 deletions.
2 changes: 1 addition & 1 deletion dist/config-import-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/config-import-bundle.js.map

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions dist/log.bundle-sizes.rest-import-ui.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@mui\icons-material: 5.93 MB (53.6%)
@mui\material: 1.28 MB (11.6%)
@mui\base: 387.29 KB (3.42%)
@mui\material: 1.28 MB (11.5%)
@mui\base: 387.29 KB (3.41%)
lodash: 239.44 KB (2.11%)
core-js-pure: 166.41 KB (1.47%)
@mui\system: 162.12 KB (1.43%)
Expand All @@ -12,7 +12,7 @@ axios: 87.01 KB (0.767%)
@reduxjs\toolkit: 84.36 KB (0.744%)
i18next: 82.68 KB (0.729%)
@popperjs\core: 68.84 KB (0.607%)
buffer: 56.99 KB (0.503%)
buffer: 56.99 KB (0.502%)
react-transition-group: 55.52 KB (0.490%)
@emotion\cache: 40.02 KB (0.353%)
@mui\utils: 34.3 KB (0.302%)
Expand All @@ -27,7 +27,7 @@ url-parse: 16.23 KB (0.143%)
@emotion\serialize: 13.35 KB (0.118%)
js-base64: 10.11 KB (0.0891%)
react-hot-toast: 9.31 KB (0.0821%)
reselect: 8.85 KB (0.0781%)
reselect: 8.85 KB (0.0780%)
react: 7.98 KB (0.0704%)
redux-immutable: 5.43 KB (0.0479%)
process: 5.29 KB (0.0467%)
Expand All @@ -40,15 +40,15 @@ deep-extend: 4.19 KB (0.0370%)
base64-js: 3.84 KB (0.0339%)
@mui\styled-engine: 3.55 KB (0.0313%)
@mui\private-theming: 3.5 KB (0.0309%)
css.escape: 3.08 KB (0.0272%)
css.escape: 3.08 KB (0.0271%)
serialize-error: 2.93 KB (0.0258%)
hoist-non-react-statics: 2.68 KB (0.0236%)
prop-types: 2.6 KB (0.0229%)
use-sync-external-store: 2.59 KB (0.0229%)
querystringify: 2.5 KB (0.0221%)
react-is: 2.4 KB (0.0212%)
goober: 2.23 KB (0.0197%)
ieee754: 2.1 KB (0.0186%)
ieee754: 2.1 KB (0.0185%)
html-parse-stringify: 2.09 KB (0.0185%)
@emotion\utils: 1.72 KB (0.0152%)
safe-buffer: 1.63 KB (0.0144%)
Expand All @@ -59,9 +59,9 @@ randombytes: 1.54 KB (0.0136%)
@braintree\sanitize-url: 1.38 KB (0.0122%)
redux-thunk: 1.27 KB (0.0112%)
@emotion\unitless: 924 B (0.00796%)
inherits: 753 B (0.00649%)
requires-port: 753 B (0.00649%)
@emotion\use-insertion-effect-with-fallbacks: 472 B (0.00407%)
inherits: 753 B (0.00648%)
requires-port: 753 B (0.00648%)
@emotion\use-insertion-effect-with-fallbacks: 472 B (0.00406%)
@emotion\weak-memoize: 379 B (0.00326%)
clsx: 374 B (0.00322%)
void-elements: 338 B (0.00291%)
Expand Down
2 changes: 1 addition & 1 deletion dist/rest-import-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/rest-import-bundle.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rest-import-wavemaker",
"version": "0.1.54",
"version": "0.1.57",
"private": false,
"main": "./dist/core/components/RestImport.js",
"release": {
Expand Down Expand Up @@ -54,7 +54,7 @@
"url-parse": "^1.5.10"
},
"scripts": {
"start": "react-scripts start",
"start": "set PORT=4200 && react-scripts start",
"dev": "npx tsc --jsx preerve -t es2020 --outDir src/jsx --noEmit false && webpack serve --config webpack/dev.babel.js",
"build": "npx tsc --jsx preserve -t es2020 --outDir src/jsx --noEmit false && webpack --color --config webpack/stylesheets.babel.js && webpack --color --config webpack/bundle.babel.js && webpack --color --config webpack/bundle.config.babel.js && bash dist-to-examples.sh",
"build-windows": "npx tsc --jsx preserve -t es2020 --outDir src/jsx --noEmit false && webpack --color --config webpack/stylesheets.babel.js && webpack --color --config webpack/bundle.babel.js && webpack --color --config webpack/bundle.config.babel.js",
Expand Down
8 changes: 4 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import { AxiosRequestConfig, AxiosResponse } from 'axios';
export default function App() {
const config: restImportConfigI = {
proxy_conf: {
base_path: "http://localhost:4000/",
proxy_path: "restimport",
base_path: "http://localhost:4200/",
proxy_path: "studio/services/projects/WMPRJ2c91808889a96400018a26070b7b2e68/restservices/invoke?optimizeResponse=true",
list_provider: "get-default-provider",
getprovider: "getprovider",
addprovider: "addprovider",
authorizationUrl: "authorizationUrl",
},
useProxy: true,
url: "https://jsonplaceholder.typicode.com/posts",
projectId: "WMPRJ2c91808889a96400018a26070b7b2e68",
projectId: "WMPRJ2c91808889a96400018a26070b7b2e68",
loggenInUserId: "fe",
appEnvVariables: [{ key: 'we', value: 'ew' }],
loggenInUserName: 'vew',
headerParams: [{
name: "new",
type: "string",
type: "DATE",
value: "vew"
}],
queryParams: [{
Expand Down
7 changes: 0 additions & 7 deletions src/core/components/ConfigModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,13 @@ export default function ConfigModel({ handleOpen, handleClose, handleParentModal
} else if (!clientSecret && !PKCE) {
setAlertMsg(translate('CLIENTSECRET_ALERT'))
} else {

setloading(true)
setShowErrorAlert(false);
const scopes_val: { name: string; value: string }[] = scopes.filter(item => item.checked).map(({ checked, ...rest }) => rest);
const scope_map_obj: { [key: string]: boolean } = scopes.reduce((result, item) => {
result[item.name] = item.checked || false;
return result;
}, {} as { [key: string]: boolean });

const newProvider = {
accessTokenParamName: "Bearer",
accessTokenUrl: accessTokenUrl,
Expand Down Expand Up @@ -351,7 +349,6 @@ export default function ConfigModel({ handleOpen, handleClose, handleParentModal
</IconButton>
</Tooltip>
</Grid>

{PKCE && (
<Grid item md={7} className='cmnflx' container>
<Grid item md={5}>
Expand All @@ -369,10 +366,8 @@ export default function ConfigModel({ handleOpen, handleClose, handleParentModal
</Select>
</FormControl>
</Grid>

</Grid>
)}

<Grid item md={3}>
<Typography>{translate("AUTHORIZATION") + " " + translate("URL")} <span className='text-danger'>*</span></Typography>
</Grid>
Expand All @@ -396,7 +391,6 @@ export default function ConfigModel({ handleOpen, handleClose, handleParentModal
<Grid item md={3} >
<Typography>{translate("CLIENT") + " " + translate("SECRET")} <span className='text-danger'>*</span></Typography>
</Grid>

<Grid item md={9}>
<TextField sx={{ width: "30em" }} defaultValue={providerConf?.clientSecret} size='small' onChange={handleClientSecret} placeholder={translate("CLIENT") + " " + translate("SECRET")} label={translate("CLIENT") + " " + translate("SECRET")} />
</Grid>
Expand All @@ -421,7 +415,6 @@ export default function ConfigModel({ handleOpen, handleClose, handleParentModal
<Typography>{translate("SCOPE")}</Typography>
</Grid>
<Grid item md={9}>

<Grid className='cmnflx' spacing={1} container>
<Grid item md={12}>
<Stack>
Expand Down
56 changes: 44 additions & 12 deletions src/core/components/RestImport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,10 @@ export default function RestImport({ language, restImportConfig }: { language: s
}
async function settingsUpload(request: any, response: any) {
const headers = response.headers;
for (const key in headers) {
if (headers.hasOwnProperty(key)) {
// eslint-disable-next-line no-self-assign
headers[key] = headers[key];
}
}
const constructHeaders: any = {};
headerParams.forEach((obj: any) => {
constructHeaders[obj.name] = obj.value;
headerParams.forEach((obj) => {
if (obj.name !== '' && obj.value !== '')
constructHeaders[obj.name] = obj.value;
});
const data = {
authDetails:
Expand All @@ -706,7 +701,7 @@ export default function RestImport({ language, restImportConfig }: { language: s
convertedResponse: null,
statusCode: response?.status,
},
requestBody: request.body
requestBody: request.body || ""
};
const dataConfig: AxiosRequestConfig = {
url: restImportConfig.proxy_conf.base_path + `services/projects/${restImportConfig.projectId}/restservice/settings`,
Expand All @@ -716,6 +711,36 @@ export default function RestImport({ language, restImportConfig }: { language: s
const settingsUploadResponse: any = await Apicall(dataConfig)
if (response.status >= 200 && response.status < 300) {
let settingsUploadResponseData = settingsUploadResponse.data
const params: any[] = getParamsWithTypes(settingsUploadResponseData).paramaters
const firstKey = getParamsWithTypes(settingsUploadResponseData).firstKey
const secondKey = getParamsWithTypes(settingsUploadResponseData).secondKey
const headers = constructHeaders
const query = queryParams
params.forEach((param) => {
if (param.in === 'header') {
for (const key in headers) {
if (headers.hasOwnProperty(key)) {
if (param.name === key) {
const type = headerParams.find(param => param.name === key)?.type
param['format'] = type
param.items.type = type
}
}
}
}
else if (param.in === 'query') {
for (const key in query) {
if (query.hasOwnProperty(key)) {
if (param.name === key) {
const type = queryParams.find(param => param.name === key)?.type
param['format'] = type
param.items.type = type
}
}
}
}
})
settingsUploadResponseData.swagger.paths[firstKey][secondKey].parameters = params
settingsUploadResponseData['proxySettings'] = {
mobile: useProxy ? 'PROXY' : 'DIRECT',
web: useProxy ? 'PROXY' : 'DIRECT',
Expand All @@ -724,11 +749,18 @@ export default function RestImport({ language, restImportConfig }: { language: s
settingsUploadResponseData['serviceId'] = serviceName.trim() !== '' ? serviceName : settingsUploadResponseData['serviceId']
return settingsUploadResponseData
}
else {
else
handleToastError("Failed to get settings upload response", settingsUploadResponse)
}
}

function getParamsWithTypes(response: any): { paramaters: any[], firstKey: string, secondKey: string } {
const swaggerPaths = response.swagger.paths;
const [firstKey] = Object.keys(swaggerPaths);
const firstObject = swaggerPaths[firstKey];
const [secondKey] = Object.keys(firstObject);
const secondObject = firstObject[secondKey];
const paramaters = secondObject.parameters;
return { paramaters, firstKey, secondKey };
}
const handleCloseConfig = () => {
setConfigOpen(false)
}
Expand Down
10 changes: 4 additions & 6 deletions src/test/configmodel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ describe("Config Modal", () => {
const callbackURL = screen.getByRole('textbox', {
name: /callback url/i
})
expect(callbackURL.getAttribute('value')).toEqual(emptyConfig.proxy_conf.base_path + '/oauth2/ProviderTest/callback')
expect(callbackURL.getAttribute('value')).toEqual(emptyConfig.proxy_conf.base_path + 'oauth2/ProviderTest/callback')

}, 80000);

Expand All @@ -497,7 +497,7 @@ describe("Config Modal", () => {
const callbackURL = screen.getByRole('textbox', {
name: /callback url/i
})
expect(callbackURL.getAttribute('value')).toEqual(emptyConfig.proxy_conf.base_path + '/oAuthCallback.html')
expect(callbackURL.getAttribute('value')).toEqual(emptyConfig.proxy_conf.base_path + 'oAuthCallback.html')

}, 80000);

Expand All @@ -519,7 +519,7 @@ describe("Config Modal", () => {
expect(tooltipCopied.getAttribute('aria-label')).toBe('Copied!')
}, 80000);

it("MouseLeave from copy icon ", async () => {
it("MouseLeave from copy icon", async () => {
user.setup()
renderComponent('withoutProviderConf')
const providerId = screen.getByRole('textbox', {
Expand Down Expand Up @@ -564,7 +564,7 @@ describe("Config Modal", () => {

}, 80000)

it("Check ProviderID Disable While Render with Provider config data ", async () => {
it("Check ProviderID Disable While Render with Provider config data", async () => {
user.setup()
renderComponent('ProviderConfigWithoutPKCE')
const modalTitle = screen.getByRole('heading', { name: /oauth provider configuration help/i })
Expand Down Expand Up @@ -597,9 +597,7 @@ describe("Config Modal", () => {
renderComponent('ProviderConfigWithPKCEBasic')
const modalTitle = screen.getByRole('heading', { name: /oauth provider configuration help/i })
expect(modalTitle).toBeInTheDocument();

await checkAllFieldPrefilled()

const pkce = within(screen.getByTestId("pkce-checkbox")).getByRole("checkbox")
expect(pkce).toBeChecked()
const challengeMethod = within(screen.getByTestId("challenge-method")).getByRole("button")
Expand Down
2 changes: 1 addition & 1 deletion src/test/restimport.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ describe("Web Service Modal", () => {

}, 80000)

it("Switched between response tabs and verified their content", async () => {
fit("Switched between response tabs and verified their content", async () => {
user.setup()
renderComponent(mockEmptyProps)
const urlTextField = screen.getByRole('textbox', { name: /url/i })
Expand Down
3 changes: 1 addition & 2 deletions src/test/testdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const RESPONSE_TABS = [
"RESPONSE HEADER",
"RESPONSE STATUS",
];
export const AUTH_OPTIONS = ["None", "Basic", "OAuth 2.0"];
export const AUTH_OPTIONS = ["None", "Basic", "OAuth2"];
export const ERROR_MESSAGES = {
EMPTY_URL: "Please provide a valid URL",
EMPTY_BASIC_AUTH_USERNAME: "Please enter a username for basic authentication",
Expand Down Expand Up @@ -204,7 +204,6 @@ export const HEADER_TYPE_OPTIONS = [
"Current Timestamp",
"LoggedIn UserId",
"LoggedIn Username",
"Option 1",
];

export const CONTENT_TYPE = [
Expand Down

0 comments on commit ff023cd

Please sign in to comment.