From ae395497a5da9cbec9940a675d78d1b43bee91fa Mon Sep 17 00:00:00 2001 From: mikiher Date: Thu, 14 Mar 2024 19:37:51 +0200 Subject: [PATCH] Add tests for cleanSeriesSequence --- test/server/providers/Audible.test.js | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/server/providers/Audible.test.js diff --git a/test/server/providers/Audible.test.js b/test/server/providers/Audible.test.js new file mode 100644 index 00000000..67e85111 --- /dev/null +++ b/test/server/providers/Audible.test.js @@ -0,0 +1,48 @@ +const Audible = require('../../../server/providers/Audible') +const { expect } = require('chai') +const sinon = require('sinon') + +describe('Audible', () => { + let audible; + + beforeEach(() => { + audible = new Audible(); + }); + + describe('cleanSeriesSequence', () => { + it('should return an empty string if sequence is falsy', () => { + const result = audible.cleanSeriesSequence('Series Name', null) + expect(result).to.equal('') + }) + + it('should return the sequence as is if it does not contain a number', () => { + const result = audible.cleanSeriesSequence('Series Name', 'part a') + expect(result).to.equal('part a') + }) + + it('should return the sequence as is if contains just a number', () => { + const result = audible.cleanSeriesSequence('Series Name', '2') + expect(result).to.equal('2') + }) + + it('should return the sequence as is if contains just a number with decimals', () => { + const result = audible.cleanSeriesSequence('Series Name', '2.3') + expect(result).to.equal('2.3') + }) + + it('should extract and return the first number from the sequence', () => { + const result = audible.cleanSeriesSequence('Series Name', 'Book 1') + expect(result).to.equal('1') + }) + + it('should extract and return the number with decimals from the sequence', () => { + const result = audible.cleanSeriesSequence('Series Name', 'Book 1.5') + expect(result).to.equal('1.5') + }) + + it('should extract and return the number even if it has no leading zero', () => { + const result = audible.cleanSeriesSequence('Series Name', 'Book .5') + expect(result).to.equal('.5') + }) + }) +}) \ No newline at end of file