All files destroy.js

100% Statements 15/15
60% Branches 3/5
100% Functions 2/2
100% Lines 15/15
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                  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;
  const csrf = getCSRF();
  const headers = addHeaders();
 
  headers.addCSRF(csrf.token);
  const url_id = add_id(url);
  const data_set = addMethod(csrf, 'delete');
  Eif (rails){
    headers.addRails();
  }
 
  const promise = createPromise();
  const xhr = xhrRequest(promise.resolve, promise.reject);
 
  return function(id, data){
    let api = (id) ? url_id(id) : url;
    xhr.open('DELETE', api);
    // data[csrf.param] = csrf.token;
    headers.set(xhr.get());
    xhr.send(data_set(data));
    return promise.promise;
  };
};