Skip to content

Commit

Permalink
test(route): ✅ update route tests for updateActions changes
Browse files Browse the repository at this point in the history
  • Loading branch information
djdembeck committed Aug 9, 2024
1 parent 1a491ae commit 0ea3d46
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
15 changes: 9 additions & 6 deletions tests/helpers/routes/AuthorShowHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
})
})
15 changes: 9 additions & 6 deletions tests/helpers/routes/BookShowHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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')
})
})
15 changes: 9 additions & 6 deletions tests/helpers/routes/ChapterShowHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
})
})

0 comments on commit 0ea3d46

Please sign in to comment.