forked from btcpayserver/btcpayserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nisaba
committed
Jan 22, 2024
1 parent
833ccb7
commit 578b531
Showing
2 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Security.AccessControl; | ||
using System.Threading.Tasks; | ||
using BTCPayServer.Abstractions.Form; | ||
using BTCPayServer.Client; | ||
using BTCPayServer.Client.Models; | ||
using BTCPayServer.Controllers; | ||
using BTCPayServer.Data; | ||
using BTCPayServer.Forms; | ||
using BTCPayServer.Forms.Models; | ||
using BTCPayServer.Models.AppViewModels; | ||
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; | ||
|
@@ -273,7 +283,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); | ||
|
@@ -303,5 +313,140 @@ public async Task CanComputeCrowdfundModel() | |
Assert.Equal(0.7m, model.Info.CurrentPendingAmount); | ||
}); | ||
} | ||
|
||
|
||
[Fact(Timeout = LongRunningTestTimeout)] | ||
[Trait("Integration", "Integration")] | ||
public async Task CrowdfundWithFormNoPerk() | ||
{ | ||
using var tester = CreateServerTester(); | ||
await tester.StartAsync(); | ||
var user = tester.NewAccount(); | ||
await user.GrantAccessAsync(); | ||
user.RegisterDerivationScheme("BTC"); | ||
await user.SetNetworkFeeMode(NetworkFeeMode.Never); | ||
|
||
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() | ||
{ | ||
Fields = new List<Field> | ||
{ | ||
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() | ||
{ | ||
StoreId = user.StoreId, | ||
Name = "frmTest", | ||
Config = form.ToString() | ||
}; | ||
await frmService.AddOrUpdateForm(frmData); | ||
|
||
var lstForms = await frmService.GetForms(user.StoreId); | ||
Assert.NotEmpty(lstForms); | ||
|
||
var crowdfundViewModel = await crowdfund.UpdateCrowdfund(app.Id).AssertViewModelAsync<UpdateCrowdfundViewModel>(); | ||
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() | ||
{ | ||
using var tester = CreateServerTester(); | ||
await tester.StartAsync(); | ||
var user = tester.NewAccount(); | ||
await user.GrantAccessAsync(); | ||
user.RegisterDerivationScheme("BTC"); | ||
await user.SetNetworkFeeMode(NetworkFeeMode.Never); | ||
|
||
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() | ||
{ | ||
Fields = new List<Field> | ||
{ | ||
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() | ||
{ | ||
StoreId = user.StoreId, | ||
Name = "frmTest", | ||
Config = form.ToString() | ||
}; | ||
await frmService.AddOrUpdateForm(frmData); | ||
|
||
var lstForms = await frmService.GetForms(user.StoreId); | ||
Assert.NotEmpty(lstForms); | ||
|
||
var crowdfundViewModel = await crowdfund.UpdateCrowdfund(app.Id).AssertViewModelAsync<UpdateCrowdfundViewModel>(); | ||
crowdfundViewModel.FormId = lstForms[0].Id; | ||
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); | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters