diff --git a/tests/helpers/routes/AuthorShowHelper.test.ts b/tests/helpers/routes/AuthorShowHelper.test.ts index 764d133f..0b6c30c0 100644 --- a/tests/helpers/routes/AuthorShowHelper.test.ts +++ b/tests/helpers/routes/AuthorShowHelper.test.ts @@ -85,12 +85,6 @@ describe('AuthorShowHelper should', () => { await expect(helper.updateActions()).resolves.toStrictEqual(parsedAuthor) }) - test('run updateActions and return original author if there was an error', async () => { - helper.originalData = authorWithoutProjection - jest.spyOn(helper.paprHelper, 'createOrUpdate').mockRejectedValue(new Error('error')) - await expect(helper.updateActions()).resolves.toStrictEqual(authorWithoutProjection) - }) - test('run handler for a new author', async () => { jest.spyOn(helper.paprHelper, 'findOne').mockResolvedValue({ data: null, modified: false }) await expect(helper.handler()).resolves.toStrictEqual(parsedAuthor) @@ -142,6 +136,7 @@ describe('AuthorShowHelper should throw error when', () => { `Data type for ${asin} is not ApiAuthorProfile` ) }) + test('getDataWithProjection sorted author is not a author type', async () => { jest .spyOn(helper.sharedHelper, 'sortObjectByKeys') @@ -150,6 +145,7 @@ describe('AuthorShowHelper should throw error when', () => { `Data type for ${asin} is not ApiAuthorProfile` ) }) + test('createOrUpdateAuthor is not a author type', async () => { jest .spyOn(helper.paprHelper, 'createOrUpdate') @@ -158,10 +154,17 @@ describe('AuthorShowHelper should throw error when', () => { `Data type for ${asin} is not ApiAuthorProfile` ) }) + test('updateActions has no originalAuthor', async () => { helper.originalData = null await expect(helper.updateActions()).rejects.toThrow( `Missing original author data for ASIN: ${asin}` ) }) + + test('updateActions fails to update', async () => { + helper.originalData = authorWithoutProjection + jest.spyOn(helper.paprHelper, 'createOrUpdate').mockRejectedValue(new Error('error')) + await expect(helper.updateActions()).rejects.toThrow('error') + }) }) diff --git a/tests/helpers/routes/BookShowHelper.test.ts b/tests/helpers/routes/BookShowHelper.test.ts index c8e6920d..c13e7415 100644 --- a/tests/helpers/routes/BookShowHelper.test.ts +++ b/tests/helpers/routes/BookShowHelper.test.ts @@ -86,12 +86,6 @@ describe('BookShowHelper should', () => { await expect(helper.updateActions()).resolves.toStrictEqual(parsedBook) }) - test('run updateActions and return original book if there was an error', async () => { - jest.spyOn(helper.paprHelper, 'createOrUpdate').mockRejectedValue(new Error('error')) - helper.originalData = bookWithoutProjection - await expect(helper.updateActions()).resolves.toStrictEqual(bookWithoutProjection) - }) - test('run handler for a new book', async () => { jest.spyOn(helper.paprHelper, 'findOne').mockResolvedValue({ data: null, modified: false }) await expect(helper.handler()).resolves.toStrictEqual(parsedBook) @@ -146,12 +140,14 @@ describe('BookShowHelper should throw error when', () => { `Data type for ${asin} is not ApiBook` ) }) + test('getDataWithProjection sorted book is not a book type', async () => { jest.spyOn(helper.sharedHelper, 'sortObjectByKeys').mockReturnValue(null as unknown as ApiBook) await expect(helper.getDataWithProjection()).rejects.toThrow( `Data type for ${asin} is not ApiBook` ) }) + test('createOrUpdateData is not a book type', async () => { jest .spyOn(helper.paprHelper, 'createOrUpdate') @@ -160,10 +156,17 @@ describe('BookShowHelper should throw error when', () => { `Data type for ${asin} is not ApiBook` ) }) + test('update has no originalData', async () => { helper.originalData = null await expect(helper.updateActions()).rejects.toThrow( `Missing original book data for ASIN: ${asin}` ) }) + + test('updateActions fails to update', async () => { + jest.spyOn(helper.paprHelper, 'createOrUpdate').mockRejectedValue(new Error('error')) + helper.originalData = bookWithoutProjection + await expect(helper.updateActions()).rejects.toThrow('error') + }) }) diff --git a/tests/helpers/routes/ChapterShowHelper.test.ts b/tests/helpers/routes/ChapterShowHelper.test.ts index d482d735..1f33a5d5 100644 --- a/tests/helpers/routes/ChapterShowHelper.test.ts +++ b/tests/helpers/routes/ChapterShowHelper.test.ts @@ -83,12 +83,6 @@ describe('ChapterShowHelper should', () => { await expect(helper.updateActions()).resolves.toStrictEqual(parsedChapters) }) - test('run all update actions and return undefined if there was an error', async () => { - jest.spyOn(helper.paprHelper, 'createOrUpdate').mockRejectedValue(new Error('Error')) - helper.originalData = chaptersWithoutProjection - await expect(helper.updateActions()).resolves.toBeUndefined() - }) - test('run all update actions and return undefined if no chapters', async () => { jest.spyOn(ChapterHelper.prototype, 'process').mockResolvedValue(undefined) helper.originalData = chaptersWithoutProjection @@ -151,6 +145,7 @@ describe('ChapterShowHelper should throw error when', () => { `Data type for ${asin} is not ApiChapter` ) }) + test('getChaptersWithProjection sorted chapters is not a chapter type', async () => { jest .spyOn(helper.sharedHelper, 'sortObjectByKeys') @@ -159,6 +154,7 @@ describe('ChapterShowHelper should throw error when', () => { `Data type for ${asin} is not ApiChapter` ) }) + test('createOrUpdateData is not a chapter type', async () => { jest .spyOn(helper.paprHelper, 'createOrUpdate') @@ -167,10 +163,17 @@ describe('ChapterShowHelper should throw error when', () => { `Data type for ${asin} is not ApiChapter` ) }) + test('update has no originalData', async () => { helper.originalData = null await expect(helper.updateActions()).rejects.toThrow( `Missing original chapter data for ASIN: ${asin}` ) }) + + test('updateActions fails to update', async () => { + jest.spyOn(helper.paprHelper, 'createOrUpdate').mockRejectedValue(new Error('Error')) + helper.originalData = chaptersWithoutProjection + await expect(helper.updateActions()).rejects.toThrow('Error') + }) })