Add alternate test

This commit is contained in:
Johan Holmerin 2020-07-15 21:29:08 +02:00
parent d56232e6b7
commit 0402f641ff
1 changed files with 27 additions and 0 deletions

27
test.ts
View File

@ -2,6 +2,7 @@ import { webServer, emailServer, WEB_PORT, EMAIL_PORT, EMAIL_DOMAIN } from ".";
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import axios from "axios"; import axios from "axios";
import qs from "qs"; import qs from "qs";
import { JSDOM } from "jsdom";
test("create feed", async () => { test("create feed", async () => {
const identifier = await createFeed(); const identifier = await createFeed();
@ -166,6 +167,28 @@ describe("receive email", () => {
}); });
}); });
describe("alternate", () => {
test("HTML content", async () => {
const identifier = await createFeed();
await emailClient.sendMail({
from: "publisher@example.com",
to: `${identifier}@${EMAIL_DOMAIN}`,
subject: "New Message",
html: "<p>HTML content</p>",
});
const feed = await getFeed(identifier);
const xml = new JSDOM(feed, { contentType: "text/xml" });
const document = xml.window.document;
const href = document
.querySelector("feed > entry link")!
.getAttribute("href") as string;
const alternate = await getAlternate(href);
expect(feed).toMatch("publisher@example.com");
expect(feed).toMatch("New Message");
expect(feed).toMatch("HTML content");
});
});
afterAll(() => { afterAll(() => {
webServer.close(); webServer.close();
emailServer.close(); emailServer.close();
@ -192,3 +215,7 @@ async function createFeed(): Promise<string> {
async function getFeed(identifier: string): Promise<string> { async function getFeed(identifier: string): Promise<string> {
return (await webClient.get(`/feeds/${identifier}.xml`)).data; return (await webClient.get(`/feeds/${identifier}.xml`)).data;
} }
async function getAlternate(url: string): Promise<string> {
return (await webClient.get(url)).data;
}