From b041bbab65666eef5673eacc8bcb9743ae473940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20Sundf=C3=B8r?= Date: Tue, 19 Jan 2021 19:40:03 +0100 Subject: [PATCH] WIP: implementing items fields. Msising some addressed in #17 --- packages/common/package.json | 4 +- packages/converter/src/converter.ts | 4 +- packages/converter/src/helpers/rss.test.ts | 73 +++++++++++++++------- packages/converter/src/helpers/rss.ts | 5 +- 4 files changed, 58 insertions(+), 28 deletions(-) diff --git a/packages/common/package.json b/packages/common/package.json index 1321f861..e3ba97ad 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -2,8 +2,8 @@ "name": "@paperpod/common", "license": "UNLICENSED", "version": "0.0.1", - "main": "./dist/index.js", - "types": "./dist/index", + "main": "dist/src/index.js", + "types": "index", "scripts": { "test": "jest", "build": "tsc" diff --git a/packages/converter/src/converter.ts b/packages/converter/src/converter.ts index 61c60627..df0a1176 100644 --- a/packages/converter/src/converter.ts +++ b/packages/converter/src/converter.ts @@ -1,5 +1,5 @@ import { models, server } from "@paperpod/common"; -import { textToAudio, articleToRSSItem, getTextualData } from "./helpers/helpers"; +import { textToAudio, toItemTag, getTextualData } from "./helpers/helpers"; /** @@ -43,7 +43,7 @@ export const convertToText = */ export const convertToRSS = (articles: models.Article[]) => { - const entires = articles.map(articleToRSSItem); + const entires = articles.map(toItemTag); //FIXME: implement } \ No newline at end of file diff --git a/packages/converter/src/helpers/rss.test.ts b/packages/converter/src/helpers/rss.test.ts index 5fb96f02..0bd2ce25 100644 --- a/packages/converter/src/helpers/rss.test.ts +++ b/packages/converter/src/helpers/rss.test.ts @@ -1,9 +1,7 @@ -import { test } from "@paperpod/common"; -import { hasUncaughtExceptionCaptureCallback } from "process"; +import { test, server, models } from "@paperpod/common"; import { serialize } from "serialize-xml"; import { convertToRSSFeed, toItemTag } from "./rss"; - describe("Conversion from articles to RSS", () => { const serializeItem = (article = test.mocks.article()) => @@ -11,28 +9,61 @@ describe("Conversion from articles to RSS", () => { toItemTag(article) ) - describe("Converting article to single item", () => { - it("Does not throw", () => { + const hasTags = (tags: string[]) => { - const article = test.mocks.article(); - expect(() => { toItemTag(article) }).not.toThrow(); - }); + for (const tag of tags) { - it("Does contain title", () => { + const rss = serializeItem() + it(`Has a tag called ${tag}`, () => { - const item = serializeItem(); - expect(item.includes("")).toBeTruthy(); - }); + expect(rss).toContain(`<${tag}>`) + expect(rss).toContain(`</${tag}>`) + }) + } + } + + const hasTagWithValue = (pairs: [string, (article: models.Article) => string][]) => { - it("Does contain the same title as the article", () => { + for (const [tag, getValue] of pairs) { 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(); + const value = getValue(article); + + it(`Does have ${tag} with value of ${value}`, () => { + + expect(rss).toContain(`<${tag}>${value}`) + }); + } + + } + + describe("Converting article to single item", () => { + + it("Does not throw", () => { + + const article = test.mocks.article(); + expect(() => { toItemTag(article) }).not.toThrow(); }); + + hasTags([ + "title", + "link", + "description", + "guid", + "pubDate", + "author", + ]); + + hasTagWithValue([ + ["title", article => article.title], + ["link", article => `https://paperpod.fm/api/files/${article._id}`], + //["description", article => article.description], //FIXME: when #17 is fixed + ["guid", article => article._id], + //["pubDate", article => article.pubDate], //FIXME: when #17 if fixed + //["author", article => article.author], //FIXME: when #17 is fixed + ]); }); describe("Converting list of articles to feed", () => { @@ -41,10 +72,10 @@ describe("Conversion from articles to RSS", () => { 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); + expect(rss).toContain(''); + expect(rss).toContain(""); + expect(rss).toContain(""); }); - }) + }); + }); \ No newline at end of file diff --git a/packages/converter/src/helpers/rss.ts b/packages/converter/src/helpers/rss.ts index ace94f86..5e3d6aa0 100644 --- a/packages/converter/src/helpers/rss.ts +++ b/packages/converter/src/helpers/rss.ts @@ -53,10 +53,9 @@ export const toItemTag = (article: models.Article) => "item", [ tag("title", article.title), - tag("link", "FIXME: some value herer"), + tag("link", `https://paperpod.fm/api/files/${article._id}`), tag("description", "FIXME: some value herer"), - tag("source ", "FIXME: some value herer"), - tag("guid", "FIXME: some value herer"), + tag("guid", `${article._id}`), tag("pubDate", "FIXME: some value herer"), tag("author", "FIXME: some value herer"), ]