diff --git a/package-lock.json b/package-lock.json index 3207bc7..306d585 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,12 +55,13 @@ "eslint-plugin-jsx-a11y": "6.9.0", "eslint-plugin-react": "7.35.0", "expect": "1.20.2", - "explorer-fvt-utilities": "2.0.4", + "explorer-fvt-utilities": "3.0.1", "file-loader": "6.2.0", "html-webpack-plugin": "5.6.0", "mocha": "10.7.3", "mocha-jenkins-reporter": "0.4.8", "nock": "13.5.5", + "node-fetch": "^2.7.0", "npm-run-all": "4.1.5", "nyc": "17.0.0", "redux-mock-store": "1.5.4", @@ -6147,9 +6148,9 @@ } }, "node_modules/explorer-fvt-utilities": { - "version": "2.0.4", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/explorer-fvt-utilities/-/explorer-fvt-utilities-2.0.4.tgz", - "integrity": "sha512-ktDkd4HrjW06MAb/cUAApz8+J7cIE0PPK060UQo5qtF68mEqUqyMQYc9GTWOuH1mFIcrB497YQDZaxVMq+AS8A==", + "version": "3.0.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/explorer-fvt-utilities/-/explorer-fvt-utilities-3.0.1.tgz", + "integrity": "sha512-bD1ngoYCpFvP4JBZdvvkuRzT59+6Rv8njxut8XZoQzDOVIr7XO3yCOqcTAGRMHhosNgYV4EhFcsx+14zsBKpfg==", "dev": true, "dependencies": { "chromedriver": "92.0.2", @@ -9358,6 +9359,26 @@ "node": ">= 10.13" } }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dev": true, + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/node-forge": { "version": "1.3.1", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/node-forge/-/node-forge-1.3.1.tgz", @@ -12564,6 +12585,12 @@ "node": ">=6" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "dev": true + }, "node_modules/ts-node": { "version": "8.6.2", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/ts-node/-/ts-node-8.6.2.tgz", @@ -13009,6 +13036,12 @@ "minimalistic-assert": "^1.0.0" } }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "dev": true + }, "node_modules/webpack": { "version": "5.94.0", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/webpack/-/webpack-5.94.0.tgz", @@ -13323,6 +13356,16 @@ "node": ">=0.8.0" } }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dev": true, + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 560f7db..abcc6bb 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,9 @@ "devDependencies": { "@babel/eslint-parser": "7.25.1", "@babel/plugin-proposal-decorators": "7.24.7", - "@babel/preset-stage-0": "7.8.3", "@babel/preset-env": "7.25.4", "@babel/preset-react": "7.24.7", + "@babel/preset-stage-0": "7.8.3", "@babel/register": "7.24.6", "@types/chai": "4.3.18", "@types/mocha": "10.0.7", @@ -51,7 +51,7 @@ "eslint-plugin-jsx-a11y": "6.9.0", "eslint-plugin-react": "7.35.0", "expect": "1.20.2", - "explorer-fvt-utilities": "2.0.4", + "explorer-fvt-utilities": "3.0.1", "file-loader": "6.2.0", "html-webpack-plugin": "5.6.0", "mocha": "10.7.3", @@ -59,6 +59,7 @@ "nock": "13.5.5", "npm-run-all": "4.1.5", "nyc": "17.0.0", + "node-fetch": "^2.7.0", "redux-mock-store": "1.5.4", "rewire": "7.0.0 ", "rimraf": "3.0.2", diff --git a/tests/FVTTests/utilities.ts b/tests/FVTTests/utilities.ts index d432578..438a88d 100644 --- a/tests/FVTTests/utilities.ts +++ b/tests/FVTTests/utilities.ts @@ -8,7 +8,11 @@ * Copyright IBM Corporation 2020 */ -import https = require('https'); +import * as https from 'https'; +import fetch from 'node-fetch'; + +process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; + import { SERVER_HOST, @@ -16,84 +20,84 @@ import { b64Credentials, TEST_PARTITIONED_DATASET, TEST_SEQUENTIAL_DATASET, - TEST_DATASET_MEMBER} from './environment'; + TEST_DATASET_MEMBER +} from './environment'; import { WebDriver, WebElement, By, until, Key } from 'selenium-webdriver'; -function getHttpsAgent() :https.Agent { - return new https.Agent({ - rejectUnauthorized: false, - }); -} - -export async function createTestPartitionedDataset() { - await deleteDataset(TEST_PARTITIONED_DATASET, true); //try to delete dataset if it didn't get cleaned up last time +async function createTestPartitionedDataset() { + await deleteDataset(TEST_PARTITIONED_DATASET, true); await createDataset({ - primary: 300, - alcunit: "TRK", - recfm: "FB", - dsorg: "PO", - name:`${TEST_PARTITIONED_DATASET}`, - dirblk: 20, - secondary: 100, - lrecl: 80 - }) + name: `${TEST_PARTITIONED_DATASET}`, + volser: "zmf046", + unit: "3390", + dsorg: "PO", + alcunit: "TRK", + primary: 10, + secondary: 5, + dirblk: 10, + avgblk: 500, + recfm: "FB", + blksize: 400, + lrecl: 80 + }); } - -export async function createTestSequentialDataset() { - await deleteDataset(TEST_SEQUENTIAL_DATASET, true) //try to delete dataset if it didn't get cleaned up last time +async function createTestSequentialDataset() { + await deleteDataset(TEST_SEQUENTIAL_DATASET, true); await createDataset({ - primary:300, - alcunit: "TRK", - recfm:"FB", - dsorg:"PS", - name:`${TEST_SEQUENTIAL_DATASET}`, - secondary:100, - lrecl:80 - }) + volser: "zmf046", + name: `${TEST_SEQUENTIAL_DATASET}`, + unit: "3390", + dsorg: "PS", + alcunit: "TRK", + primary: 10, + secondary: 5, + avgblk: 500, + recfm: "FB", + blksize: 400, + lrecl: 80 + }); } interface DatasetCreationParams { - primary :number, - alcunit :string, - recfm :string, - dsorg :string, - name? :string, - dirblk? :number, - secondary :number, - lrecl :number, + primary: number; + alcunit: string; + recfm: string; + dsorg: string; + secondary: number; + lrecl: number; + volser: string; + unit: string; + avgblk: number; + blksize: number; + dirblk?: number; + name?: string; } -async function createDataset(requestBody :DatasetCreationParams) { - const agent :https.Agent = getHttpsAgent(); - await fetch(`https://${SERVER_HOST}:${SERVER_PORT}/ibmzosmf/api/v1/zosmf/restfiles/ds/${requestBody.name}`, { +async function createDataset(requestBody: DatasetCreationParams) { + const response = await fetch(`https://${SERVER_HOST}:${SERVER_PORT}/ibmzosmf/api/v1/zosmf/restfiles/ds/${requestBody.name}`, { method: 'POST', headers: { authorization: b64Credentials, 'Content-Type': 'application/json', 'X-CSRF-ZOSMF-HEADER': '*', }, - agent, body: JSON.stringify(requestBody), - }).then( - async response => { - if (response.ok) { - console.log(`${requestBody.name}, created succesfully`); - } else { - console.log(`${requestBody.name}, create failed`); - return response.json().then(e => { - console.log(e.message); - throw Error(e.message); - }); - } - }, - ) + }); + + if (response.ok) { + console.log(`${requestBody.name}, created successfully`); + } else { + console.log(`${requestBody.name}, create failed`); + const error = await response.json(); + console.log(error.message); + throw new Error(error.message); + } } -export async function createTestDatasetMember() { - const agent :https.Agent = getHttpsAgent(); +async function createTestDatasetMember() { const fullDatasetAndMemberName = `${TEST_PARTITIONED_DATASET}(${TEST_DATASET_MEMBER})`; - await fetch(`https://${SERVER_HOST}:${SERVER_PORT}/ibmzosmf/api/v1/zosmf/restfiles/ds/${fullDatasetAndMemberName}`, { + const response = await fetch(`https://${SERVER_HOST}:${SERVER_PORT}/ibmzosmf/api/v1/zosmf/restfiles/ds/${fullDatasetAndMemberName}`, { method: 'PUT', headers: { authorization: b64Credentials, @@ -102,55 +106,44 @@ export async function createTestDatasetMember() { 'X-CSRF-ZOSMF-HEADER': '*', }, body: '', - agent, - }).then ( - async response => { - if(response.ok) { - console.log(`${fullDatasetAndMemberName}, created succesfully`); - } else { - console.log(`${fullDatasetAndMemberName}, create failed`); - return response.json().then(e => { - console.log(e.message); - throw Error(e.message); - }); - } - } - ) -} + }); + if (response.ok) { + console.log(`${fullDatasetAndMemberName}, created successfully`); + } else { + console.log(`${fullDatasetAndMemberName}, create failed`); + const error = await response.json(); + console.log(error.message); + throw new Error(error.message); + } +} -export async function cleanupDatasets(failOk = false){ +async function cleanupDatasets(failOk = false) { await deleteDataset(TEST_PARTITIONED_DATASET, true); await deleteDataset(TEST_SEQUENTIAL_DATASET, true); } -/** - * - * @param failOk If you're unsure if the dataset exists set this to true to avoid failing a test - */ -export async function deleteDataset(dataset :string, failOk = false) { - const agent :https.Agent = getHttpsAgent(); - await fetch(`https://${SERVER_HOST}:${SERVER_PORT}/ibmzosmf/api/v1/zosmf/restfiles/ds/${dataset}`, { +async function deleteDataset(dataset: string, failOk = false) { + const response = await fetch(`https://${SERVER_HOST}:${SERVER_PORT}/ibmzosmf/api/v1/zosmf/restfiles/ds/${dataset}`, { method: 'DELETE', - headers: { authorization: b64Credentials, 'X-CSRF-ZOSMF-HEADER': '*' }, - agent - }).then( - async response => { - if (response.ok) { - console.log(`${dataset}, deleted succesfully`); - } else { - console.log(`${dataset}, delete failed`); - console.log(`${response.status} : ${response.statusText}`); - //failOk can be set when you're not sure if the dataset exists that you're trying to delete - if(!failOk) { - throw Error(`Delete dataset failed - ${response.status} : ${response.statusText}`); - } - } + headers: { + authorization: b64Credentials, + 'X-CSRF-ZOSMF-HEADER': '*' }, - ); + }); + + if (response.ok) { + console.log(`${dataset}, deleted successfully`); + } else { + console.log(`${dataset}, delete failed`); + console.log(`${response.status} : ${response.statusText}`); + if (!failOk) { + throw new Error(`Delete dataset failed - ${response.status} : ${response.statusText}`); + } + } } -export async function editDatasetQualifierField(driver :WebDriver, searchQualifier :string) { +async function editDatasetQualifierField(driver: WebDriver, searchQualifier: string) { const qualifierField: WebElement = await driver.findElement(By.id("datasets-qualifier-field")); await qualifierField.clear(); await qualifierField.sendKeys(searchQualifier); @@ -159,3 +152,13 @@ export async function editDatasetQualifierField(driver :WebDriver, searchQualifi await driver.sleep(500); await driver.wait(until.elementLocated(By.id('refresh-icon')), 20000); } + + +export { + createTestPartitionedDataset, + createTestSequentialDataset, + createTestDatasetMember, + cleanupDatasets, + deleteDataset, + editDatasetQualifierField +};