Skip to content

Commit

Permalink
Fixed bug in Withdrawals.GetWithdrawal. Used wrong URL path.
Browse files Browse the repository at this point in the history
Refactoring in ExtensionsForTesting.
Proper acceptance test for Withdrawals.GetWithdrawal
  • Loading branch information
bchavez committed Aug 9, 2020
1 parent bdaaa34 commit c8a6495
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 15 deletions.
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v3.0.5
* Fixed `Withdrawals.GetWithdrawal()`. Previously used wrong URL path.

## v3.0.4
* Added `Deposits.GetDeposit()`
* Added `DateTimeOffset` parameters to `Withdrawals.ListWithdrawals()` and `Deposits.ListDeposits()`.
Expand Down
2 changes: 1 addition & 1 deletion Source/Coinbase.Pro/CoinbaseProClient.Withdrawals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Task<Withdrawal> IWithdrawalsEndpoint.GetWithdrawal(string transferId,
{
return this.TransfersEndpoint
.WithClient(this)
.SetQueryParam("transfer_id", transferId)
.AppendPathSegment(transferId)
.GetJsonAsync<Withdrawal>(cancellationToken);
}

Expand Down
12 changes: 12 additions & 0 deletions Source/Coinbase.Tests/EndpointTests/WithdrawlsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,17 @@ public async Task list_withdrawals()
await Verify(r);
}

[Test]
public async Task get_single_withdrawal()
{
server.RespondWithJsonTestFile();
var r = await client.Withdrawals.GetWithdrawal("fff");

server.ShouldHaveCalled("/transfers/fff")
.WithVerb(HttpMethod.Get);

await Verify(r);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"id": "DF7E6C3D-00E5-4BE2-A400-0FB8E5E7DBFB",
"type": "withdraw",
"created_at": "2020-08-08 19:38:15.245108+00",
"completed_at": null,
"canceled_at": null,
"processed_at": null,
"account_id": "C59D3DE6-8C16-4A23-9D18-26105770BC31",
"user_id": "888bbb888bbb88888sss88fff",
"user_nonce": "777777777772",
"amount": "1.00000000",
"details": {
"coinbase_payout_at": "2015-02-18T16:54:00-08:00",
"coinbase_account_id": "36028CFD-B782-419D-B0F0-7A59576277CB",
"coinbase_withdrawal_id": "D85FFEAF-5B95-4221-AEBE-3478EDB54C13",
"coinbase_transaction_id": "",
"coinbase_payment_method_id": "B3F6ED5F-E168-4C0B-B608-132C4037D6C6",
"coinbase_payment_method_type": "ach_bank_account"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
id: Guid_1,
type: 'withdraw',
created_at: DateTimeOffset_1,
account_id: Guid_2,
user_id: '888bbb888bbb88888sss88fff',
user_nonce: '777777777772',
amount: 1.00000000,
details: {
coinbase_account_id: Guid_3,
coinbase_withdrawal_id: Guid_4,
coinbase_transaction_id: '',
coinbase_payment_method_id: Guid_5,
coinbase_payout_at: DateTime_1,
coinbase_payment_method_type: 'ach_bank_account'
}
}
27 changes: 14 additions & 13 deletions Source/Coinbase.Tests/ExtensionsForTesting.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using DiffEngine;
using FluentAssertions;
using Flurl.Http;
using Flurl.Http.Testing;
Expand Down Expand Up @@ -63,13 +65,20 @@ public static HttpTest RespondWithJsonTestFile(this HttpTest server,
[CallerMemberName] string methodName = "",
[CallerFilePath] string filePath = "")
{
var verifiedFile = Path.ChangeExtension(filePath, $"{methodName}.server.json");
if( !File.Exists(verifiedFile) )
var responseFile = Path.ChangeExtension(filePath, $"{methodName}.server.json");

if( !File.Exists(responseFile) )
{
throw new FileNotFoundException($"*.server.json test file not found '{verifiedFile}'", verifiedFile);
var p = Process.Start("notepad.exe", responseFile);
p.WaitForExit();

if( !File.Exists(responseFile) )
{
throw new FileNotFoundException($"*.server.json test file not found '{responseFile}'", responseFile);
}
}

var json = File.ReadAllText(verifiedFile);
var json = File.ReadAllText(responseFile);
server.RespondWith(json, headers: headers);
return server;
}
Expand All @@ -79,15 +88,7 @@ public static HttpTest RespondWithJsonTestFilePagedResult(this HttpTest server,
[CallerMemberName] string methodName = "",
[CallerFilePath] string filePath = "")
{
var verifiedFile = Path.ChangeExtension(filePath, $"{methodName}.server.json");
if (!File.Exists(verifiedFile))
{
throw new FileNotFoundException("*.server.json file not found", verifiedFile);
}

var json = File.ReadAllText(verifiedFile);
server.RespondWith(json, headers: new { cb_before = cbBefore, cb_after = cbAfter });
return server;
return server.RespondWithJsonTestFile(headers: new {cb_before = cbBefore, cb_after = cbAfter}, methodName, filePath);
}

public static HttpTest RespondWithPagedResult(this HttpTest test, string json, int before, int after)
Expand Down
18 changes: 17 additions & 1 deletion Source/Coinbase.Tests/IntegrationTests/GeneralTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,26 @@ public async Task can_get_withdrawals()
w.Dump();
}

[Test]
public async Task can_get_single_withdrawl()
{
var w = await this.client.Withdrawals.GetWithdrawal("b6c836aa-bfba-460f-959d-fe0b2bcebd91");

w.Dump();
}

[Test]
public async Task can_get_deposits()
{
var d = await this.client.Deposits.ListDeposits(after: DateTime.Parse("8/8/2020"));
var d = await this.client.Deposits.ListDeposits(limit: 3);

d.Dump();
}

[Test]
public async Task can_get_single_deposit()
{
var d = await this.client.Deposits.GetDeposit("35810c2b-44c5-499c-81ff-8d056bc85d26");

d.Dump();
}
Expand Down

0 comments on commit c8a6495

Please sign in to comment.