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

How to convert object to string in frisby? #508

Open
SumanaRameshBaswan opened this issue Dec 11, 2018 · 1 comment
Open

How to convert object to string in frisby? #508

SumanaRameshBaswan opened this issue Dec 11, 2018 · 1 comment
Labels

Comments

@SumanaRameshBaswan
Copy link

SumanaRameshBaswan commented Dec 11, 2018

I am using axios to make http requests, I have a form data to be sent which i am passing as shown below

function addrequestData (token) {
const form = new FormData();
form.append('dateOfJoining', '360112000');
form.append('selectedGroups', JSON.stringify([1])); // [1] data has to be sent in a JSON format
form.append('jobLocation', '1' );

const httpHeaders = form.getHeaders();
httpHeaders.Authorization =  token;
const httpObj = {
    headers: httpHeaders,
    url:     '/admin/hr/addEmployeeBasicInfo',
    data:    form
};
const id = requestData(httpObj, false);

return id.then(({ userInfo }) => {
    return userInfo['createdUserId'];
});

}
My question is How do I make sure that [1] gets converted to string in frisby?

@H1Gdev
Copy link
Collaborator

H1Gdev commented Dec 11, 2018

@SumanaRameshBaswan

I don't know how to use frisby in above code...

If you use Promise chain, it looks like the following code.

const frisby = require('frisby');

function addrequestData (token) {
  return frisby.get(url)
    .then(res => {
      const form = new FormData();
      form.append('dateOfJoining', '360112000');
      form.append('selectedGroups', JSON.stringify(res.body)); // Received using frisby.
      form.append('jobLocation', '1' );

      const httpHeaders = form.getHeaders();
      httpHeaders.Authorization = token;
      const httpObj = {
        headers: httpHeaders,
        url:     '/admin/hr/addEmployeeBasicInfo',
        data:    form
      };
      return requestData(httpObj, false); // maybe returns Promise.
    })
    .then(({ userInfo }) => {
      return userInfo['createdUserId'];
    });
}

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

No branches or pull requests

2 participants