All files create.js

100% Statements 13/13
66.67% Branches 2/3
100% Functions 2/2
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28              12x 12x 12x   12x 12x     12x   12x 12x 12x   12x 12x 12x 12x      
import xhrRequest from './set_request';
import addHeaders from './manage_headers';
import getCSRF from './get_CSRF';
import createPromise from './create_promise';
 
export default function(url, rails = true){
  // let promise, xhr, headers, csrf;
  const csrf = getCSRF();
  const headers = addHeaders();
  headers.addCSRF(csrf.token);
 
  Eif (rails){
    headers.addRails();
  }
 
  const promise = createPromise();
  // console.log('promise', promise.resolve);
  const xhr = xhrRequest(promise.resolve, promise.reject);
  xhr.open('POST', url);
  headers.set(xhr.get());
 
  return function(data){
    data[csrf.param] = csrf.token;
    xhr.send(data);
    return promise.promise;
  };
};