Skip to content

Commit

Permalink
fix: season length
Browse files Browse the repository at this point in the history
  • Loading branch information
markusahlstrand committed Jun 3, 2024
1 parent a42336a commit e66e248
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/sesamy-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ export function parseFeedToSesamy(feed: RssFeed) {
const isComplete = /yes/i.test(channel['itunes:complete'] ?? '');
const isExplicit = /yes/i.test(channel['itunes:explicit'] ?? '');
// Pick the highest season from episodes
const totalSeasons =
Math.max(
...episodes.map(episode => {
return episode.season ?? 0;
}),
) || 0;
const totalSeasons = Math.max(
...episodes.map(episode => {
return episode.season ?? 0;
}),
0,
);
const rawProducts = channel['sesamy:product'] ?? [];

const products = rawProducts.map(item => {
Expand Down
45 changes: 45 additions & 0 deletions test/fixtures/empty-feed.rss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/template/podspace.xsl" type="text/xsl" media="screen"?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0">
<channel>
<atom:link href="https://feed.pod.space/aipodden" rel="self" type="application/rss+xml"/>
<atom:link href="https://pubsubhubbub.appspot.com" rel="hub"/>
<title>AI-podden</title>
<link>https://pod.space/aipodden</link>
<description>This podcast explores the latest in AI with diverse perspectives, making it an essential listen for anyone interested in understanding the impact of artificial intelligence on society.</description>
<content:encoded>
<![CDATA[<div>This podcast explores the latest in AI with diverse perspectives, making it an essential listen for anyone interested in understanding the impact of artificial intelligence on society.</div>]]>
</content:encoded>
<language>en</language>
<copyright>Ather Gattami</copyright>
<generator>www.pod.space feed generator</generator>
<pubDate>Wed, 15 May 2024 14:11:04 +0000</pubDate>
<lastBuildDate>Wed, 15 May 2024 14:11:04 +0000</lastBuildDate>
<itunes:author>Ather Gattami</itunes:author>
<itunes:summary>
<![CDATA[<div>This podcast explores the latest in AI with diverse perspectives, making it an essential listen for anyone interested in understanding the impact of artificial intelligence on society.</div>]]>
</itunes:summary>
<itunes:subtitle>This podcast explores the latest in AI with diverse perspectives, making it an essential listen for anyone interested in understanding the impact o...</itunes:subtitle>
<itunes:explicit>clean</itunes:explicit>
<itunes:image href="https://assets.pod.space/system/shows/images/021/f7c/df-/large/ai_podden_4_09_2019.png"/>
<itunes:owner>
<itunes:name>Ather Gattami</itunes:name>
<itunes:email>gattami@bitynamics.com</itunes:email>
</itunes:owner>
<itunes:type>episodic</itunes:type>
<image>
<url>https://assets.pod.space/system/shows/images/021/f7c/df-/large/ai_podden_4_09_2019.png</url>
<title>AI-podden</title>
<link>https://pod.space/aipodden</link>
</image>
<itunes:category text="News">
<itunes:category text="Tech News"/>
</itunes:category>
<itunes:category text="Business">
<itunes:category text="Investing"/>
</itunes:category>
<itunes:category text="Technology"/>
<itunes:category text="Science"/>
</channel>
</rss>
13 changes: 13 additions & 0 deletions test/sesamy-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const spar = fs.readFileSync('./test/fixtures/spar.rss');
const acast = fs.readFileSync('./test/fixtures/acast.rss');
const kjente = fs.readFileSync('./test/fixtures/kjente.rss');
const fof = fs.readFileSync('./test/fixtures/fof.rss');
const emptyFeed = fs.readFileSync('./test/fixtures/empty-feed.rss');

describe('Sesamy parser service tests', () => {
it('Check podspace feed', async () => {
Expand Down Expand Up @@ -68,6 +69,18 @@ describe('Sesamy parser service tests', () => {
});
});

it('should parse an empty feed', async () => {
const feedJson = await parseFeedToJson(emptyFeed.toString());
const sesamyFeed = parseFeedToSesamy(feedJson);

expect(sesamyFeed.title).toBe('AI-podden');

expect(sesamyFeed.products.length).toBe(0);
expect(sesamyFeed.episodes.length).toBe(0);
expect(sesamyFeed.totalEpisodes).toBe(0);
expect(sesamyFeed.totalSeasons).toBe(0);
});

it('Check Kjente Proxy feed', async () => {
const feedJson = await parseFeedToJson(kjente.toString());
const sesamyFeed = parseFeedToSesamy(feedJson);
Expand Down

0 comments on commit e66e248

Please sign in to comment.