All files patch.js

100% Statements 16/16
60% Branches 3/5
100% Functions 2/2
100% Lines 16/16
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 29 30 31 32 33                  23x 23x   23x 23x 23x   23x 23x     23x 23x   23x 23x 23x 23x 23x 23x 23x      
import add_id from './add_id';
import addMethod from './add_method';
import addHeaders from './manage_headers';
import getCSRF from './get_CSRF';
import createPromise from './create_promise';
import xhrRequest from './set_request';
 
export default function(url, rails = true){
  let csrf, data_set, headers, promise, xhr, url_id;
  csrf = getCSRF();
  headers = addHeaders();
 
  headers.addCSRF(csrf.token);
  url_id = add_id(url);
  data_set = addMethod(csrf, 'patch');
 
  Eif (rails){
    headers.addRails();
  }
 
  promise = createPromise();
  xhr = xhrRequest(promise.resolve, promise.reject);
 
  return function(data, id){
    let api = (id) ? url_id(id) : url;
    xhr.open('PUT', api);
    headers.set(xhr.get());
    data[csrf.param] = csrf.token;
    xhr.send(data_set(data));
    return promise.promise;
  };
};