Skip to content

Commit

Permalink
feat(mediator): add ability to decode base64 message attachment for t…
Browse files Browse the repository at this point in the history
…he mediator handler
  • Loading branch information
goncalo-frade-iohk committed Jul 26, 2023
1 parent 6dc434c commit a389894
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
14 changes: 10 additions & 4 deletions AtalaPrismSDK/Pluto/Tests/CDDIDPrivateKeyDAOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class CDDIDPrivateKeyDAOTestsTests: XCTestCase {
alias: nil
).flatMap {
dao.getDIDInfo(did: testDID)
}.sink { _ in } receiveValue: {
}.first().sink { _ in } receiveValue: {
XCTAssertEqual(testDID, $0?.did)
XCTAssertEqual([testPrivateKey], $0?.privateKeys.map { $0 as? MockPrivateKey })
expectation.fulfill()
Expand Down Expand Up @@ -64,7 +64,9 @@ final class CDDIDPrivateKeyDAOTestsTests: XCTestCase {
}
.flatMap {
dao.getAll()
}.sink { _ in } receiveValue: {
}
.first()
.sink { _ in } receiveValue: {
XCTAssertEqual($0.count, 1)
expectation.fulfill()
}
Expand Down Expand Up @@ -99,7 +101,9 @@ final class CDDIDPrivateKeyDAOTestsTests: XCTestCase {
}
.flatMap {
dao.getAll()
}.sink { _ in } receiveValue: {
}
.first()
.sink { _ in } receiveValue: {
XCTAssertEqual($0.count, 2)
expectation.fulfill()
}
Expand Down Expand Up @@ -134,7 +138,9 @@ final class CDDIDPrivateKeyDAOTestsTests: XCTestCase {
}
.flatMap {
dao.getDIDInfo(did: testDID2)
}.sink { _ in } receiveValue: {
}
.first()
.sink { _ in } receiveValue: {
XCTAssertEqual(testDID2, $0?.did)
XCTAssertEqual([testPrivateKey2], $0?.privateKeys.map { $0 as? MockPrivateKey })
expectation.fulfill()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class PickupRunner {
return try await message.attachments.compactMap { attachment in
switch attachment.data {
case let base64 as AttachmentBase64:
return (base64.base64, attachment.id)
guard
let base64Data = Data(base64URLEncoded: base64.base64),
let base64String = String(data: base64Data, encoding: .utf8)
else { return nil }
return (base64String, attachment.id)
case let json as AttachmentJsonData:
return String(data: json.data, encoding: .utf8).map { ($0, attachment.id) }
default:
Expand Down
13 changes: 11 additions & 2 deletions AtalaPrismSDK/PrismAgent/Tests/PickupRunnerTests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Core
@testable import Domain
@testable import PrismAgent
import XCTest
Expand All @@ -19,7 +20,11 @@ final class PickupRunnerTests: XCTestCase {

func testWhenReceiveDeliveryMessageThenParseMessages() async throws {
attachments = try await messagesExamples.asyncMap {
AttachmentBase64(base64: try await mercury.packMessage(msg: $0))
try await mercury.packMessage(msg: $0).data(using: .utf8)?.base64UrlEncodedString()
}
.compactMap { $0 }
.map {
AttachmentBase64(base64: $0)
}
let message = Message(
piuri: ProtocolTypes.pickupDelivery.rawValue,
Expand All @@ -36,7 +41,11 @@ final class PickupRunnerTests: XCTestCase {

func testWhenReceiveNotDeliveryMessageThenThrowError() async throws {
attachments = try await messagesExamples.asyncMap {
AttachmentBase64(base64: try await mercury.packMessage(msg: $0))
try await mercury.packMessage(msg: $0).data(using: .utf8)?.base64UrlEncodedString()
}
.compactMap { $0 }
.map {
AttachmentBase64(base64: $0)
}
let message = Message(
piuri: "SomethingElse",
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ let package = Package(
),
.testTarget(
name: "PrismAgentTests",
dependencies: ["PrismAgent"],
dependencies: ["PrismAgent", "Core"],
path: "AtalaPrismSDK/PrismAgent/Tests"
),
.target(
Expand Down

0 comments on commit a389894

Please sign in to comment.