Skip to content

Commit

Permalink
Added exportHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTV12345 committed Apr 6, 2024
1 parent 23ecfad commit bbda3c5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 15 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"devDependencies": {
"eslint": "^8.57.0",
"eslint-config-etherpad": "^4.0.4",
"typescript": "^5.4.2"
"typescript": "^5.4.2",
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.4"
},
"scripts": {
"lint": "eslint .",
Expand Down
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,46 @@

const common = require('ep_etherpad-lite/tests/backend/common');
const randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
import {generateJWTToken} from "ep_etherpad-lite/tests/backend/common";

let agent;
const apiKey = common.apiKey;
const apiVersion = 1;

const getMarkdownEndPointFor = (padID) => `/p/${padID}/export/markdown`;
const getMarkdownEndPointFor = (padID: string) => `/p/${padID}/export/markdown`;

const buildHTML = (body) => `<html><body>${body}</body></html>`;
const buildHTML = (body: string) => `<html><body>${body}</body></html>`;

// Creates a pad and returns the pad id. Calls the callback when finished.
const createPad = async (padID) => {
const res = await agent.get(`/api/${apiVersion}/createPad?apikey=${apiKey}&padID=${padID}`);
if (res.body.code !== 0) throw new Error('Unable to create new Pad');
const createPad = async (padID: string) => {
const res = await agent.get(`/api/${apiVersion}/createPad?padID=${padID}`)
.set("Authorization", await generateJWTToken())
return new Promise((resolve, reject) => {
if (res.body.code !== 0) {
reject(new Error('Unable to create new Pad'));
} else {
resolve(padID);
}
})
};

const setHTML = async (padID, html) => {
const res =
await agent.get(`/api/${apiVersion}/setHTML?apikey=${apiKey}&padID=${padID}&html=${html}`);
if (res.body.code !== 0) throw new Error('Unable to set pad HTML');
const setHTML = async (padID: string, html: string) => {
const newHtml = `/api/${apiVersion}/setHTML?padID=${padID}&html=${html}`
console.log("New HTML is",newHtml)
const res = await agent.get(newHtml)
.set("Authorization", await generateJWTToken())
console.log("Res is",res.body)
return new Promise((resolve, reject) => {
if (res.body.code !== 0) {
reject(new Error('Unable to set pad HTML'));
} else {
resolve(padID);
}
})
};

describe('Import and Export markdown', function () {
let padID;
let html;
let padID: string;
let html: Function;

before(async function () { agent = await common.init(); });

Expand All @@ -43,12 +59,16 @@ describe('Import and Export markdown', function () {
});

it('returns ok', async function () {
await agent.get(getMarkdownEndPointFor(padID))
await agent
.get(getMarkdownEndPointFor(padID))
.set("Authorization", await generateJWTToken())
.expect(200);
});

it('returns Markdown correctly', async function () {
const res = await agent.get(getMarkdownEndPointFor(padID));
const res = await agent
.get(getMarkdownEndPointFor(padID))
.set("Authorization", await generateJWTToken())
const markdown = res.text;
if (markdown.indexOf('*italic*') === -1) throw new Error('Unable to export italic');
if (markdown.indexOf('**bold**') === -1) throw new Error('Unable to export bold');
Expand Down

0 comments on commit bbda3c5

Please sign in to comment.