Skip to content

Commit

Permalink
#3 Added a Create Transaction Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Moening committed Sep 4, 2019
1 parent 91cf5a4 commit e231691
Show file tree
Hide file tree
Showing 6 changed files with 439 additions and 38 deletions.
8 changes: 6 additions & 2 deletions YNAB.SDK.Tests/YNAB_BudgetsShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ public YNAB_BudgetsShould() { }


[Fact]
public void Budgets_FailWithBadAccessTokens() {
public async Task Budgets_FailWithBadAccessTokens() {
// Arrange
var badToken = "INVALID_TOKEN";
var ynabApi = new YNAB.SDK.API(badToken);
var goodToken = Environment.GetEnvironmentVariable("YNAB_TEST_TOKEN");
var ynabApi = new YNAB.SDK.API(goodToken);

// Act
var ct = new YNAB.SDK.Examples.CreateTransaction(ynabApi);
ct.Execute();
//await ct.ExecuteAsync();
// Assert
Assert.Throws<YNAB.SDK.Client.ApiException>(() => {
ynabApi.Budgets.GetBudgets();
Expand Down
4 changes: 2 additions & 2 deletions YNAB.SDK.Tests/YNAB_ExamplesShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public async Task Examples_RunSuccessfully() {
// await cmt.ExecuteAsync();

var ct = new CreateTransaction(api);
// ct.Execute();
// await ct.ExecuteAsync();
ct.Execute();
await ct.ExecuteAsync();

var dre = new DeltaRequestExample(api);
dre.Execute();
Expand Down
13 changes: 13 additions & 0 deletions YNAB.SDK.Tests/YnabApiStub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public YnabApiStub(int? port = null, bool useDefaultResponses = true) {
)
.AddDefaultHeaders();
}
var postEndpoint = "budgets/14235236-8085-4cf6-9fa6-92c34ed44b0c/transactions";
_stub.Post(
$"/{postEndpoint}",
(req, args) => {
return "{\"data\":{\"transaction_ids\":[\"013a8128-d78f-42ff-a59e-633a4c75253e\"],\"transaction\":{\"id\":\"013a8128-d78f-42ff-a59e-633a4c75253e\",\"date\":\"2019-09-04\",\"amount\":100,\"memo\":\"TEST\",\"cleared\":\"cleared\",\"approved\":true,\"flag_color\":\"red\",\"account_id\":\"09c21bf0-8bd0-4b7b-b158-4fe2df899991\",\"account_name\":\"Checking Account\",\"payee_id\":\"51b1c8ad-f51e-4782-a0dc-f1b2b2cadd61\",\"payee_name\":\"Starting Balance\",\"category_id\":\"6e6c1877-6fa7-461a-8f5f-0aadf361f8cd\",\"category_name\":\"Immediate Income SubCategory\",\"transfer_account_id\":null,\"transfer_transaction_id\":null,\"matched_transaction_id\":null,\"import_id\":null,\"deleted\":false,\"subtransactions\":[]},\"server_knowledge\":174}}";
}
);
}
}

Expand Down Expand Up @@ -78,6 +85,12 @@ public void AddGetRequest(string relativePath, Stubbery.RequestMatching.CreateSt
.AddDefaultHeaders();
}

public void AddPostRequest(string relativePath, Stubbery.RequestMatching.CreateStubResponse response)
{
_stub.Post(relativePath, response)
.AddDefaultHeaders();
}

/// <summary>
/// Tear down the stub
/// </summary>
Expand Down
Loading

0 comments on commit e231691

Please sign in to comment.