Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to upload file #548

Open
amrsa1 opened this issue Jan 30, 2020 · 3 comments
Open

Unable to upload file #548

amrsa1 opened this issue Jan 30, 2020 · 3 comments

Comments

@amrsa1
Copy link

amrsa1 commented Jan 30, 2020

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
Copy link
Author

amrsa1 commented Jan 30, 2020

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
Copy link
Author

amrsa1 commented Jan 30, 2020

@vlucas @H1Gdev

@vlucas
Copy link
Owner

vlucas commented Jan 31, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants