Skip to content

Commit

Permalink
Mock ProductService more accurately
Browse files Browse the repository at this point in the history
  • Loading branch information
anotheroneofthese committed Aug 13, 2024
1 parent dd8c8a3 commit 4967a64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class ProductService(val db: ProductRepository, val synqProductService: SynqProd
hostName: HostName,
name: String
): Product? {
return db.findByHostNameAndHostId(hostName, name).timeout(Duration.ofSeconds(6)).awaitSingleOrNull()
// REVIEW - Can probably be improved to be more graceful
return db.findByHostNameAndHostId(hostName, name)
.timeout(Duration.ofSeconds(6))
.onErrorComplete()
.awaitSingleOrNull()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ class ProductServiceTest {
assertExceptionThrownWithMessage(tpp, "error code: '420' and error text: 'Blaze it LMAO'", ServerErrorException::class.java)
}

@Suppress("ReactiveStreamsUnusedPublisher")
@Test
fun `save when DB fails handles it gracefully`() {
every { db.findByHostNameAndHostId(tpp.hostName, tpp.hostId) } returns Mono.never()
every { synq.createProduct(any()) } returns ResponseEntity.created(URI.create("")).build()
every { db.save(any()) } throws Exception("DB is down")
every { db.save(any()) } returns Mono.error(Exception("DB is down"))

assertExceptionThrownWithMessage(tpp, "Failed to save product in the database", ServerErrorException::class.java)
}
Expand Down

0 comments on commit 4967a64

Please sign in to comment.