FIX: Vipps agreement and DB agreement out of sync #42
|
|
@ -1,4 +1,4 @@
|
||||||
import { assertEquals, assertExists } from "$std/assert/mod.ts";
|
import { assertEquals, assertExists, assertLess } from "$std/assert/mod.ts";
|
||||||
import { testUtils } from "./test-utils.ts";
|
import { testUtils } from "./test-utils.ts";
|
||||||
import { rss } from "./rss.ts";
|
import { rss } from "./rss.ts";
|
||||||
import { forTestingOnly } from "./rss.ts";
|
import { forTestingOnly } from "./rss.ts";
|
||||||
|
|
@ -30,6 +30,20 @@ Deno.test("generated rss contains promo with link to donations page", () => {
|
||||||
const series = testUtils.generateSeries();
|
const series = testUtils.generateSeries();
|
||||||
const feed = rss.assembleFeed(series);
|
const feed = rss.assembleFeed(series);
|
||||||
|
|
||||||
console.log(feed);
|
|
||||||
feed.includes("Vurder å støtte utviklingen via Vipps");
|
feed.includes("Vurder å støtte utviklingen via Vipps");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("generated rss contains promo with link to donations page", () => {
|
||||||
|
const series = testUtils.generateSeries();
|
||||||
|
const feed = rss.assembleFeed(series);
|
||||||
|
|
||||||
|
const indexOfFirstPromotion = feed.indexOf(
|
||||||
|
"NRSS er avhengig av din Vipps-støtte"
|
||||||
|
);
|
||||||
|
const indexOfSecondPromotion = feed.indexOf("Vurder å støtte utviklingen");
|
||||||
|
assertLess(
|
||||||
|
indexOfFirstPromotion,
|
||||||
|
indexOfSecondPromotion,
|
||||||
|
"First promotion should come before the second"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
|
||||||
28
lib/rss.ts
28
lib/rss.ts
|
|
@ -27,16 +27,11 @@ function assembleFeed(series: Series): string {
|
||||||
tag("itunes:name", "NRK"),
|
tag("itunes:name", "NRK"),
|
||||||
tag("itunes:email", "nrkpodcast@nrk.no"),
|
tag("itunes:email", "nrkpodcast@nrk.no"),
|
||||||
]),
|
]),
|
||||||
tag(
|
tag("description", series.subtitle || ""),
|
||||||
"description",
|
|
||||||
series.subtitle || "",
|
|
||||||
),
|
|
||||||
tag("ttl", "60"), //60 minutes
|
tag("ttl", "60"), //60 minutes
|
||||||
...(series.imageUrl
|
...(series.imageUrl
|
||||||
? [
|
? [
|
||||||
tag("itunes:image", "", [
|
tag("itunes:image", "", [["href", series.imageUrl]]),
|
||||||
["href", series.imageUrl],
|
|
||||||
]),
|
|
||||||
tag("image", [
|
tag("image", [
|
||||||
tag("url", series.imageUrl),
|
tag("url", series.imageUrl),
|
||||||
tag("title", series.title),
|
tag("title", series.title),
|
||||||
|
|
@ -44,7 +39,9 @@ function assembleFeed(series: Series): string {
|
||||||
]),
|
]),
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
...series.episodes.map((episode) => assembleEpisode(episode, series.id)),
|
...series.episodes.map((episode) =>
|
||||||
|
assembleEpisode(episode, series.id)
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
|
@ -52,16 +49,16 @@ function assembleFeed(series: Series): string {
|
||||||
["xmlns:itunes", "http://www.itunes.com/dtds/podcast-1.0.dtd"],
|
["xmlns:itunes", "http://www.itunes.com/dtds/podcast-1.0.dtd"],
|
||||||
["xmlns:content", "http://purl.org/rss/1.0/modules/content/"],
|
["xmlns:content", "http://purl.org/rss/1.0/modules/content/"],
|
||||||
["xmlns:podcast", "https://podcastindex.org/namespace/1.0"],
|
["xmlns:podcast", "https://podcastindex.org/namespace/1.0"],
|
||||||
],
|
]
|
||||||
),
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function descriptionWithDonationPromotion(description: string): string {
|
function descriptionWithDonationPromotion(description: string): string {
|
||||||
const promotion =
|
const firstPromotion = `⬇️NRSS er avhengig av din Vipps-støtte⬇️`;
|
||||||
`Takk for at du bruker NRSS 🙏🌟 Vurder å støtte utviklingen via Vipps med omtrent det samme som prisen på en kaffekopp. Se mer på https://nrss.deno.dev/`;
|
const secondPromotion = `Takk for at du bruker NRSS 🙏🌟 Vurder å støtte utviklingen via Vipps med omtrent det samme som prisen på en kaffekopp. Se mer på https://nrss.deno.dev/`;
|
||||||
|
|
||||||
return `${description}\n\n${promotion}`;
|
return `${firstPromotion}\n\n${description}\n\n${secondPromotion}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function assembleEpisode(episode: Episode, seriesId: Series["id"]): Tag {
|
function assembleEpisode(episode: Episode, seriesId: Series["id"]): Tag {
|
||||||
|
|
@ -76,10 +73,7 @@ function assembleEpisode(episode: Episode, seriesId: Series["id"]): Tag {
|
||||||
tag("pubDate", new Date(episode.date).toUTCString()),
|
tag("pubDate", new Date(episode.date).toUTCString()),
|
||||||
tag("itunes:duration", episode.durationInSeconds.toString()),
|
tag("itunes:duration", episode.durationInSeconds.toString()),
|
||||||
tag("podcast:chapters", "", [
|
tag("podcast:chapters", "", [
|
||||||
[
|
["url", `${getHostUrl()}/api/feeds/${seriesId}/${episode.id}/chapters`],
|
||||||
"url",
|
|
||||||
`${getHostUrl()}/api/feeds/${seriesId}/${episode.id}/chapters`,
|
|
||||||
],
|
|
||||||
["type", "application/json+chapters"],
|
["type", "application/json+chapters"],
|
||||||
]),
|
]),
|
||||||
tag("enclosure", "", [
|
tag("enclosure", "", [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue