From 7572dcc5bbd8ec07ee452bfc044863e50324c909 Mon Sep 17 00:00:00 2001 From: Shailesh Patil <53746241+mineme0110@users.noreply.github.com> Date: Fri, 4 Aug 2023 16:16:35 +0100 Subject: [PATCH] fix: mediator test (#71) --- .../mediator/db/MessageItemRepoSpec.scala | 5 +-- .../mediator/db/UserAccountRepoSpec.scala | 41 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/mediator/src/test/scala/io/iohk/atala/mediator/db/MessageItemRepoSpec.scala b/mediator/src/test/scala/io/iohk/atala/mediator/db/MessageItemRepoSpec.scala index 2fe51f4e..f2f7e158 100644 --- a/mediator/src/test/scala/io/iohk/atala/mediator/db/MessageItemRepoSpec.scala +++ b/mediator/src/test/scala/io/iohk/atala/mediator/db/MessageItemRepoSpec.scala @@ -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) } }, @@ -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))) } } diff --git a/mediator/src/test/scala/io/iohk/atala/mediator/db/UserAccountRepoSpec.scala b/mediator/src/test/scala/io/iohk/atala/mediator/db/UserAccountRepoSpec.scala index f5693e54..a6cd5302 100644 --- a/mediator/src/test/scala/io/iohk/atala/mediator/db/UserAccountRepoSpec.scala +++ b/mediator/src/test/scala/io/iohk/atala/mediator/db/UserAccountRepoSpec.scala @@ -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") { @@ -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)) } }, @@ -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)) } }, @@ -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)) } }, @@ -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)) } }, @@ -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)) @@ -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))