Skip to content

Commit

Permalink
add more comments + add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
akwasi-cot committed Sep 2, 2024
1 parent 3aff731 commit 1fc7721
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 86 deletions.
13 changes: 4 additions & 9 deletions GenerateSdkFromSourceUrl.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,11 @@ module OpenApiHelpers =
let reversalPathResponseContent: Dictionary<string,OpenApiMediaType> = new Dictionary<string, OpenApiMediaType>()
reversalPathResponseContent.Add("application/json", reversalPathResponseMediaType)

let reversalPathResponseList: OpenApiResponses = new OpenApiResponses()
let reversalPathResponse: OpenApiResponse = new OpenApiResponse()
reversalPathResponse.Content <- reversalPathResponseContent
reversalPathResponse.Description <- "Success"

let reversalPathResponseList: OpenApiResponses = new OpenApiResponses()
reversalPathResponseList.Add("200", reversalPathResponse)

// OriginalTransactionSchema - Create teh schema for the original transaction field
Expand All @@ -367,17 +369,10 @@ module OpenApiHelpers =
originalTransactionSchema.MinLength <- 1
originalTransactionProperty.Add("original_transaction_token", originalTransactionSchema)

// Request body content which contains the aforementioned original Transaction schema
let requestBodySchemaProperties = new Dictionary<string, OpenApiSchema>()
let requestBodySchemaPropertiesSchema = new OpenApiSchema()
requestBodySchemaPropertiesSchema.Type <- "object"
requestBodySchemaPropertiesSchema.Properties <- originalTransactionProperty
requestBodySchemaProperties.Add("reverse_authorization_model", requestBodySchemaPropertiesSchema)

// Create the media type and schema for the request content
let requestBodyOpenApiMediaType = new OpenApiMediaType()
let requestBodySchema = new OpenApiSchema()
requestBodySchema.Properties <- requestBodySchemaProperties
requestBodySchema.Properties <- originalTransactionProperty
requestBodyOpenApiMediaType.Schema <- requestBodySchema

let requestBodyContent = new Dictionary<string, OpenApiMediaType>()
Expand Down
60 changes: 60 additions & 0 deletions Marqeta.Core.Sdk.Tests/MarqetaClientTests/TransactionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using AutoFixture;
using Marqeta.Core.Sdk.Models;
using Marqeta.Core.Sdk.Tests.MarqetaClientTests.Factories;
using Marqeta.Core.Sdk.Tests.MarqetaClientTests.Helpers;
using Marqeta.Core.Sdk.Transactions.Authorizationreversal;
using Xunit;

