diff --git a/packages/common/src/test/mocks.ts b/packages/common/src/test/mocks.ts index 47c1c888..c1331c0c 100644 --- a/packages/common/src/test/mocks.ts +++ b/packages/common/src/test/mocks.ts @@ -14,6 +14,7 @@ export const credentials = (): models.UserCredentials => ({ }); export const article = (): models.Article => ({ + title: faker.hacker.phrase(), original_url: faker.internet.url(), text: faker.lorem.paragraphs(15), owner_id: faker.random.uuid(), diff --git a/packages/converter/src/helpers/rss.test.ts b/packages/converter/src/helpers/rss.test.ts index b08c9dd8..5fb96f02 100644 --- a/packages/converter/src/helpers/rss.test.ts +++ b/packages/converter/src/helpers/rss.test.ts @@ -1,16 +1,50 @@ import { test } from "@paperpod/common"; -import { convertToRSS } from "../converter"; -import { articleToRSSItem } from "./rss"; +import { hasUncaughtExceptionCaptureCallback } from "process"; +import { serialize } from "serialize-xml"; +import { convertToRSSFeed, toItemTag } from "./rss"; describe("Conversion from articles to RSS", () => { - describe("Converting a single article", () => { + const serializeItem = (article = test.mocks.article()) => + serialize( + toItemTag(article) + ) + + describe("Converting article to single item", () => { it("Does not throw", () => { const article = test.mocks.article(); - expect(() => { articleToRSSItem(article) }).not.toThrow(); + expect(() => { toItemTag(article) }).not.toThrow(); + }); + + it("Does contain title", () => { + + const item = serializeItem(); + expect(item.includes("")).toBeTruthy(); + }); + + it("Does contain the same title as the article", () => { + + const article = test.mocks.article(); + expect(article.title).toBeDefined(); + const rss = serializeItem(article); + console.log("HERE IS RSS", rss); + expect(rss.includes(`<title>${article.title}`)).toBeTruthy(); + }); + }); + + describe("Converting list of articles to feed", () => { + + + it("Does return something looking like RSS", () => { + + const rss = convertToRSSFeed([]); + console.log(`RSS HERE ${rss}`); + expect(rss.includes('')).toBe(true); + expect(rss.includes("")).toBe(true); + expect(rss.includes("")).toBe(true); }); }) }); \ No newline at end of file diff --git a/packages/converter/src/helpers/rss.ts b/packages/converter/src/helpers/rss.ts index 9b0cdcbf..ace94f86 100644 --- a/packages/converter/src/helpers/rss.ts +++ b/packages/converter/src/helpers/rss.ts @@ -24,22 +24,40 @@ import { serialize, tag, declaration } from "serialize-xml"; import { models } from "@paperpod/common"; -export const articleToRSSItem = (article: models.Article) => { - const xml = serialize( +export const convertToRSSFeed = (articles: models.Article[]) => + serialize( tag("rss", [ tag("channel", [ tag("title", "Paperpod Feed"), tag("link", "LINK TO FEED"), tag("description", "This is your Paperpod Feed. Thanks for using Paperpod! Send articles, and they will appear here"), tag("ttl", "60"), //60 minutes - tag("image", [ - tag("url", "https://paperpod.fm/logo.svg"), //TODO: image that's friendly for podcast players - tag("link", "LINK TO FEED"), - tag("title", "Paperpod Feed") - ])] - //TODO: items (should be done here, what's implemented above should be done somewhere with access to all articles) + toImageTag(), + ...articles.map(toItemTag) + ], )], [["version", "2.0"]] - )) -} \ No newline at end of file + ), + ) + +export const toImageTag = () => + tag("image", [ + tag("url", "https://paperpod.fm/logo.svg"), //TODO: image that's friendly for podcast players + tag("link", "LINK TO FEED"), + tag("title", "Paperpod Feed") + ]); + +export const toItemTag = (article: models.Article) => + tag( + "item", + [ + tag("title", article.title), + tag("link", "FIXME: some value herer"), + tag("description", "FIXME: some value herer"), + tag("source ", "FIXME: some value herer"), + tag("guid", "FIXME: some value herer"), + tag("pubDate", "FIXME: some value herer"), + tag("author", "FIXME: some value herer"), + ] + ) \ No newline at end of file