Skip to content

Commit

Permalink
WIP: implementing items fields. Msising some addressed in #17
Browse files Browse the repository at this point in the history
  • Loading branch information
olaven committed Jan 19, 2021
1 parent 78b3c0f commit b041bba
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packages/converter/src/converter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { models, server } from "@paperpod/common";
import { textToAudio, articleToRSSItem, getTextualData } from "./helpers/helpers";
import { textToAudio, toItemTag, getTextualData } from "./helpers/helpers";


/**
Expand Down Expand Up @@ -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
}
73 changes: 52 additions & 21 deletions packages/converter/src/helpers/rss.test.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,69 @@
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()) =>
serialize(
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("<title>")).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}</title>`)).toBeTruthy();
const value = getValue(article);

it(`Does have ${tag} with value of ${value}`, () => {

expect(rss).toContain(`<${tag}>${value}</${tag}>`)
});
}

}

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", () => {
Expand All @@ -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('<rss version="2.0">')).toBe(true);
expect(rss.includes("<channel>")).toBe(true);
expect(rss.includes("<link>")).toBe(true);
expect(rss).toContain('<rss version="2.0">');
expect(rss).toContain("<channel>");
expect(rss).toContain("<link>");
});
})
});

});
5 changes: 2 additions & 3 deletions packages/converter/src/helpers/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
Expand Down

0 comments on commit b041bba

Please sign in to comment.