const chai = require('chai') const expect = chai.expect const parsePodcastDescriptionForChapters = require('../../../../server/utils/parsers/parsePodcastDescriptionForChapters') const sinon = require('sinon') const Logger = require('../../../../server/Logger') describe('parsePodcastDescriptionForChapters', () => { it("should early out if description doens't contain timestamps", () => { let loggerDebugStub = sinon.stub(Logger, 'debug') let description = '

Introduction text paragraph 1

Introduction text paragraph 2

' let chapters = parsePodcastDescriptionForChapters.parse(description, 1000) expect(chapters).to.be.empty expect(loggerDebugStub.calledWith('No timestamps found in description, bailing out early')).to.be.true sinon.restore() }) var testCasesTestingSuccess = [ { testName: 'Should handle descriptions using html paragraphs', description: '

Introduction text paragraph 1

Introduction text paragraph 2

00:48 Chatper 1

12:14 Chapter 2

20:56 Chapter 3

27:34 Chapter 4

32:00 Chapter 5

35:16 Chapter 6

41:32 Chapter 7

46:43 Chapter 8

', audioDuration: 3060, expectedChapters: [ { title: 'Chatper 1', id: 1, start: 48, end: 734 }, { title: 'Chapter 2', id: 2, start: 734, end: 1256 }, { title: 'Chapter 3', id: 3, start: 1256, end: 1654 }, { title: 'Chapter 4', id: 4, start: 1654, end: 1920 }, { title: 'Chapter 5', id: 5, start: 1920, end: 2116 }, { title: 'Chapter 6', id: 6, start: 2116, end: 2492 }, { title: 'Chapter 7', id: 7, start: 2492, end: 2803 }, { title: 'Chapter 8', id: 8, start: 2803, end: 3060 } ] }, { // Example: https://podcasts.apple.com/us/podcast/giant-bombcast-931-bleepbloop-remote/id274450056?i=1000754550540 testName: 'Should handle descriptions using html line breaks', description: '
Introduction text paragraph 1

Introduction text paragraph 2

0:00:00 Chapter 1
0:17:05 Chapter 2
0:33:58 Chapter 3
0:40:35 Chapter 4
Unrelated outro line
', audioDuration: 2700, expectedChapters: [ { title: 'Chapter 1', id: 1, start: 0, end: 1025 }, { title: 'Chapter 2', id: 2, start: 1025, end: 2038 }, { title: 'Chapter 3', id: 3, start: 2038, end: 2435 }, { title: 'Chapter 4', id: 4, start: 2435, end: 2700 } ] }, { // Example: https://podcasts.apple.com/us/podcast/xboxs-big-helix-reveal-witcher-4-path-tracing-crimson/id1596728253?i=1000755411491 testName: 'Should handle descriptions using unix new lines', description: `Introduction text paragraph 1 Introduction text paragraph 2 0:00:00 Chapter 1 0:17:05 Chapter 2 0:33:58 Chapter 3 0:40:35 Chapter 4 Unrelated outro line`, audioDuration: 2700, expectedChapters: [ { title: 'Chapter 1', id: 1, start: 0, end: 1025 }, { title: 'Chapter 2', id: 2, start: 1025, end: 2038 }, { title: 'Chapter 3', id: 3, start: 2038, end: 2435 }, { title: 'Chapter 4', id: 4, start: 2435, end: 2700 } ] }, { testName: 'Should handle descriptions with no timestamps', description: 'Lorem ipsum dolor sit amet consectetur adipiscing elit quisque faucibus ex sapien vitae pellentesque sem placerat in id cursus mi pretium tellus duis convallis tempus leo eu aenean sed diam urna tempor pulvinar vivamus fringilla lacus nec metus bibendum egestas.', audioDuration: 2700, expectedChapters: [] }, { testName: 'Should handle timestampes in parentheses', description: '

Introduction text paragraph 1

Introduction text paragraph 2

(00:48) Chatper 1

(12:14) Chapter 2

(20:56) Chapter 3

(27:34) Chapter 4

(32:00) Chapter 5

(35:16) Chapter 6

(41:32) Chapter 7

(46:43) Chapter 8

', audioDuration: 3060, expectedChapters: [ { title: 'Chatper 1', id: 1, start: 48, end: 734 }, { title: 'Chapter 2', id: 2, start: 734, end: 1256 }, { title: 'Chapter 3', id: 3, start: 1256, end: 1654 }, { title: 'Chapter 4', id: 4, start: 1654, end: 1920 }, { title: 'Chapter 5', id: 5, start: 1920, end: 2116 }, { title: 'Chapter 6', id: 6, start: 2116, end: 2492 }, { title: 'Chapter 7', id: 7, start: 2492, end: 2803 }, { title: 'Chapter 8', id: 8, start: 2803, end: 3060 } ] }, { // Example here: https://podcasts.apple.com/gb/podcast/daniel-priestley-plumbers-will-earn-more-than-lawyers/id1291423644?i=1000755513967 testName: 'Should handle html lists and chapters with html tags in the title', description: '

Introduction



Chapters