first ditch, test still not working but hitting API URL working

This commit is contained in:
John McLear 2016-05-30 15:24:13 +08:00
parent d545630912
commit 248ec967e5
8 changed files with 88 additions and 14 deletions

View file

@ -342,15 +342,21 @@ exports.appendText = function(padID, text, callback)
/**
getHTML(padID, [rev]) returns the html of a pad
getHTML(padID, [rev], [authorColor]) returns the html of a pad
Example returns:
{code: 0, message:"ok", data: {text:"Welcome <strong>Text</strong>"}}
{code: 1, message:"padID does not exist", data: null}
*/
exports.getHTML = function(padID, rev, callback)
exports.getHTML = function(padID, rev, authorColor, callback)
{
console.log("tits");
console.log("authorColor", authorColor);
if(typeof authorColor == "function"){
callback = authorColor;
authorColor = undefined;
}
if(typeof rev == "function")
{
callback = rev;
@ -397,7 +403,7 @@ exports.getHTML = function(padID, rev, callback)
}
//get the html of this revision
exportHtml.getPadHTML(pad, rev, function(err, html)
exportHtml.getPadHTML(pad, rev, authorColor, function(err, html)
{
if(ERR(err, callback)) return;
html = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head
@ -409,7 +415,7 @@ exports.getHTML = function(padID, rev, callback)
//the client wants the latest text, lets return it to him
else
{
exportHtml.getPadHTML(pad, undefined, function (err, html)
exportHtml.getPadHTML(pad, undefined, authorColor, function (err, html)
{
if(ERR(err, callback)) return;
html = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head

Binary file not shown.

View file

@ -495,10 +495,61 @@ var version =
, "restoreRevision" : ["padID", "rev"]
, "appendText" : ["padID", "text"]
}
, "1.2.14":
{ "createGroup" : []
, "createGroupIfNotExistsFor" : ["groupMapper"]
, "deleteGroup" : ["groupID"]
, "listPads" : ["groupID"]
, "listAllPads" : []
, "createDiffHTML" : ["padID", "startRev", "endRev"]
, "createPad" : ["padID", "text"]
, "createGroupPad" : ["groupID", "padName", "text"]
, "createAuthor" : ["name"]
, "createAuthorIfNotExistsFor": ["authorMapper" , "name"]
, "listPadsOfAuthor" : ["authorID"]
, "createSession" : ["groupID", "authorID", "validUntil"]
, "deleteSession" : ["sessionID"]
, "getSessionInfo" : ["sessionID"]
, "listSessionsOfGroup" : ["groupID"]
, "listSessionsOfAuthor" : ["authorID"]
, "getText" : ["padID", "rev"]
, "setText" : ["padID", "text"]
, "getHTML" : ["padID", "rev", "authorColor"]
, "setHTML" : ["padID", "html"]
, "getAttributePool" : ["padID"]
, "getRevisionsCount" : ["padID"]
, "getSavedRevisionsCount" : ["padID"]
, "listSavedRevisions" : ["padID"]
, "saveRevision" : ["padID", "rev"]
, "getRevisionChangeset" : ["padID", "rev"]
, "getLastEdited" : ["padID"]
, "deletePad" : ["padID"]
, "copyPad" : ["sourceID", "destinationID", "force"]
, "movePad" : ["sourceID", "destinationID", "force"]
, "getReadOnlyID" : ["padID"]
, "getPadID" : ["roID"]
, "setPublicStatus" : ["padID", "publicStatus"]
, "getPublicStatus" : ["padID"]
, "setPassword" : ["padID", "password"]
, "isPasswordProtected" : ["padID"]
, "listAuthorsOfPad" : ["padID"]
, "padUsersCount" : ["padID"]
, "getAuthorName" : ["authorID"]
, "padUsers" : ["padID"]
, "sendClientsMessage" : ["padID", "msg"]
, "listAllGroups" : []
, "checkToken" : []
, "appendChatMessage" : ["padID", "text", "authorID", "time"]
, "getChatHistory" : ["padID"]
, "getChatHistory" : ["padID", "start", "end"]
, "getChatHead" : ["padID"]
, "restoreRevision" : ["padID", "rev"]
, "appendText" : ["padID", "text"]
}
};
// set the latest available API version here
exports.latestApiVersion = '1.2.13';
exports.latestApiVersion = '1.2.14';
// exports the versions so it can be used by the new Swagger endpoint
exports.version = version;

Binary file not shown.

View file

@ -25,7 +25,7 @@ var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var _analyzeLine = require('./ExportHelper')._analyzeLine;
var _encodeWhitespace = require('./ExportHelper')._encodeWhitespace;
function getPadHTML(pad, revNum, callback)
function getPadHTML(pad, revNum, authorColors, callback)
{
var atext = pad.atext;
var html;
@ -53,7 +53,7 @@ function getPadHTML(pad, revNum, callback)
function (callback)
{
html = getHTMLFromAtext(pad, atext);
html = getHTMLFromAtext(pad, atext, authorColors);
callback(null);
}],
// run final callback

Binary file not shown.

View file

@ -10,7 +10,7 @@ var filePath = path.join(__dirname, '../../../../APIKEY.txt');
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
apiKey = apiKey.replace(/\n$/, "");
var apiVersion = 1;
var apiVersion = "1.2.14";
var testPadId = makeid();
var lastEdited = "";
var text = generateLongText();
@ -84,6 +84,7 @@ describe('Permission', function(){
-> setHTML(padID) -- Should fail on invalid HTML
-> setHTML(padID) *3 -- Should fail on invalid HTML
-> getHTML(padID) -- Should return HTML close to posted HTML
-> getHTML(padID, authorColor) -- Should return HTML close to posted HTML with some Author markup
-> createPad -- Tries to create pads with bad url characters
*/
@ -200,7 +201,9 @@ describe('getText', function(){
describe('setText', function(){
it('creates a new Pad with text', function(done) {
api.get(endPoint('setText')+"&padID="+testPadId+"&text=testTextTwo")
var textString = "testText\tTwo"; // note the \t to emualte a tab
console.warn("Set text as ", textString);
api.get(endPoint('setText')+"&padID="+testPadId+"&text="+textString)
.expect(function(res){
if(res.body.code !== 0) throw new Error("Pad setting text failed");
})
@ -213,7 +216,8 @@ describe('getText', function(){
it('gets the Pad text', function(done) {
api.get(endPoint('getText')+"&padID="+testPadId)
.expect(function(res){
if(res.body.data.text !== "testTextTwo\n") throw new Error("Setting Text")
var expectedString = "testText Two\n";
if(res.body.data.text !== expectedString) throw new Error("Getting Text error")
})
.expect('Content-Type', /json/)
.expect(200, done)
@ -545,6 +549,19 @@ describe('getHTML', function(){
});
})
describe('getHTML', function(){
it('Gets the HTML of a Pad and include author info', function(done) {
api.get(endPoint('getHTML')+"&padID="+testPadId+"&authorColor=true")
.expect(function(res){
var html = res.body.data.html;
console.warn("html", html);
if(html !== html) throw new Error("Imported HTML does not match served HTML")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('createPad', function(){
it('errors if pad can be created', function(done) {
var badUrlChars = ["/", "%23", "%3F", "%26"];