• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 8795121910

23 Apr 2024 04:45AM UTC coverage: 31.908% (+0.4%) from 31.528%
8795121910

Pull #975

CryptoKnightIOG
feat: VC Verification test coverage (#972)

Signed-off-by: Bassam Riman <bassam.riman@iohk.io>
Pull Request #975: feat: Vc Verification Api

104 of 281 new or added lines in 15 files covered. (37.01%)

379 existing lines in 106 files now uncovered.

4619 of 14476 relevant lines covered (31.91%)

0.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.38
/connect/lib/core/src/main/scala/io/iohk/atala/connect/core/service/ConnectionServiceNotifier.scala
1
package io.iohk.atala.connect.core.service
2

3
import io.iohk.atala.connect.core.model.ConnectionRecord
4
import io.iohk.atala.connect.core.model.error.ConnectionServiceError
5
import io.iohk.atala.connect.core.model.error.ConnectionServiceError.*
6
import io.iohk.atala.event.notification.{Event, EventNotificationService}
7
import io.iohk.atala.mercury.model.DidId
8
import io.iohk.atala.mercury.protocol.connection.{ConnectionRequest, ConnectionResponse}
9
import io.iohk.atala.shared.models.WalletAccessContext
10
import zio.{UIO, URIO, URLayer, ZIO, ZLayer}
11

12
import java.time.Duration
13
import java.util.UUID
14

15
class ConnectionServiceNotifier(
16
    svc: ConnectionService,
17
    eventNotificationService: EventNotificationService
18
) extends ConnectionService {
19

20
  private val connectionUpdatedEvent = "ConnectionUpdated"
21

1✔
22
  override def createConnectionInvitation(
23
      label: Option[String],
24
      goalCode: Option[String],
25
      goal: Option[String],
26
      pairwiseDID: DidId
27
  ): ZIO[WalletAccessContext, UserInputValidationError, ConnectionRecord] =
1✔
28
    notifyOnSuccess(svc.createConnectionInvitation(label, goalCode, goal, pairwiseDID))
29

1✔
30
  override def receiveConnectionInvitation(
31
      invitation: String
32
  ): ZIO[WalletAccessContext, InvitationParsingError | InvitationAlreadyReceived, ConnectionRecord] =
1✔
33
    notifyOnSuccess(svc.receiveConnectionInvitation(invitation))
34

1✔
35
  override def acceptConnectionInvitation(
36
      recordId: UUID,
37
      pairwiseDid: DidId
38
  ): ZIO[WalletAccessContext, RecordIdNotFound | InvalidStateForOperation, ConnectionRecord] =
1✔
39
    notifyOnSuccess(svc.acceptConnectionInvitation(recordId, pairwiseDid))
40

1✔
41
  override def markConnectionRequestSent(
42
      recordId: UUID
43
  ): ZIO[WalletAccessContext, RecordIdNotFound | InvalidStateForOperation, ConnectionRecord] =
1✔
44
    notifyOnSuccess(svc.markConnectionRequestSent(recordId))
45

1✔
46
  override def receiveConnectionRequest(
47
      request: ConnectionRequest,
48
      expirationTime: Option[Duration]
49
  ): ZIO[WalletAccessContext, ThreadIdNotFound | InvalidStateForOperation | InvitationExpired, ConnectionRecord] =
1✔
50
    notifyOnSuccess(svc.receiveConnectionRequest(request, expirationTime))
51

1✔
52
  override def acceptConnectionRequest(
53
      recordId: UUID
54
  ): ZIO[WalletAccessContext, RecordIdNotFound | InvalidStateForOperation, ConnectionRecord] =
1✔
55
    notifyOnSuccess(svc.acceptConnectionRequest(recordId))
56

1✔
57
  override def markConnectionResponseSent(
58
      recordId: UUID
59
  ): ZIO[WalletAccessContext, RecordIdNotFound | InvalidStateForOperation, ConnectionRecord] =
1✔
60
    notifyOnSuccess(svc.markConnectionResponseSent(recordId))
61

×
62
  override def markConnectionInvitationExpired(
63
      recordId: UUID
64
  ): URIO[WalletAccessContext, ConnectionRecord] =
×
65
    notifyOnSuccess(svc.markConnectionInvitationExpired(recordId))
66

1✔
67
  override def receiveConnectionResponse(
68
      response: ConnectionResponse
69
  ): ZIO[
70
    WalletAccessContext,
71
    ThreadIdMissingInReceivedMessage | ThreadIdNotFound | InvalidStateForOperation,
72
    ConnectionRecord
73
  ] =
1✔
74
    notifyOnSuccess(svc.receiveConnectionResponse(response))
75

1✔
76
  private[this] def notifyOnSuccess[E](effect: ZIO[WalletAccessContext, E, ConnectionRecord]) =
1✔
77
    for {
78
      record <- effect
1✔
79
      _ <- notify(record)
80
    } yield record
81

1✔
82
  private[this] def notify(record: ConnectionRecord) = {
1✔
83
    val result = for {
×
UNCOV
84
      walletId <- ZIO.serviceWith[WalletAccessContext](_.walletId)
×
85
      producer <- eventNotificationService.producer[ConnectionRecord]("Connect")
×
86
      _ <- producer.send(Event(connectionUpdatedEvent, record, walletId))
UNCOV
87
    } yield ()
×
88
    result.catchAll(e => ZIO.logError(s"Notification service error: $e"))
89
  }
90

×
91
  override def findRecordById(
92
      recordId: UUID
93
  ): URIO[WalletAccessContext, Option[ConnectionRecord]] =
×
94
    svc.findRecordById(recordId)
95

×
96
  override def findRecordByThreadId(
97
      thid: String
98
  ): URIO[WalletAccessContext, Option[ConnectionRecord]] =
×
99
    svc.findRecordByThreadId(thid)
100

×
101
  override def deleteRecordById(recordId: UUID): URIO[WalletAccessContext, Unit] =
×
102
    svc.deleteRecordById(recordId)
103

×
104
  override def reportProcessingFailure(
105
      recordId: UUID,
106
      failReason: Option[String]
107
  ): URIO[WalletAccessContext, Unit] =
×
108
    svc.reportProcessingFailure(recordId, failReason)
109

×
110
  override def findAllRecords(): URIO[WalletAccessContext, Seq[ConnectionRecord]] =
×
111
    svc.findAllRecords()
112

×
113
  override def findRecordsByStates(
114
      ignoreWithZeroRetries: Boolean,
115
      limit: Int,
116
      states: ConnectionRecord.ProtocolState*
117
  ): URIO[WalletAccessContext, Seq[ConnectionRecord]] =
×
118
    svc.findRecordsByStates(ignoreWithZeroRetries, limit, states: _*)
119

×
120
  override def findRecordsByStatesForAllWallets(
121
      ignoreWithZeroRetries: Boolean,
122
      limit: Int,
123
      states: ConnectionRecord.ProtocolState*
124
  ): UIO[Seq[ConnectionRecord]] =
×
125
    svc.findRecordsByStatesForAllWallets(ignoreWithZeroRetries, limit, states: _*)
126
}
127

128
object ConnectionServiceNotifier {
129
  val layer: URLayer[ConnectionService & EventNotificationService, ConnectionService] =
1✔
130
    ZLayer.fromFunction(ConnectionServiceNotifier(_, _))
131
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc