Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
feat: update put request body (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanwlee authored May 8, 2024
1 parent 1121c33 commit 23f2c27
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
15 changes: 15 additions & 0 deletions lib/src/http_client/models/submit_close_request.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:tbdex/src/protocol/models/close.dart';

class SubmitCloseRequest {
final Close close;

SubmitCloseRequest({
required this.close,
});

Map<String, dynamic> toJson() {
return {
'message': close.toJson(),
};
}
}
15 changes: 15 additions & 0 deletions lib/src/http_client/models/submit_order_request.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:tbdex/src/protocol/models/order.dart';

class SubmitOrderRequest {
final Order order;

SubmitOrderRequest({
required this.order,
});

Map<String, dynamic> toJson() {
return {
'message': order.toJson(),
};
}
}
10 changes: 5 additions & 5 deletions lib/src/http_client/tbdex_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions test/helpers/test_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/http_client/tbdex_http_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 23f2c27

Please sign in to comment.