1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-08 04:50:06 +00:00

fix: file uploader error handling and tests

This commit is contained in:
Mihajlo Medjedovic
2020-10-30 16:11:50 +01:00
parent 7279c23fe2
commit 3f6e89d716
4 changed files with 122 additions and 28 deletions

View File

@@ -0,0 +1,93 @@
import { FileUploader } from '../FileUploader'
import { UploadFile } from '../types';
(global as any).fetch = jest.fn().mockImplementation(() =>
Promise.resolve({
text: () => Promise.resolve(sampleResponse),
})
);
it('should upload successfully', async (done) => {
const fileUploader =
new FileUploader(
'/sample/apploc',
'https://sample.server.com',
'/jobs/path',
null,
null
)
const sasJob = 'test/upload'
const files: UploadFile[] = [
{
file: new File([''], 'testfile'),
fileName: 'testfile'
}
];
const params = {table: 'libtable'}
fileUploader.uploadFile(sasJob, files, params).then(
(res: any) => {
if (JSON.stringify(res) === JSON.stringify(JSON.parse(sampleResponse))) done()
}
)
})
it('should throw no files error', async (done) => {
const fileUploader =
new FileUploader(
'/sample/apploc',
'https://sample.server.com',
'/jobs/path',
null,
null
)
const sasJob = 'test/upload'
const files: UploadFile[] = [];
const params = {table: 'libtable'}
fileUploader.uploadFile(sasJob, files, params).then(
(res: any) => {},
(err: any) => {
if (err.error.message === 'At least one file must be provided.') done()
}
)
})
it('should throw no sasJob error', async (done) => {
const fileUploader =
new FileUploader(
'/sample/apploc',
'https://sample.server.com',
'/jobs/path',
null,
null
)
const sasJob = ''
const files: UploadFile[] = [
{
file: new File([''], 'testfile'),
fileName: 'testfile'
}
];
const params = {table: 'libtable'}
fileUploader.uploadFile(sasJob, files, params).then(
(res: any) => {},
(err: any) => {
if (err.error.message === 'sasJob must be provided.') done()
}
)
})
const sampleResponse = `{
"SYSUSERID": "cas",
"_DEBUG":" ",
"SYS_JES_JOB_URI": "/jobExecution/jobs/000-000-000-000",
"_PROGRAM" : "/Public/app/editors/loadfile",
"SYSCC" : "0",
"SYSJOBID" : "117382",
"SYSWARNINGTEXT" : ""
}`