-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from ubarsaiyan/custom-request
Add custom request API
- Loading branch information
Showing
5 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const joinURL = require("url-join"); | ||
const { handleResponseCode } = require("../response.js"); | ||
const { encodePath, prepareRequestOptions, request } = require("../request.js"); | ||
|
||
function customRequest(remotePath, requestOptions, options) { | ||
if (!requestOptions.url) { | ||
requestOptions.url = joinURL(options.remoteURL, encodePath(remotePath), "/"); | ||
} | ||
prepareRequestOptions(requestOptions, options); | ||
return request(requestOptions).then(handleResponseCode); | ||
} | ||
|
||
module.exports = { | ||
customRequest | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,5 +47,6 @@ function parseStat(result, filename, isDetailed = false) { | |
} | ||
|
||
module.exports = { | ||
getStat | ||
getStat, | ||
parseStat | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const { parseXML } = require("../../source/interface/dav.js"); | ||
const { parseStat } = require("../../source/interface/stat.js"); | ||
const { processResponsePayload } = require("../../source/response.js"); | ||
|
||
describe("custom", function() { | ||
beforeEach(function() { | ||
this.client = createWebDAVClient("http://localhost:9988/webdav/server", { | ||
username: createWebDAVServer.test.username, | ||
password: createWebDAVServer.test.password | ||
}); | ||
clean(); | ||
this.server = createWebDAVServer(); | ||
return this.server.start(); | ||
}); | ||
|
||
afterEach(function() { | ||
return this.server.stop(); | ||
}); | ||
|
||
it("send and parse stat custom request", function() { | ||
let response = null; | ||
return this.client | ||
.customRequest("/alrighty.jpg", { | ||
method: "PROPFIND", | ||
headers: { | ||
Accept: "text/plain", | ||
Depth: 0 | ||
}, | ||
responseType: "text" | ||
}) | ||
.then(res => { | ||
response = res; | ||
return res.data; | ||
}) | ||
.then(parseXML) | ||
.then(xml => parseStat(xml, "alrighty.jpg")) | ||
.then(result => processResponsePayload(response, result)) | ||
.then(function(stat) { | ||
expect(stat).to.be.an("object"); | ||
expect(stat).to.have.property("filename", "/alrighty.jpg"); | ||
expect(stat).to.have.property("basename", "alrighty.jpg"); | ||
expect(stat).to.have.property("lastmod").that.is.a.string; | ||
expect(stat).to.have.property("type", "file"); | ||
expect(stat).to.have.property("size", 52130); | ||
expect(stat).to.have.property("mime", "image/jpeg"); | ||
}); | ||
}); | ||
}); |