mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Increase test coverage of selenium
This commit is contained in:
@@ -27,7 +27,7 @@ namespace BTCPayServer.Tests
|
|||||||
Logs.LogProvider = new XUnitLogProvider(helper);
|
Logs.LogProvider = new XUnitLogProvider(helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact(Timeout = 60000)]
|
||||||
[Trait("Integration", "Integration")]
|
[Trait("Integration", "Integration")]
|
||||||
public async void CanSetChangellyPaymentMethod()
|
public async void CanSetChangellyPaymentMethod()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using BTCPayServer;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@@ -47,6 +48,10 @@ namespace BTCPayServer.Tests
|
|||||||
Driver.AssertNoError();
|
Driver.AssertNoError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Link(string relativeLink)
|
||||||
|
{
|
||||||
|
return Server.PayTester.ServerUri.AbsoluteUri.WithoutEndingSlash() + relativeLink.WithStartingSlash();
|
||||||
|
}
|
||||||
|
|
||||||
public string RegisterNewUser(bool isAdmin = false)
|
public string RegisterNewUser(bool isAdmin = false)
|
||||||
{
|
{
|
||||||
@@ -55,6 +60,7 @@ namespace BTCPayServer.Tests
|
|||||||
Driver.FindElement(By.Id("Email")).SendKeys(usr);
|
Driver.FindElement(By.Id("Email")).SendKeys(usr);
|
||||||
Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
||||||
Driver.FindElement(By.Id("ConfirmPassword")).SendKeys("123456");
|
Driver.FindElement(By.Id("ConfirmPassword")).SendKeys("123456");
|
||||||
|
if (isAdmin)
|
||||||
Driver.FindElement(By.Id("IsAdmin")).Click();
|
Driver.FindElement(By.Id("IsAdmin")).Click();
|
||||||
Driver.FindElement(By.Id("RegisterButton")).Click();
|
Driver.FindElement(By.Id("RegisterButton")).Click();
|
||||||
Driver.AssertNoError();
|
Driver.AssertNoError();
|
||||||
@@ -117,5 +123,20 @@ namespace BTCPayServer.Tests
|
|||||||
if (Server != null)
|
if (Server != null)
|
||||||
Server.Dispose();
|
Server.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void AssertNotFound()
|
||||||
|
{
|
||||||
|
Assert.Contains("Status Code: 404; Not Found", Driver.PageSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void GoToHome()
|
||||||
|
{
|
||||||
|
Driver.Navigate().GoToUrl(Server.PayTester.ServerUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Logout()
|
||||||
|
{
|
||||||
|
Driver.FindElement(By.Id("Logout")).Click();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,13 +43,24 @@ namespace BTCPayServer.Tests
|
|||||||
var email = s.RegisterNewUser();
|
var email = s.RegisterNewUser();
|
||||||
s.Driver.FindElement(By.Id("Logout")).Click();
|
s.Driver.FindElement(By.Id("Logout")).Click();
|
||||||
s.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
|
|
||||||
//Same User Can Log Back In
|
|
||||||
s.Driver.FindElement(By.Id("Login")).Click();
|
s.Driver.FindElement(By.Id("Login")).Click();
|
||||||
|
s.Driver.AssertNoError();
|
||||||
|
|
||||||
|
s.Driver.Navigate().GoToUrl(s.Link("/invoices"));
|
||||||
|
Assert.Contains("ReturnUrl=%2Finvoices", s.Driver.Url);
|
||||||
|
|
||||||
|
// We should be redirected to login
|
||||||
|
//Same User Can Log Back In
|
||||||
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
||||||
s.Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
s.Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
||||||
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
||||||
s.Driver.AssertNoError();
|
|
||||||
|
// We should be redirected to invoice
|
||||||
|
Assert.EndsWith("/invoices", s.Driver.Url);
|
||||||
|
|
||||||
|
// Should not be able to reach server settings
|
||||||
|
s.Driver.Navigate().GoToUrl(s.Link("/server/users"));
|
||||||
|
Assert.Contains("ReturnUrl=%2Fserver%2Fusers", s.Driver.Url);
|
||||||
|
|
||||||
//Change Password & Log Out
|
//Change Password & Log Out
|
||||||
s.Driver.FindElement(By.Id("MySettings")).Click();
|
s.Driver.FindElement(By.Id("MySettings")).Click();
|
||||||
@@ -67,10 +78,22 @@ namespace BTCPayServer.Tests
|
|||||||
s.Driver.FindElement(By.Id("Password")).SendKeys("abc???");
|
s.Driver.FindElement(By.Id("Password")).SendKeys("abc???");
|
||||||
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
||||||
Assert.True(s.Driver.PageSource.Contains("Stores"), "Can't Access Stores");
|
Assert.True(s.Driver.PageSource.Contains("Stores"), "Can't Access Stores");
|
||||||
|
|
||||||
|
s.Driver.FindElement(By.Id("MySettings")).Click();
|
||||||
|
s.ClickOnAllSideMenus();
|
||||||
|
|
||||||
s.Driver.Quit();
|
s.Driver.Quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void LogIn(SeleniumTester s, string email)
|
||||||
|
{
|
||||||
|
s.Driver.FindElement(By.Id("Login")).Click();
|
||||||
|
s.Driver.FindElement(By.Id("Email")).SendKeys(email);
|
||||||
|
s.Driver.FindElement(By.Id("Password")).SendKeys("123456");
|
||||||
|
s.Driver.FindElement(By.Id("LoginButton")).Click();
|
||||||
|
s.Driver.AssertNoError();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanCreateStores()
|
public void CanCreateStores()
|
||||||
@@ -78,14 +101,47 @@ namespace BTCPayServer.Tests
|
|||||||
using (var s = SeleniumTester.Create())
|
using (var s = SeleniumTester.Create())
|
||||||
{
|
{
|
||||||
s.Start();
|
s.Start();
|
||||||
s.RegisterNewUser();
|
var alice = s.RegisterNewUser();
|
||||||
var store = s.CreateNewStore();
|
var store = s.CreateNewStore();
|
||||||
|
s.AddDerivationScheme();
|
||||||
s.Driver.AssertNoError();
|
s.Driver.AssertNoError();
|
||||||
Assert.Contains(store, s.Driver.PageSource);
|
Assert.Contains(store, s.Driver.PageSource);
|
||||||
|
var storeUrl = s.Driver.Url;
|
||||||
s.ClickOnAllSideMenus();
|
s.ClickOnAllSideMenus();
|
||||||
|
|
||||||
s.Driver.Quit();
|
CreateInvoice(s, store);
|
||||||
|
s.Driver.FindElement(By.ClassName("invoice-details-link")).Click();
|
||||||
|
var invoiceUrl = s.Driver.Url;
|
||||||
|
|
||||||
|
// When logout we should not be able to access store and invoice details
|
||||||
|
s.Driver.FindElement(By.Id("Logout")).Click();
|
||||||
|
s.Driver.Navigate().GoToUrl(storeUrl);
|
||||||
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
||||||
|
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
||||||
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
||||||
|
|
||||||
|
// When logged we should not be able to access store and invoice details
|
||||||
|
var bob = s.RegisterNewUser();
|
||||||
|
s.Driver.Navigate().GoToUrl(storeUrl);
|
||||||
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
||||||
|
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
||||||
|
s.AssertNotFound();
|
||||||
|
s.GoToHome();
|
||||||
|
s.Logout();
|
||||||
|
|
||||||
|
// Let's add Bob as a guest to alice's store
|
||||||
|
LogIn(s, alice);
|
||||||
|
s.Driver.Navigate().GoToUrl(storeUrl + "/users");
|
||||||
|
s.Driver.FindElement(By.Id("Email")).SendKeys(bob + Keys.Enter);
|
||||||
|
Assert.Contains("User added successfully", s.Driver.PageSource);
|
||||||
|
s.Logout();
|
||||||
|
|
||||||
|
// Bob should not have access to store, but should have access to invoice
|
||||||
|
LogIn(s, bob);
|
||||||
|
s.Driver.Navigate().GoToUrl(storeUrl);
|
||||||
|
Assert.Contains("ReturnUrl", s.Driver.Url);
|
||||||
|
s.Driver.Navigate().GoToUrl(invoiceUrl);
|
||||||
|
s.Driver.AssertNoError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,14 +155,25 @@ namespace BTCPayServer.Tests
|
|||||||
var store = s.CreateNewStore();
|
var store = s.CreateNewStore();
|
||||||
s.AddDerivationScheme();
|
s.AddDerivationScheme();
|
||||||
|
|
||||||
|
CreateInvoice(s, store);
|
||||||
|
|
||||||
|
s.Driver.FindElement(By.ClassName("invoice-details-link")).Click();
|
||||||
|
s.Driver.AssertNoError();
|
||||||
|
s.Driver.Navigate().Back();
|
||||||
|
s.Driver.FindElement(By.ClassName("invoice-checkout-link")).Click();
|
||||||
|
Assert.NotEmpty(s.Driver.FindElements(By.Id("checkoutCtrl")));
|
||||||
|
s.Driver.Quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CreateInvoice(SeleniumTester s, string store)
|
||||||
|
{
|
||||||
s.Driver.FindElement(By.Id("Invoices")).Click();
|
s.Driver.FindElement(By.Id("Invoices")).Click();
|
||||||
s.Driver.FindElement(By.Id("CreateNewInvoice")).Click();
|
s.Driver.FindElement(By.Id("CreateNewInvoice")).Click();
|
||||||
s.Driver.FindElement(By.CssSelector("input#Amount.form-control")).SendKeys("100");
|
s.Driver.FindElement(By.CssSelector("input#Amount.form-control")).SendKeys("100");
|
||||||
s.Driver.FindElement(By.Name("StoreId")).SendKeys(store + Keys.Enter);
|
s.Driver.FindElement(By.Name("StoreId")).SendKeys(store + Keys.Enter);
|
||||||
s.Driver.FindElement(By.Id("Create")).Click();
|
s.Driver.FindElement(By.Id("Create")).Click();
|
||||||
Assert.True(s.Driver.PageSource.Contains("just created!"), "Unable to create Invoice");
|
Assert.True(s.Driver.PageSource.Contains("just created!"), "Unable to create Invoice");
|
||||||
s.Driver.Quit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -246,7 +246,7 @@
|
|||||||
@if (invoice.ShowCheckout)
|
@if (invoice.ShowCheckout)
|
||||||
{
|
{
|
||||||
<span>
|
<span>
|
||||||
<a asp-action="Checkout" asp-route-invoiceId="@invoice.InvoiceId">Checkout</a>
|
<a asp-action="Checkout" class="invoice-checkout-link" asp-route-invoiceId="@invoice.InvoiceId">Checkout</a>
|
||||||
<a href="javascript:btcpay.showInvoice('@invoice.InvoiceId')">[^]</a>
|
<a href="javascript:btcpay.showInvoice('@invoice.InvoiceId')">[^]</a>
|
||||||
@if (!invoice.CanMarkStatus)
|
@if (!invoice.CanMarkStatus)
|
||||||
{
|
{
|
||||||
@@ -255,7 +255,7 @@
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
|
|
||||||
<a asp-action="Invoice" asp-route-invoiceId="@invoice.InvoiceId">Details</a>
|
<a asp-action="Invoice" class="invoice-details-link" asp-route-invoiceId="@invoice.InvoiceId">Details</a>
|
||||||
@*<span title="Details" class="fa fa-list"></span>*@
|
@*<span title="Details" class="fa fa-list"></span>*@
|
||||||
|
|
||||||
<a href="javascript:void(0);" onclick="detailsToggle(this, '@invoice.InvoiceId')">
|
<a href="javascript:void(0);" onclick="detailsToggle(this, '@invoice.InvoiceId')">
|
||||||
|
|||||||
Reference in New Issue
Block a user