Use SingleFile to create snapshots of web pages
This commit is contained in:
parent
785b6dd408
commit
0fba08b3c9
13 changed files with 1924 additions and 54 deletions
|
@ -141,6 +141,106 @@ describe("Zotero.Server", function () {
|
|||
assert.equal(req.responseText, "Test");
|
||||
});
|
||||
});
|
||||
|
||||
describe("multipart/form-data", function () {
|
||||
it("should support text", async function () {
|
||||
var called = false;
|
||||
var endpoint = "/test/" + Zotero.Utilities.randomString();
|
||||
|
||||
Zotero.Server.Endpoints[endpoint] = function () {};
|
||||
Zotero.Server.Endpoints[endpoint].prototype = {
|
||||
supportedMethods: ["POST"],
|
||||
supportedDataTypes: ["multipart/form-data"],
|
||||
|
||||
init: function (options) {
|
||||
called = true;
|
||||
assert.isObject(options);
|
||||
assert.property(options.headers, "Content-Type");
|
||||
assert(options.headers["Content-Type"].startsWith("multipart/form-data; boundary="));
|
||||
assert.isArray(options.data);
|
||||
assert.equal(options.data.length, 1);
|
||||
|
||||
let expected = {
|
||||
header: "Content-Disposition: form-data; name=\"foo\"",
|
||||
body: "bar",
|
||||
params: {
|
||||
name: "foo"
|
||||
}
|
||||
};
|
||||
assert.deepEqual(options.data[0], expected);
|
||||
return 204;
|
||||
}
|
||||
};
|
||||
|
||||
let formData = new FormData();
|
||||
formData.append("foo", "bar");
|
||||
|
||||
let req = await Zotero.HTTP.request(
|
||||
"POST",
|
||||
serverPath + endpoint,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
body: formData
|
||||
}
|
||||
);
|
||||
|
||||
assert.ok(called);
|
||||
assert.equal(req.status, 204);
|
||||
});
|
||||
|
||||
it("should support binary", async function () {
|
||||
let called = false;
|
||||
let endpoint = "/test/" + Zotero.Utilities.randomString();
|
||||
let file = getTestDataDirectory();
|
||||
file.append('test.png');
|
||||
let contents = await Zotero.File.getBinaryContentsAsync(file);
|
||||
|
||||
Zotero.Server.Endpoints[endpoint] = function () {};
|
||||
Zotero.Server.Endpoints[endpoint].prototype = {
|
||||
supportedMethods: ["POST"],
|
||||
supportedDataTypes: ["multipart/form-data"],
|
||||
|
||||
init: function (options) {
|
||||
called = true;
|
||||
assert.isObject(options);
|
||||
assert.property(options.headers, "Content-Type");
|
||||
assert(options.headers["Content-Type"].startsWith("multipart/form-data; boundary="));
|
||||
assert.isArray(options.data);
|
||||
assert.equal(options.data.length, 1);
|
||||
assert.equal(options.data[0].header, "Content-Disposition: form-data; name=\"image\"; filename=\"test.png\"\r\nContent-Type: image/png");
|
||||
let expected = {
|
||||
name: "image",
|
||||
filename: "test.png",
|
||||
contentType: "image/png"
|
||||
};
|
||||
assert.deepEqual(options.data[0].params, expected);
|
||||
assert.equal(options.data[0].body, contents);
|
||||
|
||||
return 204;
|
||||
}
|
||||
};
|
||||
|
||||
let image = await File.createFromFileName(OS.Path.join(getTestDataDirectory().path, 'test.png'));
|
||||
let formData = new FormData();
|
||||
formData.append("image", image);
|
||||
|
||||
let req = await Zotero.HTTP.request(
|
||||
"POST",
|
||||
serverPath + endpoint,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
body: formData
|
||||
}
|
||||
);
|
||||
|
||||
assert.ok(called);
|
||||
assert.equal(req.status, 204);
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue