From ed90cd80365651eda0ee0acb59585fb4dc653ab3 Mon Sep 17 00:00:00 2001 From: Mihajlo Date: Mon, 28 Mar 2022 17:32:30 +0200 Subject: [PATCH] chore: uploadFile test added --- sasjs-tests/package-lock.json | 20 ++++++------- sasjs-tests/src/App.tsx | 4 ++- sasjs-tests/src/testSuites/FileUpload.ts | 35 +++++++++++++++++++++++ sasjs-tests/src/testSuites/RequestData.ts | 1 + 4 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 sasjs-tests/src/testSuites/FileUpload.ts diff --git a/sasjs-tests/package-lock.json b/sasjs-tests/package-lock.json index 1117451..72347b4 100644 --- a/sasjs-tests/package-lock.json +++ b/sasjs-tests/package-lock.json @@ -2388,11 +2388,11 @@ "node_modules/@sasjs/adapter": { "version": "5.0.0", "resolved": "file:../build/sasjs-adapter-5.0.0.tgz", - "integrity": "sha512-lbDWueAEnfNlu4OGrc9hBEzT0aoLfAy7eLd2nLHArrF6zukcSGBNhUgOqxIhlz4WeBdf1gt3nk1G7p5X1mrWYQ==", + "integrity": "sha512-5qtEs9yFuZ4v2UrFGNHeCIr/yZTp7D9He+e+N333qW9mdLJJ8fzRifuur/rFE6bNPqC2bdCjicYkO/yrHR4LQw==", "hasInstallScript": true, "license": "ISC", "dependencies": { - "@sasjs/utils": "2.36.1", + "@sasjs/utils": "2.40.1", "axios": "0.26.0", "axios-cookiejar-support": "1.0.1", "form-data": "4.0.0", @@ -2422,9 +2422,9 @@ } }, "node_modules/@sasjs/utils": { - "version": "2.36.1", - "resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.36.1.tgz", - "integrity": "sha512-JkGUpLOODsvkeU+S25jb9k2WnvzyD2w6cEk7YyQ/byuqKL8xawH91PPWegrVcJlDY8WmqKE4CPcA3d1mM3B3LA==", + "version": "2.40.1", + "resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.40.1.tgz", + "integrity": "sha512-wWYElDH71bSZTdZ5V38743vAnw2EPDhzH7+1s7zxINHpaQWK/qrDldI0vgVFLeGpxVU0D7WPZ/ltG6MoE2obeg==", "hasInstallScript": true, "dependencies": { "@types/fs-extra": "9.0.13", @@ -20998,9 +20998,9 @@ }, "@sasjs/adapter": { "version": "file:../build/sasjs-adapter-5.0.0.tgz", - "integrity": "sha512-lbDWueAEnfNlu4OGrc9hBEzT0aoLfAy7eLd2nLHArrF6zukcSGBNhUgOqxIhlz4WeBdf1gt3nk1G7p5X1mrWYQ==", + "integrity": "sha512-5qtEs9yFuZ4v2UrFGNHeCIr/yZTp7D9He+e+N333qW9mdLJJ8fzRifuur/rFE6bNPqC2bdCjicYkO/yrHR4LQw==", "requires": { - "@sasjs/utils": "2.36.1", + "@sasjs/utils": "2.40.1", "axios": "0.26.0", "axios-cookiejar-support": "1.0.1", "form-data": "4.0.0", @@ -21022,9 +21022,9 @@ } }, "@sasjs/utils": { - "version": "2.36.1", - "resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.36.1.tgz", - "integrity": "sha512-JkGUpLOODsvkeU+S25jb9k2WnvzyD2w6cEk7YyQ/byuqKL8xawH91PPWegrVcJlDY8WmqKE4CPcA3d1mM3B3LA==", + "version": "2.40.1", + "resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.40.1.tgz", + "integrity": "sha512-wWYElDH71bSZTdZ5V38743vAnw2EPDhzH7+1s7zxINHpaQWK/qrDldI0vgVFLeGpxVU0D7WPZ/ltG6MoE2obeg==", "requires": { "@types/fs-extra": "9.0.13", "@types/prompts": "2.0.13", diff --git a/sasjs-tests/src/App.tsx b/sasjs-tests/src/App.tsx index d0b92a2..066c12a 100644 --- a/sasjs-tests/src/App.tsx +++ b/sasjs-tests/src/App.tsx @@ -6,6 +6,7 @@ import { specialCaseTests } from './testSuites/SpecialCases' import { sasjsRequestTests } from './testSuites/SasjsRequests' import '@sasjs/test-framework/dist/index.css' import { computeTests } from './testSuites/Compute' +import { fileUploadTests } from './testSuites/FileUpload' const App = (): ReactElement<{}> => { const { adapter, config } = useContext(AppContext) @@ -18,7 +19,8 @@ const App = (): ReactElement<{}> => { sendArrTests(adapter), sendObjTests(adapter), specialCaseTests(adapter), - sasjsRequestTests(adapter) + sasjsRequestTests(adapter), + fileUploadTests(adapter) ] if (adapter.getSasjsConfig().serverType === 'SASVIYA') { diff --git a/sasjs-tests/src/testSuites/FileUpload.ts b/sasjs-tests/src/testSuites/FileUpload.ts new file mode 100644 index 0000000..b068ee4 --- /dev/null +++ b/sasjs-tests/src/testSuites/FileUpload.ts @@ -0,0 +1,35 @@ +import SASjs from '@sasjs/adapter' +import { TestSuite } from '@sasjs/test-framework' + +export const fileUploadTests = (adapter: SASjs): TestSuite => ({ + name: 'File Upload Tests', + tests: [ + { + title: 'Upload File', + description: 'Should upload the file to VIYA', + test: async () => { + let blob: any = new Blob(['test'], { type: 'text/html' }) + blob['lastModifiedDate'] = '' + blob['name'] = 'macvars_testfile' + let file = blob + + const filesToUpload = [ + { + file: file, + fileName: file.name + } + ] + + return adapter.uploadFile('common/sendMacVars', filesToUpload, null) + }, + assertion: (response: any) => + (response.macvars as any[]).findIndex( + (el: any) => el.NAME === '_WEBIN_FILE_COUNT' && el.VALUE === '1' + ) > -1 && + (response.macvars as any[]).findIndex( + (el: any) => + el.NAME === '_WEBIN_FILENAME' && el.VALUE === 'macvars_testfile' + ) > -1 + } + ] +}) diff --git a/sasjs-tests/src/testSuites/RequestData.ts b/sasjs-tests/src/testSuites/RequestData.ts index b4bf93e..c0584e9 100644 --- a/sasjs-tests/src/testSuites/RequestData.ts +++ b/sasjs-tests/src/testSuites/RequestData.ts @@ -218,6 +218,7 @@ export const sendObjTests = (adapter: SASjs): TestSuite => ({ const invalidData: any = { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: [{ col1: 42 }] } + return adapter.request('common/sendObj', invalidData).catch((e) => e) }, assertion: (error: any) =>