frisby icon indicating copy to clipboard operation
frisby copied to clipboard

Unable to upload file

Open amrsa1 opened this issue 4 years ago • 3 comments

im trying to upload file as shown below but im getting error regarding timeout mo matter how much its

fit ('Verify Api will return status code 200 after successful bulk upload', async ()=> {
    const uploadedFile = path.resolve('../bulkTemplate/ACTIVATION.csv');
    let content = fs.createReadStream(uploadedFile);
    const form = frisby.formData();

    form.append('fileName', content);
    form.append('fileType', ".csv");
    form.append('scheduledDate', "2020-02-05");
    form.append('m2mAccountId', "31111");
    form.append('m2mPlatform', "GMNA");

    // let fileName = file.split('.')[0]+'_';
    // let extension = '.'+file.split('.')[1];
    // console.log(fileName);
    // let uploadedFile = fileName+D.fileDateFormat+extension;

    return frisby.timeout(timeout)
        .post('https://dsdev.sd.com/api/batch/upload',{
                body: form
            // fileType: ".csv",
            // scheduledDate: "2020-01-30",
            // m2mAccountId: "31111",
            // m2mPlatform: "GMNA"
        })
        .inspectBody()
        .expect('status',200)
},timeout);

**: Timeout - Async callback was not invoked within the 10000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 10000ms timeout specified by jest.setTimeout.Error:**

Note that when file is uploaded from UI the name is changing from ACTIVATION.csv to ACTIVATION_09-30-2020_14-28-35.csv were this date is the current date,so user can upload multiple files, but also there is validation for the name so it can't be named to anything else except ACTIVATION.csv

so i have add these lines const name= path.resolve('../bulkTemplate/ACTIVATION.csv'); let fileName = name.split('.')[0]+'_'; let extension = '.'+name.split('.')[1]; let uploadedFile = fileName+D.fileDateFormat+extension; // uploadedFile output will be equal to ACTIVATION_09-30-2020_14-28-35.csv to change the file name within post request but seems im missing something

then i do the following here

return frisby.timeout(timeout) .post('https://desdv.msdsdrl.com/api/batch/upload',{ fileName: uploadedFile // it the whole path as string not file , its posting file path fileType: extension, scheduledDate: "2020-01-30", m2mAccountId: "31111", m2mPlatform: "GMNA" })

in other word ACTIVATION.csv should be renamed to match this format ACTIVATION_MM-DD-YYYY_HH-MM-SS.csv first after that posted

amrsa1 avatar Jan 30 '20 14:01 amrsa1

update : i have update the test to be like this

fit ('Verify Api will return status code 200 after successful bulk upload', async ()=> {

    const template = path.resolve('./suite/bulkTemplate/ACTIVATION_01-30-2021_17-03-56.csv');
    let content = fs.createReadStream(template);
    const form = frisby.formData();

    form.append('fileName', content,{
        contentType: 'text/plain',
        knownLength: fs.statSync(template).size
    });
    form.append('fileType', ".csv");
    form.append('scheduledDate', "01-30-2021");
    form.append('m2mAccountId', "31111");
    form.append('m2mPlatform', "GMNA");

    let fileName = template.split('.')[0]+'_';
    let extension = '.'+template.split('.')[1];
    let uploadedFile = fileName+D.fileDateFormat+extension;

    return frisby.timeout(timeout)
        .setup({
            request: {
                headers: {
                    accept: 'application/json, text/plain, */*',
                    'Content-Type': form.getHeaders()['content-type'],
                }
            }
        })
        .post('https://deasdv.mssdnsdl.com/api/batch/upload',{

                body: form,
        })
        .inspectHeaders()
        .inspectBody()
        .expect('status',200)
},timeout);

getting status code 415 instead on 200

FAILURE Status: 415
JSON: {
    "message": "Content-Type is not supported or not sent"
}

amrsa1 avatar Jan 30 '20 16:01 amrsa1

@vlucas @H1Gdev

amrsa1 avatar Jan 30 '20 21:01 amrsa1

You don't need to send the header explicitly. There is an example of how to do this here: https://www.frisbyjs.com/file-uploads-with-frisbyjs.html

vlucas avatar Jan 31 '20 22:01 vlucas