diff --git a/lib/src/http_client/models/submit_close_request.dart b/lib/src/http_client/models/submit_close_request.dart new file mode 100644 index 0000000..9131764 --- /dev/null +++ b/lib/src/http_client/models/submit_close_request.dart @@ -0,0 +1,15 @@ +import 'package:tbdex/src/protocol/models/close.dart'; + +class SubmitCloseRequest { + final Close close; + + SubmitCloseRequest({ + required this.close, + }); + + Map toJson() { + return { + 'message': close.toJson(), + }; + } +} diff --git a/lib/src/http_client/models/submit_order_request.dart b/lib/src/http_client/models/submit_order_request.dart new file mode 100644 index 0000000..62410c1 --- /dev/null +++ b/lib/src/http_client/models/submit_order_request.dart @@ -0,0 +1,15 @@ +import 'package:tbdex/src/protocol/models/order.dart'; + +class SubmitOrderRequest { + final Order order; + + SubmitOrderRequest({ + required this.order, + }); + + Map toJson() { + return { + 'message': order.toJson(), + }; + } +} diff --git a/lib/src/http_client/tbdex_http_client.dart b/lib/src/http_client/tbdex_http_client.dart index 825fab6..649a223 100644 --- a/lib/src/http_client/tbdex_http_client.dart +++ b/lib/src/http_client/tbdex_http_client.dart @@ -4,6 +4,8 @@ import 'package:http/http.dart' as http; import 'package:tbdex/src/http_client/models/create_exchange_request.dart'; import 'package:tbdex/src/http_client/models/exchange.dart'; import 'package:tbdex/src/http_client/models/get_offerings_filter.dart'; +import 'package:tbdex/src/http_client/models/submit_close_request.dart'; +import 'package:tbdex/src/http_client/models/submit_order_request.dart'; import 'package:tbdex/src/protocol/models/close.dart'; import 'package:tbdex/src/protocol/models/offering.dart'; import 'package:tbdex/src/protocol/models/order.dart'; @@ -102,9 +104,7 @@ class TbdexHttpClient { }) async { Validator.validateMessage(rfq); final pfiDid = rfq.metadata.to; - final body = jsonEncode( - CreateExchangeRequest(rfq: rfq, replyTo: replyTo), - ); + final body = jsonEncode(CreateExchangeRequest(rfq: rfq, replyTo: replyTo)); return _submitMessage(pfiDid, body); } @@ -113,7 +113,7 @@ class TbdexHttpClient { Validator.validateMessage(order); final pfiDid = order.metadata.to; final exchangeId = order.metadata.exchangeId; - final body = jsonEncode(order.toJson()); + final body = jsonEncode(SubmitOrderRequest(order: order)); return _submitMessage(pfiDid, body, exchangeId: exchangeId); } @@ -122,7 +122,7 @@ class TbdexHttpClient { Validator.validateMessage(close); final pfiDid = close.metadata.to; final exchangeId = close.metadata.exchangeId; - final body = jsonEncode(close.toJson()); + final body = jsonEncode(SubmitCloseRequest(close: close)); return _submitMessage(pfiDid, body, exchangeId: exchangeId); } diff --git a/test/helpers/test_data.dart b/test/helpers/test_data.dart index 2c6f2a4..b537572 100644 --- a/test/helpers/test_data.dart +++ b/test/helpers/test_data.dart @@ -2,6 +2,8 @@ import 'dart:convert'; import 'package:json_schema/json_schema.dart'; import 'package:tbdex/src/http_client/models/create_exchange_request.dart'; +import 'package:tbdex/src/http_client/models/submit_close_request.dart'; +import 'package:tbdex/src/http_client/models/submit_order_request.dart'; import 'package:tbdex/src/protocol/models/close.dart'; import 'package:tbdex/src/protocol/models/message.dart'; import 'package:tbdex/src/protocol/models/message_data.dart'; @@ -185,10 +187,10 @@ class TestData { jsonEncode(CreateExchangeRequest(rfq: rfq, replyTo: replyTo)); static String getSubmitOrderRequest(Order order) => - jsonEncode(order.toJson()); + jsonEncode(SubmitOrderRequest(order: order)); static String getSubmitCloseRequest(Close close) => - jsonEncode(close.toJson()); + jsonEncode(SubmitCloseRequest(close: close)); static JsonSchema requiredPaymentDetailsSchema() { return JsonSchema.create( diff --git a/test/http_client/tbdex_http_client_test.dart b/test/http_client/tbdex_http_client_test.dart index 631a56e..520c8f4 100644 --- a/test/http_client/tbdex_http_client_test.dart +++ b/test/http_client/tbdex_http_client_test.dart @@ -13,7 +13,7 @@ void main() async { const pfiServiceEndpoint = 'http://localhost:8892/ingress/pfi'; const didDoc = - '''{"id":"did:web:localhost%3A8892:ingress","verificationMethod":[{"id":"#0","type":"JsonWebKey","controller":"did:web:localhost%3A8892:ingress","publicKeyJwk":{"kty":"OKP","crv":"Ed25519","x":"oQ6Nl6pZjDa0I2MIsPV7q7aXX7moneoIC0XprR6ull8"}}],"service":[{"id":"#pfi","type":"PFI","serviceEndpoint":["localhost:8892/ingress/pfi"]}]}'''; + '''{"id":"did:web:localhost%3A8892:ingress","verificationMethod":[{"id":"#0","type":"JsonWebKey","controller":"did:web:localhost%3A8892:ingress","publicKeyJwk":{"kty":"OKP","crv":"Ed25519","x":"oQ6Nl6pZjDa0I2MIsPV7q7aXX7moneoIC0XprR6ull8"}}],"service":[{"id":"#pfi","type":"PFI","serviceEndpoint":["http://localhost:8892/ingress/pfi"]}]}'''; late MockHttpClient mockHttpClient;