Commit 9d44a1c5 authored by Jake Oliversen's avatar Jake Oliversen

New promises added to post and import function as well as changes to tests

parent 4ddaaaef
......@@ -128,7 +128,7 @@ SC.get = function(path, depth, callback, options){
if(!callback || typeof callback !== "function"){
return new Promise((resolve, reject)=>{
sc_self.getSling(path, options, (err, data)=>{
err ? reject(err) : resolve(data)
err ? reject(new Error(err)) : resolve(data)
});
})
}
......@@ -153,7 +153,7 @@ SC.getRaw = function(path, callback){
if(!callback || typeof(callback) !== "function"){
return new Promise((resolve, reject)=>{
this.getSling(path, {dontParseBody:true}, (err, data)=>{
err ? reject(err) : resolve(data)
err ? reject(new Error(err)) : resolve(data)
});
})
}
......@@ -181,7 +181,7 @@ SC.getSling = function(path, options, callback){
return new Promise((resolve, reject)=>{
this.getSling(path, options, (err, data) =>{
err ? reject(err) : resolve(data)
err ? reject(new Error(err)) : resolve(data)
});
})
}
......@@ -405,6 +405,15 @@ SC.getSling = function(path, options, callback){
path = "/" + path;
var sc_self=this;
if(!cb || typeof(cb) !== "function"){
return new Promise((resolve, reject)=>{
this.checkForBackingFile(path, preprocess, (err, data) =>{
err ? reject(new Error(err)) : resolve(data)
});
})
}
if(preprocess.fileMap){
cb(null, {path: preprocess.fileMap, useImmediately: true});
return;
......@@ -546,6 +555,14 @@ SC.import = function(path, data, options, callback){
form = _.merge(form, options.extraParams)
}
if(!callback || typeof(callback) !== "function"){
return new Promise((resolve, reject)=>{
this.import(path, data, options, (err, data) =>{
err ? reject(new Error(err)) : resolve(data)
});
})
}
// if(!options.protectNodes)
// form[':replace']="true"; // This seems to make sling fail when replacing jcr:content.
......@@ -601,6 +618,16 @@ SC.post = function(path,params,cb){
var sc_self=this;
params=params||{};
params._charset_ = params._charset_ || "utf-8";
if(!cb || typeof(cb) !== "function"){
return new Promise((resolve, reject)=>{
this.post(path, params, (err, data) =>{
err ? reject(new Error(err)) : resolve(data)
});
})
}
var settings={
url: this.buildUri(path),
timeout: this.timeout,
......
......@@ -15,7 +15,6 @@ test('Call get without callback', async done => {
let data = await sc.get('test1');
expect(data['something']).toBe("here");
}catch(err){
console.log(err);
expect(err).toBeDefined();
}finally{
done();
......
......@@ -5,7 +5,6 @@ const sc = new SlingConnector({baseUri: "../__fixtures__"});
test('Call getRaw with callback', done => {
sc.getRaw('test1' , (err, data) => {
console.log(data);
expect(data).toBe("{\"something\":\"here\",\"_jcr_something\":\"also here\",\"another\":{\"deeper\":\"one\"}}");
done();
})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment