Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yacchin1205 committed Nov 16, 2024
1 parent a9098c5 commit 2650b7d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
with:
packages: libreoffice libreoffice-pdfimport
version: 1.0
- name: Checkout repository
uses: actions/checkout@v3
with:
path: ep_weave
-
name: Install etherpad core
uses: actions/checkout@v3
Expand Down Expand Up @@ -80,6 +84,9 @@ jobs:
working-directory: ./plugin
run: |
pnpm link --global ep_etherpad-lite
- name: Install ep_weave
run: |
pnpm run plugins i ./ep_weave
-
name: Run the backend tests
working-directory: ./etherpad-lite
Expand Down
64 changes: 64 additions & 0 deletions static/tests/backend/specs/title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"use strict";

const common = require("ep_etherpad-lite/tests/backend/common");

let agent: any;
const apiVersion = 1;
const randomString =
require("ep_etherpad-lite/static/js/pad_utils").randomString;
import { generateJWTToken } from "ep_etherpad-lite/tests/backend/common";

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

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);
if (res.body.code !== 0) {
throw new Error("Unable to set pad HTML");
}
return padID;
};

const getHTMLEndPointFor = (padID: string) =>
`/api/${apiVersion}/getHTML?padID=${padID}`;

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

describe("access via title", function () {
let padID: string;
let html: () => string;

before(async function () {
agent = await common.init();
html = () => buildHTML("<p>Title of Sample Pad</p><p>Hello World</p>");
});

// create a new pad before each test run
beforeEach(async function () {
padID = randomString(5);
await createPad(padID);
await setHTML(padID, html());
});

it("returns ok", async function () {
await agent
.get(getHTMLEndPointFor(padID))
.set("Authorization", await generateJWTToken())
.expect("Content-Type", /json/)
.expect(200);
throw new Error("Not implemented");
});
});

0 comments on commit 2650b7d

Please sign in to comment.