Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisreimann authored and Nisaba committed Feb 8, 2024
1 parent d0f517d commit 103acb1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 45 deletions.
52 changes: 11 additions & 41 deletions BTCPayServer.Tests/CrowdfundTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Security.AccessControl;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Form;
using BTCPayServer.Client;
Expand All @@ -13,16 +11,12 @@
using BTCPayServer.Plugins.Crowdfund;
using BTCPayServer.Plugins.Crowdfund.Controllers;
using BTCPayServer.Plugins.Crowdfund.Models;
using BTCPayServer.Plugins.PointOfSale.Models;
using BTCPayServer.Services.Apps;
using BTCPayServer.Services.Invoices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using NBitcoin;
using NBitpayClient;
using OpenQA.Selenium.DevTools.V100.Runtime;
using Xunit;
using Xunit.Abstractions;
using static BTCPayServer.Tests.UnitTest1;
Expand Down Expand Up @@ -283,7 +277,7 @@ public async Task CanComputeCrowdfundModel()
PosData = "posData",
ItemDesc = "Some description",
TransactionSpeed = "high",
FullNotifications = true,
FullNotifications = true
}, Facade.Merchant);
invoiceEntity = tester.PayTester.InvoiceRepository.GetInvoice(invoice.Id).GetAwaiter().GetResult();
Assert.DoesNotContain(AppService.GetAppInternalTag(app.Id), invoiceEntity.InternalTags);
Expand Down Expand Up @@ -314,7 +308,6 @@ public async Task CanComputeCrowdfundModel()
});
}


[Fact(Timeout = LongRunningTestTimeout)]
[Trait("Integration", "Integration")]
public async Task CrowdfundWithFormNoPerk()
Expand All @@ -328,32 +321,25 @@ public async Task CrowdfundWithFormNoPerk()

var frmService = tester.PayTester.GetService<FormDataService>();
var appService = tester.PayTester.GetService<AppService>();

var crowdfund = user.GetController<UICrowdfundController>();
var apps = user.GetController<UIAppsController>();

var vm = new CreateAppViewModel()
{
SelectedAppType = CrowdfundAppType.AppType,
AppName = "test",
};
var appData = new AppData { StoreDataId = user.StoreId, Name = "test", AppType = CrowdfundAppType.AppType };
await appService.UpdateOrCreateApp(appData);
var appList = Assert.IsType<ListAppsViewModel>(Assert.IsType<ViewResult>(apps.ListApps(user.StoreId).Result).Model);
var app = appList.Apps[0];
apps.HttpContext.SetAppData(appData);
crowdfund.HttpContext.SetAppData(appData);

var form = new Form()
var form = new Form
{
Fields = new List<Field>
{
Fields =
[
Field.Create("Enter your email", "item1", "[email protected]", true, null, "email"),
Field.Create("Name", "item2", 2.ToString(), true, null),
Field.Create("Item3", "invoice_item3", 3.ToString(), true, null)
}
]
};
var frmData = new FormData()
var frmData = new FormData
{
StoreId = user.StoreId,
Name = "frmTest",
Expand All @@ -368,20 +354,14 @@ public async Task CrowdfundWithFormNoPerk()
crowdfundViewModel.FormId = lstForms[0].Id;
crowdfundViewModel.TargetCurrency = "BTC";
crowdfundViewModel.Enabled = true;

Assert.IsType<RedirectToActionResult>(crowdfund.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result);

var vm2 = await crowdfund.CrowdfundForm(app.Id, (decimal?)0.01).AssertViewModelAsync<FormViewModel>();

var res = await crowdfund.CrowdfundFormSubmit(app.Id, (decimal)0.01, "", vm2);

Assert.IsNotType<NotFoundObjectResult>(res);
Assert.IsNotType<BadRequest>(res);


}


[Fact(Timeout = LongRunningTestTimeout)]
[Trait("Integration", "Integration")]
public async Task CrowdfundWithFormAndPerk()
Expand All @@ -395,32 +375,25 @@ public async Task CrowdfundWithFormAndPerk()

var frmService = tester.PayTester.GetService<FormDataService>();
var appService = tester.PayTester.GetService<AppService>();

var crowdfund = user.GetController<UICrowdfundController>();
var apps = user.GetController<UIAppsController>();

var vm = new CreateAppViewModel()
{
SelectedAppType = CrowdfundAppType.AppType,
AppName = "test",
};
var appData = new AppData { StoreDataId = user.StoreId, Name = "test", AppType = CrowdfundAppType.AppType };
await appService.UpdateOrCreateApp(appData);
var appList = Assert.IsType<ListAppsViewModel>(Assert.IsType<ViewResult>(apps.ListApps(user.StoreId).Result).Model);
var app = appList.Apps[0];
apps.HttpContext.SetAppData(appData);
crowdfund.HttpContext.SetAppData(appData);

var form = new Form()
var form = new Form
{
Fields = new List<Field>
{
Fields =
[
Field.Create("Enter your email", "item1", "[email protected]", true, null, "email"),
Field.Create("Name", "item2", 2.ToString(), true, null),
Field.Create("Item3", "invoice_item3", 3.ToString(), true, null)
}
]
};
var frmData = new FormData()
var frmData = new FormData
{
StoreId = user.StoreId,
Name = "frmTest",
Expand All @@ -436,13 +409,10 @@ public async Task CrowdfundWithFormAndPerk()
crowdfundViewModel.TargetCurrency = "BTC";
crowdfundViewModel.Enabled = true;
crowdfundViewModel.PerksTemplate = "[{\"id\": \"xxx\",\"title\": \"Perk 1\",\"priceType\": \"Fixed\",\"price\": \"0.001\",\"image\": \"\",\"description\": \"\",\"categories\": [],\"disabled\": false}]";

Assert.IsType<RedirectToActionResult>(crowdfund.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result);

var vm2 = await crowdfund.CrowdfundForm(app.Id, (decimal?)0.01, "xxx").AssertViewModelAsync<FormViewModel>();

var res = await crowdfund.CrowdfundFormSubmit(app.Id, (decimal)0.01, "xxx", vm2);

Assert.IsNotType<NotFoundObjectResult>(res);
Assert.IsNotType<BadRequest>(res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,10 @@ public async Task<IActionResult> ContributeToCrowdfund(string appId, ContributeT
FormDataService.SetValues(form, formResponseJObject);
if (!FormDataService.Validate(form, ModelState))
{
//someone tried to bypass validation
// someone tried to bypass validation
return RedirectToAction(nameof(ViewCrowdfund), new { appId });
}

}

}

var store = await _appService.GetStore(app);
Expand Down Expand Up @@ -356,7 +354,6 @@ public async Task<IActionResult> CrowdfundFormSubmit(string appId, decimal amoun
return View("Views/UIForms/View", viewModel);
}


[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[HttpGet("{appId}/settings/crowdfund")]
public async Task<IActionResult> UpdateCrowdfund(string appId)
Expand Down

0 comments on commit 103acb1

Please sign in to comment.