Skip to content

Commit

Permalink
fix: mediator test (#71)
Browse files Browse the repository at this point in the history
Signed-off-by: Shailesh Patil <[email protected]>
  • Loading branch information
mineme0110 committed May 1, 2024
1 parent d3f36ae commit 03d1d61
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ object MessageItemRepoSpec extends ZIOSpecDefault with AccountStubSetup {
msg <- ZIO.fromEither(encryptedMessageAlice)
result <- messageItem.insert(MessageItem(msg))
} yield {
println(result)
assertTrue(result.writeErrors == Nil)
assertTrue(result.writeErrors == Nil) &&
assertTrue(result.n == 1)
}
},
Expand All @@ -41,7 +40,7 @@ object MessageItemRepoSpec extends ZIOSpecDefault with AccountStubSetup {
msg2Added <- messageItem.insert(MessageItem(msg2))
result <- messageItem.findByIds(Seq(msg.sha1, msg2.sha1))
} yield {
assertTrue(result.contains(MessageItem(msg)))
assertTrue(result.contains(MessageItem(msg))) &&
assertTrue(result.contains(MessageItem(msg2)))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ object UserAccountRepoSpec extends ZIOSpecDefault with AccountStubSetup {
userAccount <- ZIO.service[UserAccountRepo]
result <- userAccount.getDidAccount(DIDSubject(alice))
} yield {
assertTrue(result.isDefined)
assertTrue(result.exists(_.did == DIDSubject(alice)))
assertTrue(result.isDefined) && assertTrue(result.exists(_.did == DIDSubject(alice)))
}
},
test("Get Did Account return for unknown did") {
Expand All @@ -66,10 +65,10 @@ object UserAccountRepoSpec extends ZIOSpecDefault with AccountStubSetup {
result <- userAccount.addAlias(DIDSubject(alice), DIDSubject(bob))
didAccount <- userAccount.getDidAccount(DIDSubject(alice))
} yield {
assertTrue(result.isRight)
assertTrue(result == Right((1)))
assertTrue(didAccount.isDefined)
val alias: Seq[String] = didAccount.map(_.alias.map(_.did)).getOrElse(Seq.empty)
assertTrue(result.isRight) &&
assertTrue(result == Right((1))) &&
assertTrue(didAccount.isDefined) &&
assertTrue(alias == Seq(alice, bob))
}
},
Expand All @@ -87,10 +86,10 @@ object UserAccountRepoSpec extends ZIOSpecDefault with AccountStubSetup {
result <- userAccount.addAlias(DIDSubject(alice), DIDSubject(alice))
didAccount <- userAccount.getDidAccount(DIDSubject(alice))
} yield {
assertTrue(result.isRight)
assertTrue(result == Right(0))
assertTrue(didAccount.isDefined)
val alias: Seq[String] = didAccount.map(_.alias.map(_.did)).getOrElse(Seq.empty)
assertTrue(result.isRight) &&
assertTrue(result == Right(0)) &&
assertTrue(didAccount.isDefined) &&
assertTrue(alias == Seq(alice, bob))
}
},
Expand All @@ -100,11 +99,10 @@ object UserAccountRepoSpec extends ZIOSpecDefault with AccountStubSetup {
result <- userAccount.removeAlias(DIDSubject(alice), DIDSubject(bob))
didAccount <- userAccount.getDidAccount(DIDSubject(alice))
} yield {
assertTrue(result.isRight)
assertTrue(result == Right(1))
assertTrue(didAccount.isDefined)
val alias: Seq[String] = didAccount.map(_.alias.map(_.did)).getOrElse(Seq.empty)

assertTrue(result.isRight) &&
assertTrue(result == Right(1)) &&
assertTrue(didAccount.isDefined) &&
assertTrue(alias == Seq(alice))
}
},
Expand All @@ -114,10 +112,10 @@ object UserAccountRepoSpec extends ZIOSpecDefault with AccountStubSetup {
result <- userAccount.removeAlias(DIDSubject(alice), DIDSubject(bob))
didAccount <- userAccount.getDidAccount(DIDSubject(alice))
} yield {
assertTrue(result.isRight)
assertTrue(result == Right(0))
assertTrue(didAccount.isDefined)
val alias: Seq[String] = didAccount.map(_.alias.map(_.did)).getOrElse(Seq.empty)
assertTrue(result.isRight) &&
assertTrue(result == Right(0)) &&
assertTrue(didAccount.isDefined) &&
assertTrue(alias == Seq(alice))
}
},
Expand All @@ -131,12 +129,13 @@ object UserAccountRepoSpec extends ZIOSpecDefault with AccountStubSetup {
addedToInbox <- userAccount.addToInboxes(Set(DIDSubject(bob)), msg)
didAccount <- userAccount.getDidAccount(DIDSubject(alice))
} yield {
assertTrue(result.isRight)
assertTrue(result == Right(1))
assertTrue(msgAdded.writeErrors == Nil)
assertTrue(msgAdded.n == 1)
assertTrue(addedToInbox == 1)
val messageMetaData: Seq[MessageMetaData] = didAccount.map(_.messagesRef).getOrElse(Seq.empty)

assertTrue(result.isRight) &&
assertTrue(result == Right(1)) &&
assertTrue(msgAdded.writeErrors == Nil) &&
assertTrue(msgAdded.n == 1) &&
assertTrue(addedToInbox == 1) &&
assert(messageMetaData)(
forall(
hasField("hash", (m: MessageMetaData) => m.hash, equalTo(msg.sha1))
Expand All @@ -152,8 +151,8 @@ object UserAccountRepoSpec extends ZIOSpecDefault with AccountStubSetup {
markedDelivered <- userAccount.markAsDelivered(DIDSubject(alice), Seq(msg.sha1))
didAccount <- userAccount.getDidAccount(DIDSubject(alice))
} yield {
assertTrue(markedDelivered == 1)
val messageMetaData: Seq[MessageMetaData] = didAccount.map(_.messagesRef).getOrElse(Seq.empty)
assertTrue(markedDelivered == 1) &&
assert(messageMetaData)(
forall(
hasField("state", (m: MessageMetaData) => m.state, equalTo(true))
Expand Down

0 comments on commit 03d1d61

Please sign in to comment.