Skip to content

Commit

Permalink
(test): Fix TestExecutor logic (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbulaja98 authored Jan 9, 2023
1 parent e66626a commit d311861
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions modules/library/src/main/scala/zio/elasticsearch/TestExecutor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ private[elasticsearch] final case class TestExecutor private (data: TMap[IndexNa
}

private def fakeCreate(index: IndexName, document: Document): Task[DocumentId] =
(for {
documents <- getDocumentsFromIndex(index)
documentId = DocumentId(nextUUID.toString)
_ <- documents.put(documentId, document)
} yield documentId).commit
for {
uuid <- nextUUID
documents <- getDocumentsFromIndex(index).commit
documentId = DocumentId(uuid.toString)
_ <- documents.put(documentId, document).commit
} yield documentId

private def fakeCreateWithId(index: IndexName, documentId: DocumentId, document: Document): Task[CreationOutcome] =
(for {
Expand All @@ -66,15 +67,15 @@ private[elasticsearch] final case class TestExecutor private (data: TMap[IndexNa
private def fakeDeleteById(index: IndexName, documentId: DocumentId): Task[DeletionOutcome] =
(for {
documents <- getDocumentsFromIndex(index)
notExists <- documents.contains(documentId)
exists <- documents.contains(documentId)
_ <- documents.delete(documentId)
} yield if (notExists) NotFound else Deleted).commit
} yield if (exists) Deleted else NotFound).commit

private def fakeDeleteIndex(index: IndexName): Task[DeletionOutcome] =
(for {
notExists <- self.data.contains(index)
_ <- self.data.delete(index)
} yield if (notExists) NotFound else Deleted).commit
exists <- self.data.contains(index)
_ <- self.data.delete(index)
} yield if (exists) Deleted else NotFound).commit

private def fakeExists(index: IndexName, documentId: DocumentId): Task[Boolean] =
(for {
Expand Down

0 comments on commit d311861

Please sign in to comment.