namespace Marqeta.Core.Sdk.Tests.MarqetaClientTests
{
public class TransactionTests : BaseTests
{
[Fact]
public async void Ensure_velocity_control_lifetime_is_honoured()
{
// Get client / fixture
var client = TestMarqetaClientFactory.Create();
var fixture = new Fixture();

// NB: Responses from other test classes have already had assertions run against them
//
// Get card product
var cardProductResponse = await CardProductHelper.CreateCardProduct();

// Create a program funding source
var programFundingSourceResponse = await ProgramFundingHelper.CreateProgramFundingSource();

// Create user account
var cardHolderResponse = await UserHelper.CreateUser();

// Create / activate card
var cardResponse = await CardTests.CreateCard(cardHolderResponse.Token, cardProductResponse.Token);

// Fund user account
const double fundingAmount = 1000;
await GpaOrderHelper.FundUserAccount(cardHolderResponse.Token, programFundingSourceResponse.Token, fundingAmount);

// Transaction that will be pending and reversed
var authRequest1 = new Auth_request_model
{
Amount = 1500,
Mid = fixture.Create<string>(),
CardToken = cardResponse.Token,
};
var simulateResponse1 = await client.Simulate.Authorization.PostAsync(authRequest1);
Assert.NotNull(simulateResponse1);
Assert.Equal(Transaction_model_state.PENDING, simulateResponse1.Transaction.State);

// Attempt reversal
var reversalRequest = new AuthorizationreversalPostRequestBody
{
OriginalTransactionToken = simulateResponse1.Transaction.Token
};

var updatedResponse = await client.Transactions.Authorizationreversal.PostAsync(reversalRequest);

Assert.NotNull(updatedResponse);
Assert.Equal(Transaction_model_state.COMPLETION, updatedResponse.State);
}
}
}
15 changes: 6 additions & 9 deletions Marqeta.Core.Sdk/CoreAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13871,17 +13871,14 @@ paths:
application/json:
schema:
properties:
reverse_authorization_model:
type: object
properties:
original_transaction_token:
maxLength: 36
minLength: 1
type: string
description: Identifies the transaction to reverse.
original_transaction_token:
maxLength: 36
minLength: 1
type: string
description: Identifies the transaction to reverse.
responses:
'200':
description:
description: Success
content:
application/json:
schema:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class AuthorizationreversalPostRequestBody : IAdditionalDataHolder, IPars
{
/// <summary>Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.</summary>
public IDictionary<string, object> AdditionalData { get; set; }
/// <summary>The reverse_authorization_model property</summary>
/// <summary>Identifies the transaction to reverse.</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public Marqeta.Core.Sdk.Transactions.Authorizationreversal.AuthorizationreversalPostRequestBody_reverse_authorization_model? ReverseAuthorizationModel { get; set; }
public string? OriginalTransactionToken { get; set; }
#nullable restore
#else
public Marqeta.Core.Sdk.Transactions.Authorizationreversal.AuthorizationreversalPostRequestBody_reverse_authorization_model ReverseAuthorizationModel { get; set; }
public string OriginalTransactionToken { get; set; }
#endif
/// <summary>
/// Instantiates a new <see cref="Marqeta.Core.Sdk.Transactions.Authorizationreversal.AuthorizationreversalPostRequestBody"/> and sets the default values.
Expand All @@ -45,7 +45,7 @@ public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
{
return new Dictionary<string, Action<IParseNode>>
{
{ "reverse_authorization_model", n => { ReverseAuthorizationModel = n.GetObjectValue<Marqeta.Core.Sdk.Transactions.Authorizationreversal.AuthorizationreversalPostRequestBody_reverse_authorization_model>(Marqeta.Core.Sdk.Transactions.Authorizationreversal.AuthorizationreversalPostRequestBody_reverse_authorization_model.CreateFromDiscriminatorValue); } },
{ "original_transaction_token", n => { OriginalTransactionToken = n.GetStringValue(); } },
};
}
/// <summary>
Expand All @@ -55,7 +55,7 @@ public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
public virtual void Serialize(ISerializationWriter writer)
{
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteObjectValue<Marqeta.Core.Sdk.Transactions.Authorizationreversal.AuthorizationreversalPostRequestBody_reverse_authorization_model>("reverse_authorization_model", ReverseAuthorizationModel);
writer.WriteStringValue("original_transaction_token", OriginalTransactionToken);
writer.WriteAdditionalData(AdditionalData);
}
}
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion Marqeta.Core.Sdk/Generated/kiota-lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"descriptionHash": "48B3FF237124433BFA5044B3ACB040C139C05D3A5F92456F388EF8E8137B279DBED3C18413919EE4F3BC448D080CEC9D832A0AB8C39FA196FF7E068E5402BEEF",
"descriptionHash": "A109DCDF9F099FB945D81AEB4E0BDA017EBEBC597F7B41B88AD1261E29CE5FEE1A995CB693A6D62AC7A2C9FEC5BC8552932975723B874B62046DF15EA618A8F6",
"descriptionLocation": "..\\CoreAPI.yaml",
"lockFileVersion": "1.0.0",
"kiotaVersion": "1.15.0",
Expand Down

0 comments on commit 1fc7721

Please sign in to comment.