1870 lines
100 KiB
C++
1870 lines
100 KiB
C++
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
||
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
// Nostro's window without a window (Nostro.App): every screen built into a frame of the toolkit and pressed by name,
|
||
|
|
// against a real nostrod. nostrod is this executable again (its main is compiled in), on a fake system bus
|
||
|
|
// (tests/Support/FakeBus.inc) in front of a fake bunq (tests/Support/FakeBunq.inc), and every answer arrives through
|
||
|
|
// an sd-event loop, as in the app. What the screens say is read from the frame's draw list.
|
||
|
|
|
||
|
|
#include "../../lib/json.hpp"
|
||
|
|
#include <poll.h>
|
||
|
|
#include <signal.h>
|
||
|
|
#include <spawn.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <sys/resource.h>
|
||
|
|
#include <sys/socket.h>
|
||
|
|
#include <sys/un.h>
|
||
|
|
#include <sys/wait.h>
|
||
|
|
#include <systemd/sd-bus.h>
|
||
|
|
#include <systemd/sd-event.h>
|
||
|
|
#include <systemd/sd-id128.h>
|
||
|
|
#include <time.h>
|
||
|
|
#include <unistd.h>
|
||
|
|
|
||
|
|
import std;
|
||
|
|
import Nostro;
|
||
|
|
import Nostro.Ui;
|
||
|
|
import Nostro.App;
|
||
|
|
import Crafter.Network;
|
||
|
|
|
||
|
|
#define main NostrodMain
|
||
|
|
#include "../../implementations/nostrod.cpp"
|
||
|
|
#undef main
|
||
|
|
|
||
|
|
#include "../Support/Check.inc"
|
||
|
|
#include "../Support/Ui.inc"
|
||
|
|
#include "../Support/FakeBunq.inc"
|
||
|
|
#include "../Support/FakeBus.inc"
|
||
|
|
|
||
|
|
using namespace Nostro;
|
||
|
|
using namespace Nostro::Ui;
|
||
|
|
using Nostro::App::Fingerprint;
|
||
|
|
using Nostro::App::GroupIban;
|
||
|
|
using Nostro::App::Operation;
|
||
|
|
using Test::Check;
|
||
|
|
using Test::Equal;
|
||
|
|
using Test::Hides;
|
||
|
|
using Test::Shows;
|
||
|
|
using json = nlohmann::json;
|
||
|
|
using Fault = Fake::Fault;
|
||
|
|
using Where = std::source_location;
|
||
|
|
namespace fs = std::filesystem;
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
constexpr std::uint16_t port = 47307;
|
||
|
|
constexpr std::uint32_t uid = 4242;
|
||
|
|
constexpr std::string_view busName = "net.catcrafts.Nostro1";
|
||
|
|
const std::string aliceKey = "key-alice-0123456789abcdef";
|
||
|
|
const std::string aliceMain = "NL23BUNQ2025123456";
|
||
|
|
const std::string aliceSavings = "NL84BUNQ2025333333";
|
||
|
|
const std::string bobIban = "NL67BUNQ2025654321";
|
||
|
|
const std::string carolIban = "NL65BUNQ2025222222";
|
||
|
|
const std::string daveKey = "sandbox_dave_0123456789abcdef";
|
||
|
|
const std::string daveIban = "NL06BUNQ2025444444";
|
||
|
|
const std::string otherAliceIban = "NL25BUNQ2025555555";
|
||
|
|
const std::string strangerIban = "NL44BUNQ2025666666";
|
||
|
|
|
||
|
|
void SetPolkit(Fake::Bus& bus, Fake::Polkit outcome, std::string_view action = {}) {
|
||
|
|
std::lock_guard lock(bus.mutex);
|
||
|
|
if(action.empty()) {
|
||
|
|
bus.polkit = outcome;
|
||
|
|
bus.polkitByAction.clear();
|
||
|
|
} else {
|
||
|
|
bus.polkitByAction[std::string(action)] = outcome;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Runs the loop until `done` says so, for at most `limit`; whether it did.
|
||
|
|
template<typename Done>
|
||
|
|
bool RunUntil(sd_event* loop, Done&& done, std::chrono::seconds limit = std::chrono::seconds(60)) {
|
||
|
|
const std::chrono::steady_clock::time_point deadline = std::chrono::steady_clock::now() + limit;
|
||
|
|
while(!done()) {
|
||
|
|
if(std::chrono::steady_clock::now() >= deadline) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
sd_event_run(loop, 100000);
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
// The app with what a window gives it: a toolkit context of a phone's size, a client on the loop, a desktop that
|
||
|
|
// opens addresses, and a clock that stands still on 1 October 2026, the day the fake bunq dates what it makes.
|
||
|
|
struct Driver {
|
||
|
|
Fake::Bus& bus;
|
||
|
|
sd_event* loop;
|
||
|
|
std::chrono::seconds timeout = std::chrono::minutes(10);
|
||
|
|
bool noBus = false;
|
||
|
|
std::int32_t connects = 0;
|
||
|
|
std::vector<std::string> opened;
|
||
|
|
bool opens = true;
|
||
|
|
std::vector<std::string> answers;
|
||
|
|
std::int32_t settled = 0;
|
||
|
|
std::int64_t clock = 1000;
|
||
|
|
Box size{0, 0, 400, 800};
|
||
|
|
Context ui;
|
||
|
|
Nostro::App::App app;
|
||
|
|
|
||
|
|
// `bare`: with nothing but the connection, as a program that gives the app no more runs it.
|
||
|
|
Driver(Fake::Bus& bus, sd_event* loop, bool bare = false) : bus(bus), loop(loop), ui(Test::FixedMeasure()), app(ui, Host(bare)) {
|
||
|
|
if(!bare) {
|
||
|
|
app.onAnswer = [this](std::string_view member, bool failed) { answers.push_back(std::format("{} {}", member, failed ? "failed" : "ok")); };
|
||
|
|
app.onSettled = [this] { settled++; };
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
Nostro::App::Host Host(bool bare) {
|
||
|
|
Nostro::App::Host host;
|
||
|
|
host.connect = [this] {
|
||
|
|
connects++;
|
||
|
|
if(noBus) {
|
||
|
|
throw std::system_error(std::make_error_code(std::errc::connection_refused), "cannot connect to the system bus");
|
||
|
|
}
|
||
|
|
Client client = Client::System(timeout);
|
||
|
|
client.Attach(loop);
|
||
|
|
return client;
|
||
|
|
};
|
||
|
|
if(bare) {
|
||
|
|
return host;
|
||
|
|
}
|
||
|
|
host.openUri = [this](std::string_view uri, std::function<void(bool)> then) {
|
||
|
|
opened.emplace_back(uri);
|
||
|
|
then(opens);
|
||
|
|
};
|
||
|
|
host.now = [] { return ParseLocalDate("2026-10-01 15:00"); };
|
||
|
|
host.oauthState = [] { return std::string("state-1"); };
|
||
|
|
host.version = "1.2.3";
|
||
|
|
return host;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
// The regions already said to be too small to press, so that each is said once.
|
||
|
|
std::set<std::string, std::less<>> tooSmall;
|
||
|
|
// And the screens already said to name a bank.
|
||
|
|
std::set<std::string, std::less<>> naming;
|
||
|
|
|
||
|
|
// No screen names a bank, or a way to connect to one, in the app's own words: an account's pages are the same
|
||
|
|
// whichever bank it is with. Only the settings' pages that add a connection and list them do, from what the app
|
||
|
|
// knows of each bank. What nostrod and the bank say in their own words is theirs to say: the library's warning
|
||
|
|
// about a connector, a bank's refusal with the call it refused, a link the bank made.
|
||
|
|
void NamesNoBank(Driver& d) {
|
||
|
|
const std::string screen = d.app.Screen();
|
||
|
|
if(screen.starts_with("add") || screen.starts_with("connections")) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
std::string said;
|
||
|
|
for(const std::string& text : d.ui.Shown().draw.Texts()) {
|
||
|
|
said += text;
|
||
|
|
said += ' ';
|
||
|
|
}
|
||
|
|
for(const std::string_view theirs : {"bunq connector", "bunq GET", "bunq POST", "bunq PUT", "bunq DELETE", "bunq.me"}) {
|
||
|
|
for(std::size_t at = said.find(theirs); at != std::string::npos; at = said.find(theirs)) {
|
||
|
|
said.erase(at, theirs.size());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for(const std::string_view name : {"bunq", "OAuth"}) {
|
||
|
|
if(said.contains(name) && naming.insert(std::format("{} {}", screen, name)).second) {
|
||
|
|
std::println("FAIL: the screen {} says '{}', which is one bank's own. It says:\n{}", screen, name, Test::Said(d.ui));
|
||
|
|
Test::failures++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void Build(Driver& d) {
|
||
|
|
Frame& frame = d.ui.Begin(d.size, 1, d.clock);
|
||
|
|
d.app.Build(frame);
|
||
|
|
d.ui.End();
|
||
|
|
NamesNoBank(d);
|
||
|
|
// On a phone, what can be pressed is at least as wide and as tall as a finger needs, on every screen the tests
|
||
|
|
// come by.
|
||
|
|
if(d.ui.Shown().sizeClass != SizeClass::Compact) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
for(const Region& region : d.ui.Regions()) {
|
||
|
|
if(region.onTap && region.enabled && region.role != Role::Scrim && std::min(region.box.w, region.box.h) < Size::touch && tooSmall.insert(region.key).second) {
|
||
|
|
std::println("FAIL: on the screen {}, '{}' is {} by {}: less than a finger needs", d.app.Screen(), region.key, region.box.w, region.box.h);
|
||
|
|
Test::failures++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Waits until nostrod has answered everything the app asked, and draws what the user then sees.
|
||
|
|
void Settle(Driver& d, Where where = Where::current()) {
|
||
|
|
Check(RunUntil(d.loop, [&d] { return !d.app.Busy(); }), "nostrod answers", where);
|
||
|
|
Build(d);
|
||
|
|
}
|
||
|
|
|
||
|
|
// A tap on what is called `key`, and the frame after it; nostrod is not waited for.
|
||
|
|
void Tap(Driver& d, std::string_view key, Where where = Where::current()) {
|
||
|
|
Build(d);
|
||
|
|
if(!d.ui.Tap(key)) {
|
||
|
|
std::println("FAIL {}:{}: nothing called '{}' can be tapped. The screen ({}) says:\n{}", where.file_name(), where.line(), key, d.app.Screen(), Test::Said(d.ui));
|
||
|
|
Test::failures++;
|
||
|
|
}
|
||
|
|
Build(d);
|
||
|
|
}
|
||
|
|
|
||
|
|
// A tap, and what the user sees once nostrod has answered what it led to.
|
||
|
|
void Press(Driver& d, std::string_view key, Where where = Where::current()) {
|
||
|
|
Tap(d, key, where);
|
||
|
|
Settle(d, where);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Types into the field of that name, after what it holds.
|
||
|
|
void Type(Driver& d, std::string_view key, std::string_view text, Where where = Where::current()) {
|
||
|
|
Tap(d, key, where);
|
||
|
|
d.ui.Text(text);
|
||
|
|
Build(d);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Replaces what the field of that name holds.
|
||
|
|
void Retype(Driver& d, std::string_view key, std::string_view text, Where where = Where::current()) {
|
||
|
|
Tap(d, key, where);
|
||
|
|
d.ui.KeyDown(Key::A, {.control = true});
|
||
|
|
d.ui.KeyDown(Key::Backspace, {});
|
||
|
|
d.ui.Text(text);
|
||
|
|
Build(d);
|
||
|
|
}
|
||
|
|
|
||
|
|
bool Has(Driver& d, std::string_view key) {
|
||
|
|
return d.ui.Find(key) != nullptr;
|
||
|
|
}
|
||
|
|
|
||
|
|
// What the line called `label` says, of the sheet that is open: a press on it copies that. Nothing for no such line.
|
||
|
|
std::string Line(Driver& d, std::string_view label) {
|
||
|
|
Build(d);
|
||
|
|
if(!d.ui.Tap(std::format("copy.{}", label))) {
|
||
|
|
return {};
|
||
|
|
}
|
||
|
|
Build(d);
|
||
|
|
return d.ui.Take().copy.value_or(std::string());
|
||
|
|
}
|
||
|
|
|
||
|
|
// From the list of connections to the form of one of bunq's ways: the bank is chosen first, then the way.
|
||
|
|
void Adding(Driver& d, std::string_view way, Where where = Where::current()) {
|
||
|
|
Tap(d, "connections.add", where);
|
||
|
|
Tap(d, "bank.bunq", where);
|
||
|
|
Tap(d, std::format("way.{}", way), where);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Out of every page that was gone into, back to the place they were gone into from.
|
||
|
|
void Out(Driver& d) {
|
||
|
|
Build(d);
|
||
|
|
while(Has(d, "bar.back")) {
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Scrolls the page to its end, where what follows a long list is.
|
||
|
|
void Bottom(Driver& d) {
|
||
|
|
const std::string screen = d.app.Screen();
|
||
|
|
d.ui.Scroll(std::format("page:{}", screen.substr(0, screen.find('+')))).ScrollBy(1000000);
|
||
|
|
Build(d);
|
||
|
|
Build(d);
|
||
|
|
}
|
||
|
|
|
||
|
|
void Top(Driver& d) {
|
||
|
|
const std::string screen = d.app.Screen();
|
||
|
|
d.ui.Scroll(std::format("page:{}", screen.substr(0, screen.find('+')))).ScrollBy(-1000000);
|
||
|
|
Build(d);
|
||
|
|
}
|
||
|
|
|
||
|
|
// A tap beside a sheet, on what it covers: at the window's top, which no sheet reaches.
|
||
|
|
void TapBeside(Driver& d) {
|
||
|
|
Build(d);
|
||
|
|
Test::TapAt(d.ui, {200, 20}, d.clock);
|
||
|
|
Build(d);
|
||
|
|
}
|
||
|
|
|
||
|
|
// The key of the first row of a list: "incoming." gives the newest request received.
|
||
|
|
std::string Row(Driver& d, std::string_view prefix, std::size_t index = 0) {
|
||
|
|
std::size_t seen = 0;
|
||
|
|
for(const Region& region : d.ui.Regions()) {
|
||
|
|
if(region.key.starts_with(prefix) && seen++ == index) {
|
||
|
|
return region.key;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return std::format("no row {} of {}", index, prefix);
|
||
|
|
}
|
||
|
|
|
||
|
|
// How many lines of the screen say `text`.
|
||
|
|
std::size_t Count(Driver& d, std::string_view text) {
|
||
|
|
return static_cast<std::size_t>(std::ranges::count_if(d.ui.Shown().draw.Texts(), [text](const std::string& line) { return line.contains(text); }));
|
||
|
|
}
|
||
|
|
|
||
|
|
std::size_t Answers(const Driver& d, std::string_view answer) {
|
||
|
|
return static_cast<std::size_t>(std::ranges::count(d.answers, answer));
|
||
|
|
}
|
||
|
|
|
||
|
|
// nostrod's worker for the user: the other process on the bus besides nostrod itself.
|
||
|
|
pid_t Worker(Fake::Bus& bus, pid_t nostrod) {
|
||
|
|
for(const pid_t peer : bus.Peers()) {
|
||
|
|
if(peer != nostrod) {
|
||
|
|
return peer;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
// The polkit action of the last check that was for a change: every screen reads again after one, which is a
|
||
|
|
// check of its own.
|
||
|
|
std::string Action(Fake::Bus& bus) {
|
||
|
|
std::lock_guard lock(bus.mutex);
|
||
|
|
const auto change = std::ranges::find_if(std::views::reverse(bus.checks), [](const Fake::PolkitCheck& check) { return check.action != Bus::actionView; });
|
||
|
|
return change == std::views::reverse(bus.checks).end() ? std::string() : change->action;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Before nostrod runs: no system bus at all, then a bus without nostrod, then nostrod without a connection.
|
||
|
|
void Starting(Driver& d, pid_t& nostrod, const fs::path& state) {
|
||
|
|
d.noBus = true;
|
||
|
|
d.app.Start();
|
||
|
|
Check(!d.app.Busy() && !d.app.Changing(), "without a system bus nothing is waited for");
|
||
|
|
Build(d);
|
||
|
|
Shows(d.ui, "The system bus cannot be reached", "no system bus is said");
|
||
|
|
Shows(d.ui, "Connection refused", "with why");
|
||
|
|
Equal(d.app.Screen(), std::string("accounts"), "on the first screen");
|
||
|
|
Check(d.app.Overview().state == Nostro::App::LoadState::Failed, "nothing is known");
|
||
|
|
d.noBus = false;
|
||
|
|
Press(d, "overview.action");
|
||
|
|
Shows(d.ui, "Nostro's service is not running", "a bus without nostrod is said");
|
||
|
|
Shows(d.ui, "README", "with where to read how to install it");
|
||
|
|
Equal(d.answers.back(), std::string("Connectors failed"), "the answer is told to whoever listens");
|
||
|
|
|
||
|
|
nostrod = Fake::StartNostrod({"--state", state.string(), "--idle", "120", "--prompt-timeout", "2"});
|
||
|
|
Check(d.bus.WaitForName(busName), "nostrod owns its name");
|
||
|
|
Tap(d, "overview.action");
|
||
|
|
Check(d.app.Busy(), "nostrod is being asked");
|
||
|
|
Check(!Has(d, "overview.action"), "and the screen waits");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Welcome to Nostro", "a user without a bank connection is welcomed");
|
||
|
|
Check(Has(d, "nav.accounts") && Has(d, "nav.cards") && Has(d, "nav.settings"), "the app's places are along the bottom");
|
||
|
|
Equal(d.connects, 2, "one connection to the bus is all it took");
|
||
|
|
|
||
|
|
// Every place says so when it has nothing to show.
|
||
|
|
Press(d, "nav.cards");
|
||
|
|
Shows(d.ui, "No cards", "no cards");
|
||
|
|
Press(d, "nav.settings");
|
||
|
|
Shows(d.ui, "0 connected", "no connections");
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
Shows(d.ui, "No bank is connected yet", "none to list");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "settings.checkout");
|
||
|
|
Shows(d.ui, "No accounts to choose from", "and no account to pay at checkout from");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
// A connection without an account: there is nothing to pay from.
|
||
|
|
Client other = Client::System();
|
||
|
|
other.AddBunq("key-eve", "*", "");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "Eve", "a connection without accounts is listed");
|
||
|
|
Shows(d.ui, "No accounts", "as having none");
|
||
|
|
Check(!d.ui.Find("home.pay")->enabled && !d.ui.Find("home.request")->enabled, "and nothing can be paid or asked for");
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
Check(Has(d, "connection.Eve."), "and has a row among the connections");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
other.RemoveConnector("Eve");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "Welcome to Nostro", "without it the welcome is back");
|
||
|
|
// Connecting a bank from there: which bank first, then how, and then the form of that way.
|
||
|
|
Check(Has(d, "welcome.connect") && d.ui.Find("welcome.connect")->label == "Connect a bank", "which offers to connect a bank, whichever");
|
||
|
|
Tap(d, "welcome.connect");
|
||
|
|
Equal(d.app.Screen(), std::string("add"), "that leads to the banks there are");
|
||
|
|
Shows(d.ui, "Add a connection", "which is the first step of adding a connection");
|
||
|
|
Shows(d.ui, "Which bank is the account with?", "and asks which bank");
|
||
|
|
Check(Has(d, "bank.bunq") && !Has(d, "nav.accounts"), "bunq is one of them");
|
||
|
|
Shows(d.ui, "API key · OAuth", "listed with the ways it can be connected");
|
||
|
|
Tap(d, "bank.bunq");
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq"), "a bank leads to its ways");
|
||
|
|
Shows(d.ui, "How do you want to connect to bunq?", "which are asked for by the bank's name");
|
||
|
|
Check(Has(d, "way.key") && Has(d, "way.oauth"), "an API key and OAuth, for bunq");
|
||
|
|
Shows(d.ui, "Full access", "each with what it gives");
|
||
|
|
Tap(d, "way.oauth");
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq:oauth"), "and a way to its form");
|
||
|
|
Shows(d.ui, "bunq · OAuth", "which is called what was chosen");
|
||
|
|
Check(Has(d, "oauth.client"), "and is that way's own");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq"), "the way back is by the same steps: the ways");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Equal(d.app.Screen(), std::string("add"), "the banks");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Equal(d.app.Screen(), std::string("accounts"), "and the welcome it was gone into from");
|
||
|
|
Shows(d.ui, "Welcome to Nostro", "which is still there");
|
||
|
|
}
|
||
|
|
|
||
|
|
// The first connection, with an API key.
|
||
|
|
void Connecting(Driver& d, Fake::Bus& bus) {
|
||
|
|
Tap(d, "welcome.connect");
|
||
|
|
Tap(d, "bank.bunq");
|
||
|
|
Tap(d, "way.key");
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq:key"), "by the bank and the way, the welcome leads to the key's form");
|
||
|
|
Shows(d.ui, "bunq · API key", "which is called what was chosen");
|
||
|
|
Check(!Has(d, "nav.accounts") && Has(d, "bar.back"), "a page gone into has a way back and no way sideways");
|
||
|
|
Press(d, "key.connect");
|
||
|
|
Shows(d.ui, "The API key, from the bunq app", "a form without a key says so");
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq:key"), "and asks nostrod nothing");
|
||
|
|
Type(d, "key.key", aliceKey);
|
||
|
|
Shows(d.ui, std::format("Typed: {}", Fingerprint(aliceKey)), "what was typed is told by how it begins and ends");
|
||
|
|
Hides(d.ui, aliceKey, "and never shown");
|
||
|
|
Hides(d.ui, "The API key, from the bunq app", "the error goes once there is a key");
|
||
|
|
Check(!Has(d, "key.ips"), "the allowed addresses are tucked away");
|
||
|
|
Tap(d, "key.advanced");
|
||
|
|
Check(Has(d, "key.ips"), "until they are asked for");
|
||
|
|
Tap(d, "key.advanced");
|
||
|
|
Check(!Has(d, "key.ips"), "and can be put away again");
|
||
|
|
Check(!Has(d, "key.environment") && !Has(d, "key.environment.0"), "there is no environment to choose: the key says which it is of");
|
||
|
|
Shows(d.ui, "A key that starts with sandbox_", "which the form says");
|
||
|
|
|
||
|
|
// The password dialog closed without a password: nothing is added, and the key need not be typed again.
|
||
|
|
SetPolkit(bus, Fake::Polkit::Dismiss, Bus::actionConnectors);
|
||
|
|
Press(d, "key.connect");
|
||
|
|
Shows(d.ui, "Not confirmed", "a closed password dialog is said");
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq:key+problem"), "over the form");
|
||
|
|
Equal(d.settled, 1, "and the change is over");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
Shows(d.ui, std::format("Typed: {}", Fingerprint(aliceKey)), "the key is still in its field");
|
||
|
|
|
||
|
|
SetPolkit(bus, Fake::Polkit::Password, Bus::actionConnectors);
|
||
|
|
Tap(d, "key.connect");
|
||
|
|
Shows(d.ui, "Connecting to bunq", "the change under way is shown");
|
||
|
|
Shows(d.ui, "Confirm it in your system's password dialog.", "with where to confirm it");
|
||
|
|
Check(d.app.Changing() && d.app.Busy() && d.app.Screen() == "add:bunq:key+working", "it is under way");
|
||
|
|
TapBeside(d);
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq:key+working"), "and cannot be sent away");
|
||
|
|
d.ui.KeyDown(Key::Escape, {});
|
||
|
|
Build(d);
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq:key+working"), "by Escape either");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Connected Alice", "the connection is made");
|
||
|
|
Equal(Line(d, "Connected with"), std::string("API key"), "with the way that was chosen");
|
||
|
|
Equal(Line(d, "Environment"), std::string("Production"), "in the environment the key is of");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionConnectors), "after the password for changing connections");
|
||
|
|
Check(!d.app.Changing() && d.settled == 2, "and whoever waits for it is told");
|
||
|
|
Press(d, "done.close");
|
||
|
|
Equal(d.app.Screen(), std::string("accounts"), "which leads to the accounts");
|
||
|
|
Shows(d.ui, "Main", "the account is listed");
|
||
|
|
Shows(d.ui, GroupIban(aliceMain), "with its IBAN in groups");
|
||
|
|
Shows(d.ui, "€1,000.00", "and its balance");
|
||
|
|
Shows(d.ui, "€2,500.00", "and so is the other one");
|
||
|
|
Hides(d.ui, "Welcome to Nostro", "the welcome is over");
|
||
|
|
Check(Has(d, "home.pay") && Has(d, "home.request"), "paying and asking are at hand");
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
Shows(d.ui, "No account chosen", "no account pays at checkout yet");
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
Check(Has(d, "connections.add") && d.ui.Find("connections.add")->label == "Add a connection", "the settings add a connection too, of whichever bank");
|
||
|
|
Adding(d, "key");
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq:key"), "by the same steps");
|
||
|
|
Hides(d.ui, "Typed:", "a key that connected is forgotten");
|
||
|
|
Out(d);
|
||
|
|
Equal(d.app.Screen(), std::string("settings"), "and the way back leads to the settings they were gone into from");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
}
|
||
|
|
|
||
|
|
// The accounts' screen: what a refresh finds, a connection that does not work, the library's warnings, a reading
|
||
|
|
// that fails, and connections that change while they are read.
|
||
|
|
void Overview(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq, std::uint64_t alice, pid_t nostrod) {
|
||
|
|
Client other = Client::System();
|
||
|
|
other.AddBunq(daveKey, "*", "");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "Dave", "a connection made elsewhere is found by a refresh");
|
||
|
|
Shows(d.ui, "Sandbox", "and one of the sandbox is marked");
|
||
|
|
Shows(d.ui, "€123.45", "with its account");
|
||
|
|
Hides(d.ui, "Not working", "a connection that answers is not marked");
|
||
|
|
|
||
|
|
bunq.Fail(Fault{.method = "GET", .path = std::format("/user/{}", alice), .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "Not working", "a connection the bank does not answer for is marked");
|
||
|
|
Shows(d.ui, "Main", "and its accounts are still there");
|
||
|
|
const std::size_t readings = Answers(d, "Connectors ok");
|
||
|
|
Build(d);
|
||
|
|
d.ui.KeyDown(Key::F5, {});
|
||
|
|
Settle(d);
|
||
|
|
Equal(Answers(d, "Connectors ok"), readings + 1, "F5 reads the connections again, as the bar's Refresh does");
|
||
|
|
// And by a finger: the list pulled down at its top, and let go.
|
||
|
|
d.ui.Pointer(PointerPhase::Down, {200, 300}, d.clock);
|
||
|
|
d.ui.Pointer(PointerPhase::Move, {200, 380}, d.clock + 100);
|
||
|
|
Build(d);
|
||
|
|
Shows(d.ui, "Pull down to refresh", "a list dragged down at its top says what that is for");
|
||
|
|
d.ui.Pointer(PointerPhase::Move, {200, 460}, d.clock + 200);
|
||
|
|
Build(d);
|
||
|
|
Shows(d.ui, "Let go to refresh", "and when it is far enough down");
|
||
|
|
d.ui.Pointer(PointerPhase::Up, {200, 460}, d.clock + 300);
|
||
|
|
Settle(d);
|
||
|
|
Equal(Answers(d, "Connectors ok"), readings + 2, "let go, the connections are read again");
|
||
|
|
Hides(d.ui, "to refresh", "and the list is back where it was");
|
||
|
|
|
||
|
|
// The accounts could not be read from the bank: the library says so, once however often it happens.
|
||
|
|
for(std::int32_t i = 0; i < 2; i++) {
|
||
|
|
bunq.Fail(Fault{.method = "GET", .path = std::format("/user/{}/monetary-account", alice), .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
}
|
||
|
|
Equal(Count(d, "bunq connector 'Alice' is unavailable"), std::size_t{1}, "the library's warning is shown, once");
|
||
|
|
Hides(d.ui, "Not working", "the connection itself answers again");
|
||
|
|
|
||
|
|
// A reading that is refused: what was known stays, and why it is no newer is said, under the warning before.
|
||
|
|
SetPolkit(bus, Fake::Polkit::Deny, Bus::actionView);
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "The accounts could not be read again", "a refresh that fails says so");
|
||
|
|
Shows(d.ui, "is unavailable", "beside what was said before");
|
||
|
|
Shows(d.ui, "Main", "and leaves what was known");
|
||
|
|
Press(d, "notes.dismiss");
|
||
|
|
Hides(d.ui, "is unavailable", "until they are sent away");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Allow, Bus::actionView);
|
||
|
|
|
||
|
|
// A second refresh asked for while the first is under way waits for it, and is then made.
|
||
|
|
const std::size_t rounds = Answers(d, "Connectors ok");
|
||
|
|
Tap(d, "bar.refresh");
|
||
|
|
Tap(d, "bar.refresh");
|
||
|
|
Tap(d, "bar.refresh");
|
||
|
|
Settle(d);
|
||
|
|
Equal(Answers(d, "Connectors ok"), rounds + 2, "of readings asked for while one is under way, the last is made after it");
|
||
|
|
|
||
|
|
// nostrod's worker ends under the second of the two calls: the same.
|
||
|
|
SetPolkit(bus, Fake::Polkit::Slow, Bus::actionView);
|
||
|
|
std::size_t before = Answers(d, "Connectors ok");
|
||
|
|
Tap(d, "bar.refresh");
|
||
|
|
Check(RunUntil(d.loop, [&d, before] { return Answers(d, "Connectors ok") > before; }), "the connections are read");
|
||
|
|
kill(Worker(bus, nostrod), SIGTERM);
|
||
|
|
Settle(d);
|
||
|
|
Equal(d.answers.back(), std::string("Accounts failed"), "the accounts are not");
|
||
|
|
Shows(d.ui, "The accounts could not be read again", "which is said");
|
||
|
|
Press(d, "notes.dismiss");
|
||
|
|
|
||
|
|
// A connection is added between the two calls: both are read again, and then agree.
|
||
|
|
before = Answers(d, "Connectors ok");
|
||
|
|
Tap(d, "bar.refresh");
|
||
|
|
Check(RunUntil(d.loop, [&d, before] { return Answers(d, "Connectors ok") > before; }), "the connections are read");
|
||
|
|
other.AddBunq("key-bob", "*", "");
|
||
|
|
Settle(d);
|
||
|
|
Equal(Answers(d, "Connectors ok"), before + 2, "connections that changed while they were read are read again");
|
||
|
|
Shows(d.ui, "Bob's", "and what is shown is what there is");
|
||
|
|
// And once more while they are read again: the reading gives up, and says so.
|
||
|
|
before = Answers(d, "Connectors ok");
|
||
|
|
Tap(d, "bar.refresh");
|
||
|
|
Check(RunUntil(d.loop, [&d, before] { return Answers(d, "Connectors ok") > before; }), "the connections are read");
|
||
|
|
other.RemoveConnector("Bob");
|
||
|
|
Check(RunUntil(d.loop, [&d, before] { return Answers(d, "Connectors ok") > before + 1; }), "and read again");
|
||
|
|
other.AddBunq("key-bob", "*", "");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "connections kept changing", "connections that keep changing are given up on");
|
||
|
|
Press(d, "notes.dismiss");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Allow, Bus::actionView);
|
||
|
|
other.RemoveConnector("Bob");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Hides(d.ui, "Bob's", "a connection removed elsewhere is gone after a refresh");
|
||
|
|
}
|
||
|
|
|
||
|
|
// One account: its payments by day, the search, the filter, more of them, and one of them looked at.
|
||
|
|
void Activity(Driver& d, Fake::Bunq& bunq, std::uint64_t alice, std::uint64_t main) {
|
||
|
|
// Oldest first, as a bank makes them.
|
||
|
|
const std::uint64_t card = bunq.AddPayment(main, -999, "", "", "", {{"created", "2026-09-03 10:00:00.000000"}, {"type", "MASTERCARD"}, {"sub_type", "PAYMENT"}});
|
||
|
|
const std::uint64_t salary = bunq.AddPayment(main, 50000, "Employer", strangerIban, "salary", {{"created", "2026-09-30 08:00:00.000000"}, {"type", "EBA_SCT"}, {"sub_type", "SCT"}});
|
||
|
|
const std::uint64_t lunch = bunq.AddPayment(main, -1250, "Bob", bobIban, "lunch");
|
||
|
|
const std::string page = std::format("account:{}", aliceMain);
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Press(d, std::format("account.{}", aliceMain));
|
||
|
|
Equal(d.app.Screen(), page, "a row leads to its account");
|
||
|
|
Shows(d.ui, "€1,477.51", "its balance");
|
||
|
|
Shows(d.ui, GroupIban(aliceMain), "its IBAN");
|
||
|
|
Tap(d, "account.copy");
|
||
|
|
Check(d.ui.Take().copy == std::optional<std::string>(aliceMain), "which can be copied");
|
||
|
|
Shows(d.ui, "IBAN copied", "and says so");
|
||
|
|
for(const std::string_view said : {"Today", "Bob", "lunch", "-€12.50", "12:00", "Yesterday", "Employer", "salary", "+€500.00", "Thursday 3 September", "Card payment", "-€9.99"}) {
|
||
|
|
Shows(d.ui, said, "the payments are listed by day");
|
||
|
|
}
|
||
|
|
|
||
|
|
const std::size_t readings = Answers(d, "Transactions ok");
|
||
|
|
d.ui.KeyDown(Key::R, {.control = true});
|
||
|
|
Settle(d);
|
||
|
|
Equal(Answers(d, "Transactions ok"), readings + 1, "Ctrl+R reads the account's payments again");
|
||
|
|
d.ui.KeyDown(Key::F, {.control = true});
|
||
|
|
Build(d);
|
||
|
|
Equal(d.ui.Focused(), std::string_view("search"), "Ctrl+F goes to the search");
|
||
|
|
d.ui.Focus({});
|
||
|
|
|
||
|
|
Press(d, Row(d, std::format("tx.{}.", lunch)));
|
||
|
|
Equal(d.app.Screen(), std::format("{}+transaction", page), "a payment opens");
|
||
|
|
for(const std::string& said : {std::string("To"), std::string("Bob"), GroupIban(bobIban), std::string("Description"), std::string("1 October 2026, 12:"), std::string("Payment within the bank"), std::string("Bank's number")}) {
|
||
|
|
Shows(d.ui, said, "with all of it");
|
||
|
|
}
|
||
|
|
Shows(d.ui, "Press a line to copy it", "and says how a line of it is taken along");
|
||
|
|
Tap(d, "copy.IBAN");
|
||
|
|
Check(d.ui.Take().copy == std::optional<std::string>(bobIban), "a press on the IBAN copies it, without the spaces it is read with");
|
||
|
|
Shows(d.ui, "Copied", "and says so");
|
||
|
|
Check(d.ui.LongPress("copy.Description") && d.ui.Take().copy == std::optional<std::string>("lunch"), "a long press on a line copies it as it is shown");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
Equal(d.app.Screen(), page, "and closes");
|
||
|
|
Tap(d, Row(d, std::format("tx.{}.", card)));
|
||
|
|
Check(!Has(d, "detail.pay") && !Has(d, "detail.request"), "a payment to nobody known cannot be made again");
|
||
|
|
Shows(d.ui, "Card payment", "its kind is said in words");
|
||
|
|
TapBeside(d);
|
||
|
|
Equal(d.app.Screen(), page, "a tap beside it closes it too");
|
||
|
|
Tap(d, Row(d, std::format("tx.{}.", salary)));
|
||
|
|
Shows(d.ui, "From", "money that came in is from someone");
|
||
|
|
Shows(d.ui, "Bank transfer", "by a transfer");
|
||
|
|
Tap(d, "detail.pay");
|
||
|
|
Equal(d.app.Screen(), std::string("pay"), "paying again opens the form");
|
||
|
|
for(const std::string_view said : {std::string_view(strangerIban), std::string_view("Employer"), std::string_view("500.00"), std::string_view("salary")}) {
|
||
|
|
Shows(d.ui, said, "filled in from the payment");
|
||
|
|
}
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, Row(d, std::format("tx.{}.", salary)));
|
||
|
|
Tap(d, "detail.request");
|
||
|
|
Equal(d.app.Screen(), std::string("request"), "asking back opens the other form");
|
||
|
|
Shows(d.ui, strangerIban, "filled in too");
|
||
|
|
d.ui.KeyDown(Key::Escape, {});
|
||
|
|
Build(d);
|
||
|
|
Equal(d.app.Screen(), page, "Escape goes back");
|
||
|
|
|
||
|
|
// The search looks through what nostrod has stored of the list that is shown: with every letter typed, at
|
||
|
|
// once, and without a call to the bank.
|
||
|
|
const std::string listing = std::format("/user/{}/monetary-account/{}/payment", alice, main);
|
||
|
|
const std::size_t asked = Answers(d, "Transactions ok");
|
||
|
|
const std::size_t fetched = bunq.Count("GET", listing);
|
||
|
|
Type(d, "search", "lun");
|
||
|
|
Check(d.app.Busy(), "what is typed is looked for at once");
|
||
|
|
Settle(d);
|
||
|
|
Equal(Answers(d, "Transactions ok"), asked + 1, "nostrod is asked, once");
|
||
|
|
Equal(bunq.Count("GET", listing), fetched, "and the bank is not: the list was read from it when it was shown");
|
||
|
|
Shows(d.ui, "lunch", "what matches is listed");
|
||
|
|
Hides(d.ui, "salary", "what does not is not");
|
||
|
|
Retype(d, "search", "sal");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "salary", "each change of what is typed is looked for");
|
||
|
|
d.ui.KeyDown(Key::Enter, {});
|
||
|
|
Settle(d);
|
||
|
|
Retype(d, "search", "nothing like it");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Nothing matches", "a search without a match says so");
|
||
|
|
Equal(bunq.Count("GET", listing), fetched, "none of which asked the bank, Enter neither");
|
||
|
|
// A search typed while the list is being read again waits for that, and is then looked for in what it brought.
|
||
|
|
Tap(d, "bar.refresh");
|
||
|
|
Retype(d, "search", "lun");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "lunch", "a search behind a reading is answered after it");
|
||
|
|
Equal(bunq.Count("GET", listing), fetched + 1, "and only the reading asked the bank");
|
||
|
|
Retype(d, "search", "");
|
||
|
|
Settle(d);
|
||
|
|
|
||
|
|
// The filter: an exact amount paid or received, and between which days.
|
||
|
|
Tap(d, "filter");
|
||
|
|
Equal(d.app.Screen(), std::format("{}+filter", page), "the filter opens over the list");
|
||
|
|
Type(d, "filter.amount", "1,234");
|
||
|
|
Shows(d.ui, "At most 2 decimals", "a mistake is said where it is");
|
||
|
|
Check(!d.ui.Find("filter.show")->enabled, "and nothing can be shown by it");
|
||
|
|
Retype(d, "filter.amount", "12,50");
|
||
|
|
Press(d, "filter.show");
|
||
|
|
Equal(d.app.Screen(), page, "showing closes it");
|
||
|
|
Shows(d.ui, "Paid €12.50", "what is asked for is said above the list");
|
||
|
|
Shows(d.ui, "lunch", "the payment of that amount is listed");
|
||
|
|
Hides(d.ui, "salary", "and no other");
|
||
|
|
Tap(d, "filter");
|
||
|
|
Tap(d, "filter.direction.1");
|
||
|
|
Press(d, "filter.show");
|
||
|
|
Shows(d.ui, "Received €12.50", "the same amount coming in");
|
||
|
|
Shows(d.ui, "Nothing matches", "matches nothing");
|
||
|
|
Tap(d, "filter");
|
||
|
|
Retype(d, "filter.amount", "");
|
||
|
|
Type(d, "filter.from", "2026-09-30");
|
||
|
|
Type(d, "filter.to", "2026-09-30");
|
||
|
|
Press(d, "filter.show");
|
||
|
|
Shows(d.ui, "From 30 Sep", "a day's payments");
|
||
|
|
Shows(d.ui, "Until 30 Sep", "from its start to its end");
|
||
|
|
Shows(d.ui, "salary", "are that day's");
|
||
|
|
Hides(d.ui, "lunch", "and no other day's");
|
||
|
|
Tap(d, "filter");
|
||
|
|
TapBeside(d);
|
||
|
|
Equal(d.app.Screen(), page, "a tap beside the filter leaves it as it was");
|
||
|
|
Shows(d.ui, "From 30 Sep", "with what it asked for");
|
||
|
|
Tap(d, "filter");
|
||
|
|
Press(d, "filter.clear");
|
||
|
|
Shows(d.ui, "lunch", "clearing it shows everything again");
|
||
|
|
Hides(d.ui, "From 30 Sep", "and says nothing above the list");
|
||
|
|
|
||
|
|
// More than the hundred that are asked for at first. What the bank has had since the list was read is not in
|
||
|
|
// what nostrod has stored, so a search does not find it until the list is read again.
|
||
|
|
for(std::int32_t i = 0; i < 120; i++) {
|
||
|
|
bunq.AddPayment(main, -100, "Shop", strangerIban, std::format("item {}", i));
|
||
|
|
}
|
||
|
|
Retype(d, "search", "item 7");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Nothing matches", "a payment made since the list was read is not found by a search");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "item 7", "until the list is read again, which asks the bank and keeps the search");
|
||
|
|
Retype(d, "search", "");
|
||
|
|
Settle(d);
|
||
|
|
Bottom(d);
|
||
|
|
Check(Has(d, "more"), "a list as long as was asked for may go on");
|
||
|
|
Hides(d.ui, "lunch", "and does not reach the older payments yet");
|
||
|
|
const std::size_t before = bunq.Count("GET", listing);
|
||
|
|
Press(d, "more");
|
||
|
|
Bottom(d);
|
||
|
|
Shows(d.ui, "Thursday 3 September", "more of it reaches them");
|
||
|
|
Equal(bunq.Count("GET", listing), before, "from what nostrod has stored: the bank is not asked for older payments again");
|
||
|
|
Check(!Has(d, "more"), "and a list shorter than was asked for is at its end");
|
||
|
|
Top(d);
|
||
|
|
|
||
|
|
// The bank refuses the reading: it can be tried again.
|
||
|
|
const Fault hiccup{.method = "GET", .path = listing, .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"};
|
||
|
|
bunq.Fail(hiccup);
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "The bank refused", "a reading the bank refused is said");
|
||
|
|
Shows(d.ui, "Hiccup.", "with what it said");
|
||
|
|
Press(d, "activity.problem.action");
|
||
|
|
Shows(d.ui, "Shop", "and can be tried again");
|
||
|
|
|
||
|
|
// Where no list is shown there is nothing stored to look through that was just read: a search goes to the bank,
|
||
|
|
// which counts its calls, so it waits for the typing to stop, or for Enter.
|
||
|
|
bunq.Fail(hiccup);
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "The bank refused", "a list that could not be read");
|
||
|
|
const std::size_t tried = bunq.Count("GET", listing);
|
||
|
|
Type(d, "search", "sal");
|
||
|
|
Check(!d.app.Busy(), "a letter typed asks nothing yet");
|
||
|
|
d.clock += 399;
|
||
|
|
d.ui.Tick(d.clock);
|
||
|
|
Check(!d.app.Busy(), "nor does the wait that is not over");
|
||
|
|
d.clock += 1;
|
||
|
|
d.ui.Tick(d.clock);
|
||
|
|
Settle(d);
|
||
|
|
Equal(bunq.Count("GET", listing), tried + 1, "once the typing has stopped the bank is asked, once");
|
||
|
|
Shows(d.ui, "salary", "and what matches is listed");
|
||
|
|
bunq.Fail(hiccup);
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Retype(d, "search", "lun");
|
||
|
|
Check(!d.app.Busy(), "again nothing is asked while it is typed");
|
||
|
|
d.ui.KeyDown(Key::Enter, {});
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "lunch", "Enter asks at once");
|
||
|
|
d.clock += 1000;
|
||
|
|
d.ui.Tick(d.clock);
|
||
|
|
Check(!d.app.Busy() && bunq.Count("GET", listing) == tried + 3, "and the wait that was running is dropped");
|
||
|
|
Retype(d, "search", "");
|
||
|
|
Settle(d);
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Equal(d.app.Screen(), std::string("accounts"), "the way back leads to the accounts");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Paying: the form and what it refuses, the account picker, the button that sends it with no question of the app's
|
||
|
|
// own, and each kind of payment made.
|
||
|
|
void Paying(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq) {
|
||
|
|
const std::string page = std::format("account:{}", aliceMain);
|
||
|
|
Tap(d, "home.pay");
|
||
|
|
Equal(d.app.Screen(), std::string("pay"), "paying starts from the accounts");
|
||
|
|
Shows(d.ui, "Main", "from the first account");
|
||
|
|
Equal(d.ui.Find("pay.submit")->label, std::string("Pay"), "the form's button says what it does");
|
||
|
|
Tap(d, "pay.submit");
|
||
|
|
Shows(d.ui, "An IBAN, an e-mail address or a phone number", "a form without a payee says so");
|
||
|
|
Shows(d.ui, "Enter an amount", "and one without an amount");
|
||
|
|
Check(d.app.Screen() == "pay" && !d.app.Changing(), "and sends nothing");
|
||
|
|
Type(d, "pay.to", "NL23 BUNQ");
|
||
|
|
Shows(d.ui, "Not a valid IBAN", "an IBAN that is not one yet is said");
|
||
|
|
Retype(d, "pay.to", bobIban);
|
||
|
|
Shows(d.ui, "IBAN", "what kind of address it is is said under it");
|
||
|
|
Shows(d.ui, "The name of the account's holder", "an IBAN needs a name");
|
||
|
|
Type(d, "pay.name", "Bob");
|
||
|
|
Type(d, "pay.amount", "12,50");
|
||
|
|
Type(d, "pay.description", "lunch");
|
||
|
|
Hides(d.ui, "Enter an amount", "the errors go as they are mended");
|
||
|
|
|
||
|
|
// Which account pays.
|
||
|
|
Tap(d, "pay.from");
|
||
|
|
Equal(d.app.Screen(), std::string("pay+accounts"), "the paying account is chosen from a list");
|
||
|
|
Shows(d.ui, "Play money", "of every account");
|
||
|
|
Tap(d, std::format("pick.{}", aliceSavings));
|
||
|
|
Equal(d.app.Screen(), std::string("pay"), "choosing closes it");
|
||
|
|
Shows(d.ui, "Savings", "and the form pays from the chosen one");
|
||
|
|
Tap(d, "pay.from");
|
||
|
|
TapBeside(d);
|
||
|
|
Equal(d.app.Screen(), std::string("pay"), "a tap beside the list closes it");
|
||
|
|
Shows(d.ui, "Savings", "and changes nothing");
|
||
|
|
Tap(d, "pay.from");
|
||
|
|
Tap(d, std::format("pick.{}", aliceMain));
|
||
|
|
|
||
|
|
// The button sends it, by the keyboard here: the app asks nothing in between, since the system's password
|
||
|
|
// dialog is what confirms a payment. So the button must not be reached a second time while that is under way.
|
||
|
|
SetPolkit(bus, Fake::Polkit::Password, Bus::actionPay);
|
||
|
|
const std::size_t before = bunq.Count("POST", "/user/");
|
||
|
|
Build(d);
|
||
|
|
d.ui.Focus("pay.submit");
|
||
|
|
d.ui.KeyDown(Key::Enter, {});
|
||
|
|
d.ui.KeyDown(Key::Enter, {});
|
||
|
|
Build(d);
|
||
|
|
Equal(d.app.Screen(), std::string("pay+working"), "a form filled in is sent by its button, with no review of the app's own");
|
||
|
|
Shows(d.ui, "Paying €12.50 to Bob", "the payment under way is shown");
|
||
|
|
Shows(d.ui, "Confirm it in your system's password dialog.", "with where to confirm it");
|
||
|
|
Check(d.app.Changing(), "and is a change under way");
|
||
|
|
d.ui.KeyDown(Key::Enter, {});
|
||
|
|
d.ui.KeyDown(Key::Space, {});
|
||
|
|
d.ui.KeyDown(Key::Escape, {});
|
||
|
|
Check(!d.ui.Tap("pay.submit") && !d.ui.Tap("bar.back") && d.ui.Focused().empty(), "under which the form is out of reach: of a finger, and of the key that sent it");
|
||
|
|
Check(!d.app.Navigate("cards") && d.app.Screen() == "pay+working", "nor is the screen left by name while it is under way");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Paid €12.50 to Bob", "the payment made is said");
|
||
|
|
Check(Has(d, "copy.Payment") && !Test::Says(d.ui, "Press a line to copy it"), "with the bank's number of it, which can be copied without a word about it");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionPay), "after the password for paying");
|
||
|
|
Equal(bunq.Count("POST", "/user/"), before + 1, "and was made once, however often Enter was pressed");
|
||
|
|
Press(d, "done.close");
|
||
|
|
Equal(d.app.Screen(), std::string("accounts"), "which leads back to where paying began");
|
||
|
|
Tap(d, "home.pay");
|
||
|
|
Hides(d.ui, "lunch", "with the form empty for the next one");
|
||
|
|
|
||
|
|
// To an e-mail address, which needs no name, on a schedule.
|
||
|
|
Type(d, "pay.to", "bob@example.org");
|
||
|
|
Shows(d.ui, "E-mail address", "an e-mail address is known for one");
|
||
|
|
Type(d, "pay.amount", "5");
|
||
|
|
Tap(d, "pay.when.1");
|
||
|
|
Check(Has(d, "pay.day") && Has(d, "pay.time") && !Has(d, "pay.every"), "a schedule asks for its first day");
|
||
|
|
Bottom(d);
|
||
|
|
Equal(d.ui.Find("pay.submit")->label, std::string("Schedule"), "and its button says that it schedules");
|
||
|
|
Tap(d, "pay.submit");
|
||
|
|
Shows(d.ui, "A day: YYYY-MM-DD", "which it needs");
|
||
|
|
Check(!d.app.Changing(), "before anything is sent");
|
||
|
|
Type(d, "pay.day", "2026-10-02");
|
||
|
|
Type(d, "pay.time", "09:30");
|
||
|
|
Bottom(d);
|
||
|
|
Tap(d, "pay.unit.3");
|
||
|
|
Bottom(d);
|
||
|
|
Check(Has(d, "pay.every") && Has(d, "pay.until"), "one that repeats asks how often and until when");
|
||
|
|
Type(d, "pay.every", "2");
|
||
|
|
Type(d, "pay.until", "2027-01-01");
|
||
|
|
Bottom(d);
|
||
|
|
Tap(d, "pay.submit");
|
||
|
|
Shows(d.ui, "Scheduling €5.00 to bob@example.org", "a schedule is sent as one");
|
||
|
|
Shows(d.ui, "Confirm it in your system's password dialog.", "to confirm like a payment");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Scheduled €5.00 to bob@example.org", "and made");
|
||
|
|
Shows(d.ui, "Every 2 weeks from 2 Oct, 09:30", "with when it runs");
|
||
|
|
Shows(d.ui, "until 1 Jan 2027", "and until when");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionPay), "after the password for paying");
|
||
|
|
Press(d, "done.close");
|
||
|
|
|
||
|
|
// A draft: made now, paid once someone accepts it, and no password for making it.
|
||
|
|
Tap(d, "home.pay");
|
||
|
|
Type(d, "pay.to", "+31612345678");
|
||
|
|
Shows(d.ui, "Phone number", "a phone number is known for one");
|
||
|
|
Type(d, "pay.amount", "2");
|
||
|
|
Tap(d, "pay.when.2");
|
||
|
|
Shows(d.ui, "A draft is paid once it is accepted", "what a draft is is said");
|
||
|
|
Bottom(d);
|
||
|
|
Equal(d.ui.Find("pay.submit")->label, std::string("Save as draft"), "and the button says that it saves one");
|
||
|
|
Tap(d, "pay.submit");
|
||
|
|
Shows(d.ui, "Saving a draft of €2.00 to +31612345678", "a draft is saved at once");
|
||
|
|
Shows(d.ui, "One moment.", "and needs no password, so the wait says nothing of one");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Drafted €2.00 to +31612345678", "and is made");
|
||
|
|
Shows(d.ui, "It is paid once it is accepted", "with what that means");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionChange), "as a change that moves no money");
|
||
|
|
Press(d, "done.close");
|
||
|
|
|
||
|
|
// What can go wrong with a payment, each said for what it is.
|
||
|
|
Press(d, std::format("account.{}", aliceMain));
|
||
|
|
Tap(d, "account.pay");
|
||
|
|
Shows(d.ui, "Main", "paying from an account's own page pays from it");
|
||
|
|
Type(d, "pay.to", bobIban);
|
||
|
|
Type(d, "pay.name", "Bob");
|
||
|
|
Type(d, "pay.amount", "1");
|
||
|
|
const auto refused = [&](std::string_view title, std::string_view detail, Where where = Where::current()) {
|
||
|
|
Press(d, "pay.submit", where);
|
||
|
|
Shows(d.ui, title, "the payment's failure has a name", where);
|
||
|
|
Shows(d.ui, detail, "and is explained", where);
|
||
|
|
Equal(d.app.Screen(), std::string("pay+problem"), "over the form", where);
|
||
|
|
};
|
||
|
|
SetPolkit(bus, Fake::Polkit::Dismiss, Bus::actionPay);
|
||
|
|
refused("Not confirmed", "Nothing was done");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
Shows(d.ui, bobIban, "the form is still as it was filled in");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Deny, Bus::actionPay);
|
||
|
|
refused("Not allowed", "the system's policy does not allow");
|
||
|
|
TapBeside(d);
|
||
|
|
Equal(d.app.Screen(), std::string("pay"), "a tap beside the explanation closes it");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Absent, Bus::actionPay);
|
||
|
|
refused("Not allowed", "Nothing was done");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Password, Bus::actionPay);
|
||
|
|
bunq.Fail(Fault{.method = "POST", .path = "/user/", .status = 400, .body = R"({"Error":[{"error_description":"Not enough money."}]})"});
|
||
|
|
refused("The bank refused", "Not enough money.");
|
||
|
|
Check(!Has(d, "problem.activity"), "a refusal leaves nothing to look for");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
// bunq's 5xx leaves open whether it paid: that is said, the activity is offered, and trying again is not.
|
||
|
|
bunq.Fail(Fault{.method = "POST", .path = "/user/", .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||
|
|
refused("It may have been paid", "at the account's activity before trying again.");
|
||
|
|
Check(Has(d, "problem.activity") && !Has(d, "problem.draft"), "the account's activity is a press away");
|
||
|
|
Press(d, "problem.activity");
|
||
|
|
Equal(d.app.Screen(), page, "which shows the account");
|
||
|
|
Shows(d.ui, "Today", "and its payments");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Asking for money, and the request sent looked at and revoked.
|
||
|
|
void Requesting(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq) {
|
||
|
|
const std::string page = std::format("account:{}", aliceMain);
|
||
|
|
Tap(d, "home.request");
|
||
|
|
Equal(d.app.Screen(), std::string("request"), "asking starts from the accounts");
|
||
|
|
Tap(d, "request.review");
|
||
|
|
Shows(d.ui, "Enter an amount", "a form that is empty says what it lacks");
|
||
|
|
Tap(d, "request.into");
|
||
|
|
Tap(d, std::format("pick.{}", aliceMain));
|
||
|
|
Type(d, "request.from", bobIban);
|
||
|
|
Tap(d, "request.review");
|
||
|
|
Shows(d.ui, "The name of the account's holder", "an IBAN needs a name here too");
|
||
|
|
Type(d, "request.name", "Bob");
|
||
|
|
Type(d, "request.amount", "5");
|
||
|
|
Type(d, "request.description", "back");
|
||
|
|
Tap(d, "request.review");
|
||
|
|
Equal(d.app.Screen(), std::string("request+review"), "a request is reviewed");
|
||
|
|
Shows(d.ui, "Ask Bob for €5.00?", "as what it is");
|
||
|
|
Shows(d.ui, std::format("Main · {}", GroupIban(aliceMain)), "and into which account");
|
||
|
|
Hides(d.ui, "Your system asks for your password", "it needs no password");
|
||
|
|
Tap(d, "review.back");
|
||
|
|
Tap(d, "request.review");
|
||
|
|
Press(d, "review.confirm");
|
||
|
|
Shows(d.ui, "Asked Bob for €5.00", "the request is made");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionChange), "as a change that moves no money");
|
||
|
|
Shows(d.ui, "https://bunq.me/t/", "with the link anyone can pay through");
|
||
|
|
const std::vector<std::string> said = d.ui.Shown().draw.Texts();
|
||
|
|
const std::string link = *std::ranges::find_if(said, [](const std::string& line) { return line.starts_with("https://bunq.me/"); });
|
||
|
|
Tap(d, "dialog.copy");
|
||
|
|
Check(d.ui.Take().copy == std::optional<std::string>(link), "which can be copied");
|
||
|
|
Shows(d.ui, "Link copied", "and says so");
|
||
|
|
Tap(d, "dialog.open");
|
||
|
|
Check(d.opened.size() == 1 && d.opened.back() == link, "or opened");
|
||
|
|
d.opens = false;
|
||
|
|
Tap(d, "dialog.open");
|
||
|
|
Shows(d.ui, "No browser could be opened", "and when it cannot be, that is said");
|
||
|
|
d.opens = true;
|
||
|
|
Press(d, "done.close");
|
||
|
|
Equal(d.app.Screen(), std::string("accounts"), "which leads back");
|
||
|
|
|
||
|
|
// A request that leaves open whether it was made is not left in its form either.
|
||
|
|
Tap(d, "home.request");
|
||
|
|
Type(d, "request.from", "+31612345678");
|
||
|
|
Type(d, "request.amount", "3");
|
||
|
|
Tap(d, "request.review");
|
||
|
|
Shows(d.ui, "Ask +31612345678 for €3.00?", "someone asked by phone number is named by it");
|
||
|
|
bunq.Fail(Fault{.method = "POST", .path = "/user/", .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||
|
|
Press(d, "review.confirm");
|
||
|
|
Shows(d.ui, "It may have been done", "a request without a clear answer may have been made");
|
||
|
|
Check(Has(d, "problem.activity"), "and the account is a press away");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
Hides(d.ui, "+31612345678", "with its form emptied");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
|
||
|
|
// Dave pays a request of Alice's: it is listed as paid, with what was paid.
|
||
|
|
Client other = Client::System();
|
||
|
|
other.Request(aliceMain, daveIban, "Dave", 400, "owed");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Password, Bus::actionPay);
|
||
|
|
other.RespondToRequest(daveIban, other.IncomingRequests(daveIban).front().id, true);
|
||
|
|
|
||
|
|
Press(d, std::format("account.{}", aliceMain));
|
||
|
|
Tap(d, "account.request");
|
||
|
|
Equal(d.app.Screen(), std::string("request"), "an account's own page asks into it");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Press(d, "tabs.1");
|
||
|
|
Shows(d.ui, "Accepted · owed", "a request that was paid is listed as such");
|
||
|
|
Tap(d, Row(d, "request."));
|
||
|
|
Shows(d.ui, "Paid", "with what was paid");
|
||
|
|
Check(!Has(d, "detail.revoke"), "and nothing left to take back");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
Shows(d.ui, "Bob", "the request sent is listed");
|
||
|
|
Shows(d.ui, "Pending · back", "with how it stands");
|
||
|
|
const std::string row = Row(d, "request.", 1);
|
||
|
|
Tap(d, row);
|
||
|
|
Equal(d.app.Screen(), std::format("{}+request", page), "and opens");
|
||
|
|
Shows(d.ui, "€5.00 asked of Bob", "as what it is");
|
||
|
|
Check(Has(d, "dialog.copy") && Has(d, "detail.revoke"), "with its link, and a way to take it back");
|
||
|
|
Tap(d, "detail.revoke");
|
||
|
|
Equal(d.app.Screen(), std::format("{}+confirm", page), "taking it back is asked about first");
|
||
|
|
Shows(d.ui, "Revoke the request to Bob?", "by name");
|
||
|
|
Tap(d, "confirm.no");
|
||
|
|
Equal(d.app.Screen(), page, "and can be thought better of");
|
||
|
|
Tap(d, row);
|
||
|
|
Tap(d, "detail.revoke");
|
||
|
|
Press(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Request revoked", "a revoked request is said");
|
||
|
|
Shows(d.ui, "Revoked · back", "and listed as such");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionChange), "as a change");
|
||
|
|
Tap(d, row);
|
||
|
|
Check(!Has(d, "detail.revoke"), "what is revoked cannot be revoked again");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
Press(d, "tabs.0");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
}
|
||
|
|
|
||
|
|
// An account's other lists: what was asked of it, what is scheduled from it, and what waits to be accepted.
|
||
|
|
void Lists(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq, std::uint64_t alice, std::uint64_t main) {
|
||
|
|
const std::string page = std::format("account:{}", aliceMain);
|
||
|
|
Client other = Client::System();
|
||
|
|
// Dave asks Alice for money, twice.
|
||
|
|
other.Request(daveIban, aliceMain, "Alice", 700, "rent");
|
||
|
|
other.Request(daveIban, aliceMain, "Alice", 800, "food");
|
||
|
|
Press(d, std::format("account.{}", aliceMain));
|
||
|
|
Press(d, "tabs.2");
|
||
|
|
Shows(d.ui, "Dave", "a request received is listed");
|
||
|
|
Shows(d.ui, "Pending · food", "with how it stands");
|
||
|
|
Shows(d.ui, "€8.00", "and what it asks");
|
||
|
|
Tap(d, Row(d, "incoming."));
|
||
|
|
Equal(d.app.Screen(), std::format("{}+incoming", page), "and opens");
|
||
|
|
Shows(d.ui, "Dave asks for €8.00", "as what it is");
|
||
|
|
Shows(d.ui, "Internal", "with its kind");
|
||
|
|
Check(d.ui.Find("detail.pay")->enabled, "it can be paid");
|
||
|
|
Tap(d, "detail.pay");
|
||
|
|
Shows(d.ui, "Pay €8.00 to Dave?", "paying it is asked about first");
|
||
|
|
Shows(d.ui, "Your system asks for your password", "and needs the password");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Password, Bus::actionPay);
|
||
|
|
Tap(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Confirm it in your system's password dialog.", "which the wait says");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Paid €8.00 to Dave", "a request paid is said");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionPay), "after the password for paying");
|
||
|
|
Press(d, "done.close");
|
||
|
|
Equal(d.app.Screen(), page, "which leads back to the list");
|
||
|
|
Shows(d.ui, "Accepted · food", "where it is listed as paid");
|
||
|
|
Tap(d, Row(d, "incoming.", 1));
|
||
|
|
Tap(d, "detail.reject");
|
||
|
|
Shows(d.ui, "Reject the request from Dave?", "rejecting is asked about first");
|
||
|
|
Hides(d.ui, "Your system asks for your password", "and needs no password");
|
||
|
|
Press(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Request rejected", "a request rejected is said");
|
||
|
|
Shows(d.ui, "Rejected · rent", "and listed as such");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionChange), "as a change that moves no money");
|
||
|
|
Tap(d, Row(d, "incoming.", 1));
|
||
|
|
Check(!Has(d, "detail.pay") && !Has(d, "detail.reject"), "what was answered cannot be answered again");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
|
||
|
|
// bunq names nobody for a payee it knows by an e-mail address or a phone number alone.
|
||
|
|
Press(d, "tabs.3");
|
||
|
|
Shows(d.ui, "Unknown", "the schedule made earlier is listed");
|
||
|
|
Shows(d.ui, "Active", "as running");
|
||
|
|
Tap(d, Row(d, "scheduled."));
|
||
|
|
Equal(d.app.Screen(), std::format("{}+scheduled", page), "and opens");
|
||
|
|
Shows(d.ui, "€5.00 to Unknown", "as what it is");
|
||
|
|
Tap(d, "detail.cancel");
|
||
|
|
Shows(d.ui, "Cancel the payments of €5.00 to Unknown?", "cancelling is asked about first");
|
||
|
|
Press(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Schedule cancelled", "a schedule cancelled is said");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionChange), "as a change");
|
||
|
|
Shows(d.ui, "No payments are scheduled from this account", "and gone from the list");
|
||
|
|
// One that has run its course is listed, and has nothing left to cancel.
|
||
|
|
other.Schedule(aliceMain, bobIban, "Bob", 300, "rent", BunqSchedule{.start = ParseLocalDate("2026-10-02"), .unit = "MONTHLY"});
|
||
|
|
{
|
||
|
|
std::lock_guard lock(bunq.mutex);
|
||
|
|
bunq.schedules[main].front()["ScheduledPayment"]["status"] = "FINISHED";
|
||
|
|
}
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "Every month from 2 Oct", "a schedule made elsewhere is found by a refresh");
|
||
|
|
Tap(d, Row(d, "scheduled."));
|
||
|
|
for(const std::string_view said : {"€3.00 to Bob", "Finished", "Next", "IBAN", "Description", "rent"}) {
|
||
|
|
Shows(d.ui, said, "with all of it");
|
||
|
|
}
|
||
|
|
Check(!Has(d, "detail.cancel"), "what is over cannot be cancelled");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
|
||
|
|
Press(d, "tabs.4");
|
||
|
|
Shows(d.ui, "Pending · Alice", "the draft made earlier is listed, with who made it");
|
||
|
|
Shows(d.ui, "€2.00", "and its sum");
|
||
|
|
Tap(d, Row(d, "draft."));
|
||
|
|
Equal(d.app.Screen(), std::format("{}+draft", page), "and opens");
|
||
|
|
Shows(d.ui, "A draft of €2.00", "as what it is");
|
||
|
|
Tap(d, "detail.accept");
|
||
|
|
Shows(d.ui, "Accept the draft and pay €2.00?", "accepting is asked about first");
|
||
|
|
Press(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Draft accepted: €2.00 paid", "a draft accepted is said");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionPay), "after the password for paying");
|
||
|
|
Press(d, "done.close");
|
||
|
|
other.Draft(aliceMain, bobIban, "Bob", 300, "gift");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "Pending · Alice", "a draft made elsewhere is found by a refresh");
|
||
|
|
Tap(d, Row(d, "draft."));
|
||
|
|
Shows(d.ui, "€3.00 · gift", "with what it is for");
|
||
|
|
Tap(d, "detail.reject");
|
||
|
|
Shows(d.ui, "Reject the draft of €3.00?", "rejecting is asked about first");
|
||
|
|
Press(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Draft rejected", "a draft rejected is said");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionChange), "as a change");
|
||
|
|
Tap(d, Row(d, "draft."));
|
||
|
|
Check(!Has(d, "detail.accept"), "what was answered cannot be answered again");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
|
||
|
|
// The bank refuses a list: it can be tried again, and is by coming back to it.
|
||
|
|
bunq.Fail(Fault{.method = "GET", .path = std::format("/user/{}/monetary-account/{}/draft-payment", alice, main), .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "The bank refused", "a list the bank refused is said");
|
||
|
|
Press(d, "list.problem.action");
|
||
|
|
Shows(d.ui, "Rejected · Alice", "and can be tried again");
|
||
|
|
bunq.Fail(Fault{.method = "GET", .path = std::format("/user/{}/monetary-account/{}/draft-payment", alice, main), .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "The bank refused", "a list that failed");
|
||
|
|
Press(d, "tabs.3");
|
||
|
|
Press(d, "tabs.4");
|
||
|
|
Shows(d.ui, "Rejected · Alice", "is read again when it is come back to");
|
||
|
|
// A draft of several payments is named by the first, and one of none by nobody.
|
||
|
|
{
|
||
|
|
std::lock_guard lock(bunq.mutex);
|
||
|
|
const json entry = bunq.drafts[main].front()["DraftPayment"]["entries"][0];
|
||
|
|
bunq.drafts[main].insert(bunq.drafts[main].begin(), json{{"DraftPayment", json{{"id", 990001}, {"status", "PENDING"}, {"entries", json::array({entry, entry})}}}});
|
||
|
|
bunq.drafts[main].insert(bunq.drafts[main].begin(), json{{"DraftPayment", json{{"id", 990002}, {"status", "CANCELLED"}, {"entries", json::array()}}}});
|
||
|
|
}
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "Bob and 1 more", "a draft of two payments");
|
||
|
|
Shows(d.ui, "€6.00", "sums them");
|
||
|
|
Shows(d.ui, "Cancelled", "and one of none is listed by its status alone");
|
||
|
|
Tap(d, "draft.990001");
|
||
|
|
Shows(d.ui, "A draft of €6.00", "and opens as their sum");
|
||
|
|
Check(Has(d, "copy.Bob") && Has(d, "copy.Bob.2"), "its two payments to one payee are two lines, each with a name of its own");
|
||
|
|
Tap(d, "copy.Bob.2");
|
||
|
|
Check(d.ui.Take().copy.value_or("").starts_with("€3.00"), "and each can be copied");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
Tap(d, "draft.990002");
|
||
|
|
Shows(d.ui, "A draft of €0.00", "as one of none opens as nothing");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
Press(d, "tabs.0");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
|
||
|
|
// An account nothing has happened on says so, list by list.
|
||
|
|
Press(d, std::format("account.{}", aliceSavings));
|
||
|
|
Shows(d.ui, "No payments yet", "an account without payments");
|
||
|
|
const std::array<std::string_view, 4> none = {"No requests sent from this account", "Nobody has asked this account for money", "No payments are scheduled from this account", "No draft payments wait for this account"};
|
||
|
|
for(std::size_t tab = 0; tab < none.size(); tab++) {
|
||
|
|
Tap(d, std::format("tabs.{}", tab + 1));
|
||
|
|
Check(Count(d, "No payments yet") == 0 && Has(d, "tabs.0"), "a list being read shows its place");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, none[tab], "an empty list says what it would hold");
|
||
|
|
}
|
||
|
|
Tap(d, "tabs.0");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
}
|
||
|
|
|
||
|
|
// The cards: frozen and unfrozen, one bunq keeps as it is, and reported lost or stolen, which is asked twice.
|
||
|
|
void Cards(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq, std::uint64_t alice) {
|
||
|
|
Tap(d, "nav.cards");
|
||
|
|
Check(d.app.Busy() && d.app.Screen() == "cards", "the cards are read when they are first looked at");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "No cards", "a user without cards");
|
||
|
|
const std::uint64_t card = bunq.AddCard(alice, "ACTIVE", json{{"label_monetary_account_current", json{{"iban", aliceMain}}}});
|
||
|
|
const std::uint64_t spare = bunq.AddCard(alice, "DEACTIVATED", json{{"primary_account_numbers", json::array({json{{"four_digit", "9876"}}})}, {"name_on_card", ""}, {"second_line", ""}, {"expiry_date", ""}, {"label_monetary_account_current", json{{"iban", strangerIban}}}});
|
||
|
|
// A virtual card, which the bank has as deactivated however well it pays.
|
||
|
|
const std::uint64_t number = bunq.AddCard(alice, "DEACTIVATED", json{{"order_status", "VIRTUAL_DELIVERY"}, {"primary_account_numbers", json::array({json{{"four_digit", "4321"}}})}});
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
for(const std::string_view said : {"Alice", "Mastercard debit •••• 1234", "J. Tester · until 11/30", "Active", "Mastercard debit •••• 9876", "Deactivated", "Mastercard debit •••• 4321", "Virtual"}) {
|
||
|
|
Shows(d.ui, said, "the cards are listed by connection");
|
||
|
|
}
|
||
|
|
Equal(Count(d, "Deactivated"), std::size_t{1}, "and a virtual card is not said to be deactivated, which the bank's word for it would have it");
|
||
|
|
const std::size_t readings = Answers(d, "Cards ok");
|
||
|
|
d.ui.KeyDown(Key::F5, {});
|
||
|
|
Settle(d);
|
||
|
|
Equal(Answers(d, "Cards ok"), readings + 1, "F5 reads the cards again");
|
||
|
|
Tap(d, std::format("card.{}", card));
|
||
|
|
Equal(d.app.Screen(), std::string("cards+card"), "a card opens");
|
||
|
|
for(const std::string_view said : {"Name on card", "J. Tester · Nostro", "Expires", "11/30", "Pays from"}) {
|
||
|
|
Shows(d.ui, said, "with what is on it");
|
||
|
|
}
|
||
|
|
Shows(d.ui, std::format("Main · {}", GroupIban(aliceMain)), "and the account it pays from, by name");
|
||
|
|
Equal(Line(d, "Status"), std::string("Active"), "its status as the bank reports it");
|
||
|
|
Equal(Line(d, "Order status"), std::string("Delivered to customer"), "and how far the bank is with the card itself");
|
||
|
|
Hides(d.ui, "Deactivated is what the bank reports", "with nothing to explain about a card that works");
|
||
|
|
Check(Has(d, "detail.freeze") && !Has(d, "detail.unfreeze") && Has(d, "detail.lost") && Has(d, "detail.stolen"), "a card in use can be frozen or reported");
|
||
|
|
Tap(d, "detail.freeze");
|
||
|
|
Shows(d.ui, "Freezing card •••• 1234", "freezing is under way at once");
|
||
|
|
Shows(d.ui, "One moment.", "without a password");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Card •••• 1234 is now Deactivated", "a frozen card is said");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionChange), "as a change");
|
||
|
|
Equal(d.app.Screen(), std::string("cards"), "over the list");
|
||
|
|
|
||
|
|
// A card that was never activated: bunq answers with the card as it is, which is not as it was asked to be.
|
||
|
|
{
|
||
|
|
std::lock_guard lock(bunq.mutex);
|
||
|
|
bunq.cardsActivate = false;
|
||
|
|
}
|
||
|
|
SetPolkit(bus, Fake::Polkit::Password, Bus::actionUnfreezeCard);
|
||
|
|
Tap(d, std::format("card.{}", spare));
|
||
|
|
Check(!Has(d, "detail.freeze") && Has(d, "detail.unfreeze"), "a frozen card can be unfrozen");
|
||
|
|
Shows(d.ui, "Deactivated is what the bank reports", "a card the bank has as deactivated says what the bank means by that: frozen, or never activated");
|
||
|
|
Shows(d.ui, GroupIban(strangerIban), "an account that is not the user's is said by its IBAN");
|
||
|
|
Hides(d.ui, "Name on card", "and what a card lacks is left out");
|
||
|
|
Tap(d, "detail.unfreeze");
|
||
|
|
Shows(d.ui, "Confirm it in your system's password dialog.", "unfreezing needs the password");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "That did not work", "a card bunq kept as it was is said");
|
||
|
|
Shows(d.ui, "Your bank kept card", "as the bank having kept it");
|
||
|
|
Shows(d.ui, "once it has been activated", "with why it may have");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionUnfreezeCard), "after the password for unfreezing");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
{
|
||
|
|
std::lock_guard lock(bunq.mutex);
|
||
|
|
bunq.cardsActivate = true;
|
||
|
|
}
|
||
|
|
Tap(d, std::format("card.{}", card));
|
||
|
|
Press(d, "detail.unfreeze");
|
||
|
|
Shows(d.ui, "Card •••• 1234 is now Active", "a card unfrozen is said");
|
||
|
|
|
||
|
|
// Lost or stolen blocks a card for good, and is asked twice.
|
||
|
|
SetPolkit(bus, Fake::Polkit::Password, Bus::actionBlockCard);
|
||
|
|
Tap(d, std::format("card.{}", card));
|
||
|
|
Tap(d, "detail.lost");
|
||
|
|
Equal(d.app.Screen(), std::string("cards+confirm"), "reporting a card is asked about");
|
||
|
|
Shows(d.ui, "Report card •••• 1234 lost?", "by what it does");
|
||
|
|
Tap(d, "confirm.no");
|
||
|
|
Equal(d.app.Screen(), std::string("cards"), "and can be thought better of");
|
||
|
|
Tap(d, std::format("card.{}", card));
|
||
|
|
Tap(d, "detail.lost");
|
||
|
|
Tap(d, "confirm.yes");
|
||
|
|
Equal(d.app.Screen(), std::string("cards+confirm.again"), "and asked about again");
|
||
|
|
Shows(d.ui, "Block card •••• 1234 for good?", "in other words");
|
||
|
|
Tap(d, "confirm.no");
|
||
|
|
Equal(d.app.Screen(), std::string("cards"), "and thought better of again");
|
||
|
|
Tap(d, std::format("card.{}", card));
|
||
|
|
Tap(d, "detail.lost");
|
||
|
|
Tap(d, "confirm.yes");
|
||
|
|
Press(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Card •••• 1234 is now Lost", "a card reported lost is said");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionBlockCard), "after the password for blocking");
|
||
|
|
Tap(d, std::format("card.{}", card));
|
||
|
|
Check(!Has(d, "detail.freeze") && !Has(d, "detail.unfreeze") && !Has(d, "detail.lost"), "a blocked card can be nothing else");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
Tap(d, std::format("card.{}", spare));
|
||
|
|
Tap(d, "detail.stolen");
|
||
|
|
Shows(d.ui, "Report card •••• 9876 stolen?", "a stolen card is reported the same way");
|
||
|
|
Tap(d, "confirm.yes");
|
||
|
|
Press(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Card •••• 9876 is now Stolen", "and said");
|
||
|
|
|
||
|
|
// A virtual card stands as that. The bank does not say whether one is frozen and leaves it as it is when asked
|
||
|
|
// to freeze or unfreeze it, so neither is offered; reporting it is, which the bank does do.
|
||
|
|
Tap(d, std::format("card.{}", number));
|
||
|
|
Shows(d.ui, "This is a virtual card.", "a virtual card says what it is");
|
||
|
|
Hides(d.ui, "Deactivated is what the bank reports", "and nothing about plastic");
|
||
|
|
Equal(Line(d, "Status"), std::string("Virtual"), "it stands as virtual, whatever the bank's word for it");
|
||
|
|
Check(!Has(d, "copy.Order status"), "with nothing more to say of how it was made");
|
||
|
|
Check(!Has(d, "detail.freeze") && !Has(d, "detail.unfreeze") && Has(d, "detail.lost") && Has(d, "detail.stolen"), "it can be reported, and not frozen or unfrozen");
|
||
|
|
const std::size_t changes = bunq.Count("PUT", "/user/");
|
||
|
|
Tap(d, "detail.lost");
|
||
|
|
Shows(d.ui, "Report card •••• 4321 lost?", "reporting it is asked about like any card's");
|
||
|
|
Tap(d, "confirm.yes");
|
||
|
|
Press(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Card •••• 4321 is now Lost", "and done");
|
||
|
|
Equal(bunq.Count("PUT", "/user/"), changes + 1, "by the one call to the bank");
|
||
|
|
Tap(d, std::format("card.{}", number));
|
||
|
|
Equal(Line(d, "Status"), std::string("Lost"), "after which it stands as the bank says: gone for good");
|
||
|
|
Hides(d.ui, "This is a virtual card.", "which is all there is to say of it");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
|
||
|
|
bunq.Fail(Fault{.method = "GET", .path = std::format("/user/{}/card", alice), .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "The bank refused", "cards the bank refused to list are said");
|
||
|
|
Press(d, "cards.problem.action");
|
||
|
|
Shows(d.ui, "Lost", "and can be tried again");
|
||
|
|
|
||
|
|
// A card with a name and nothing under it, frozen without a clear answer: it may have been.
|
||
|
|
const std::uint64_t plain = bunq.AddCard(alice, "ACTIVE", json{{"primary_account_numbers", json::array({json{{"four_digit", "5555"}}})}, {"name_on_card", "A. Other"}, {"second_line", ""}});
|
||
|
|
std::uint64_t last = 0;
|
||
|
|
for(std::int32_t i = 0; i < 12; i++) {
|
||
|
|
last = bunq.AddCard(alice, "ACTIVE", json{{"primary_account_numbers", json::array({json{{"four_digit", std::format("{:04}", 7000 + i)}}})}});
|
||
|
|
}
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Check(!Has(d, std::format("card.{}", last)), "of more cards than the window shows, those below it are not drawn");
|
||
|
|
Bottom(d);
|
||
|
|
Check(Has(d, std::format("card.{}", last)), "until they are scrolled to");
|
||
|
|
Top(d);
|
||
|
|
Tap(d, std::format("card.{}", plain));
|
||
|
|
Shows(d.ui, "A. Other", "a card with a name alone says the name");
|
||
|
|
bunq.Fail(Fault{.method = "PUT", .path = std::format("/user/{}/card", alice), .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||
|
|
Press(d, "detail.freeze");
|
||
|
|
Shows(d.ui, "It may have been done", "a card change without a clear answer may have been made");
|
||
|
|
Check(!Has(d, "problem.activity"), "which no account's activity would show");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
Tap(d, "nav.cards");
|
||
|
|
Check(!d.app.Busy(), "cards that are known are not read again by looking at them");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
}
|
||
|
|
|
||
|
|
// The settings: the account that pays at checkout, what the app is, and the connections, removed by name and,
|
||
|
|
// where two have one name, by number.
|
||
|
|
void Settings(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq) {
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
for(const std::string_view said : {"Bank connections", "2 connected", "Pay at checkout from", "No account chosen", "About and security", "Nostro 1.2.3"}) {
|
||
|
|
Shows(d.ui, said, "the settings are listed");
|
||
|
|
}
|
||
|
|
Tap(d, "settings.about");
|
||
|
|
Equal(d.app.Screen(), std::string("about"), "what the app is has a page");
|
||
|
|
Shows(d.ui, "Nostro is a banking client for Linux", "which says so");
|
||
|
|
Shows(d.ui, "Nostro 1.2.3", "with its version");
|
||
|
|
Shows(d.ui, "GPL-3.0-only", "and its licence");
|
||
|
|
Hides(d.ui, "LGPL", "which is the app's own, not the library's");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
|
||
|
|
Tap(d, "settings.checkout");
|
||
|
|
Equal(d.app.Screen(), std::string("checkout"), "the account that pays at checkout has a page");
|
||
|
|
Shows(d.ui, "Play money", "which lists the accounts");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Password, Bus::actionConnectors);
|
||
|
|
Tap(d, std::format("checkout.{}", aliceMain));
|
||
|
|
Shows(d.ui, "Letting apps ask you to pay from Main", "choosing one is under way");
|
||
|
|
Shows(d.ui, "Confirm it in your system's password dialog.", "and needs the password");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Apps now ask you to pay from Main", "the choice is said");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionConnectors), "after the password for changing connections");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Shows(d.ui, std::format("Main · {}", GroupIban(aliceMain)), "and shown in the settings");
|
||
|
|
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
Equal(d.app.Screen(), std::string("connections"), "the connections have a page");
|
||
|
|
for(const std::string_view said : {"bunq · Production · API key", "bunq · Sandbox · API key", "Working"}) {
|
||
|
|
Shows(d.ui, said, "which lists them");
|
||
|
|
}
|
||
|
|
const std::string dave = std::format("connection.Dave.{}", daveIban);
|
||
|
|
Tap(d, dave);
|
||
|
|
Equal(d.app.Screen(), std::string("connections+connection"), "a connection opens");
|
||
|
|
for(const std::string_view said : {"Bank", "Environment", "Sandbox", "Connected with", "Accounts", "Working"}) {
|
||
|
|
Shows(d.ui, said, "with what it is");
|
||
|
|
}
|
||
|
|
Equal(Line(d, "Bank"), std::string("bunq"), "its bank by the bank's own name");
|
||
|
|
Equal(Line(d, "Connected with"), std::string("API key"), "and the way it was connected");
|
||
|
|
Check(!Has(d, "copy.Pays"), "with nothing about what it can pay, which is anyone");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
Equal(d.app.Screen(), std::string("connections"), "and closes");
|
||
|
|
Tap(d, dave);
|
||
|
|
Tap(d, "detail.remove");
|
||
|
|
Shows(d.ui, "Remove Dave?", "removing it is asked about first");
|
||
|
|
Shows(d.ui, "The API key itself stays valid", "with what stays valid at its bank, by the way it was connected");
|
||
|
|
Tap(d, "confirm.no");
|
||
|
|
Equal(d.app.Screen(), std::string("connections"), "and can be thought better of");
|
||
|
|
Tap(d, dave);
|
||
|
|
Tap(d, "detail.remove");
|
||
|
|
Tap(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Removing Dave", "removing is under way");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Removed Dave", "a connection removed is said");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionConnectors), "after the password for changing connections");
|
||
|
|
Check(!Has(d, dave), "and no longer listed");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Shows(d.ui, "1 connected", "one is left");
|
||
|
|
Shows(d.ui, "Pay at checkout from", "and the checkout's account is read again");
|
||
|
|
|
||
|
|
// Two connections of one name: the one to remove is told apart by its accounts, and removed by its number.
|
||
|
|
Client other = Client::System();
|
||
|
|
other.AddBunq("key-alice-two", "*", "");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "Other", "a second Alice is connected");
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
const std::string second = std::format("connection.Alice.{}", otherAliceIban);
|
||
|
|
const std::string first = Row(d, "connection.Alice.") == second ? Row(d, "connection.Alice.", 1) : Row(d, "connection.Alice.");
|
||
|
|
Check(Has(d, second) && Has(d, first) && first != second, "each has a row of its own");
|
||
|
|
// The list cannot be read: nothing is removed.
|
||
|
|
Tap(d, second);
|
||
|
|
Tap(d, "detail.remove");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Deny, Bus::actionView);
|
||
|
|
Press(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Not allowed", "a list that cannot be read is said");
|
||
|
|
Equal(d.app.Screen(), std::string("connections+problem"), "and removing stops there");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Allow, Bus::actionView);
|
||
|
|
// It went meanwhile: which one is meant is no longer clear.
|
||
|
|
other.RemoveConnector("2");
|
||
|
|
Tap(d, second);
|
||
|
|
Tap(d, "detail.remove");
|
||
|
|
Press(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "The connections changed", "a connection that went meanwhile is not guessed at");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
Check(!Has(d, second), "and the list is read again");
|
||
|
|
other.AddBunq("key-alice-two", "*", "");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
Tap(d, second);
|
||
|
|
Tap(d, "detail.remove");
|
||
|
|
Press(d, "confirm.yes");
|
||
|
|
Shows(d.ui, "Removed Alice", "the second of two is removed");
|
||
|
|
Check(!Has(d, second) && Has(d, first), "and the first is still there");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
|
||
|
|
// A connection the bank does not answer for says so on its own sheet.
|
||
|
|
bunq.Fail(Fault{.method = "GET", .path = "/user/", .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
Shows(d.ui, "Not working", "a connection that does not work is listed as such");
|
||
|
|
Tap(d, first);
|
||
|
|
Shows(d.ui, "Failing: the bank did not", "and says so when it is opened");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
}
|
||
|
|
|
||
|
|
// A connection through OAuth, and what bunq lets such a connection do.
|
||
|
|
void OAuth(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq) {
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
Adding(d, "oauth");
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq:oauth"), "OAuth has a form of its own");
|
||
|
|
Bottom(d);
|
||
|
|
Tap(d, "oauth.continue");
|
||
|
|
Top(d);
|
||
|
|
for(const std::string_view said : {"The client id bunq gave the OAuth client", "registered with the client", "The client's secret"}) {
|
||
|
|
Shows(d.ui, said, "an empty form says what it lacks");
|
||
|
|
}
|
||
|
|
Type(d, "oauth.client", "someone-else");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "way.oauth");
|
||
|
|
Hides(d.ui, "someone-else", "a form that was left is forgotten");
|
||
|
|
Type(d, "oauth.client", "fake-client");
|
||
|
|
Type(d, "oauth.redirect", "http://127.0.0.1/cb");
|
||
|
|
Type(d, "oauth.secret", "fake-secret");
|
||
|
|
Shows(d.ui, "Typed: ••••", "the secret is told by nothing of itself");
|
||
|
|
Hides(d.ui, "fake-secret", "and never shown");
|
||
|
|
Bottom(d);
|
||
|
|
Tap(d, "oauth.environment.1");
|
||
|
|
Tap(d, "oauth.continue");
|
||
|
|
Check(d.app.OAuthState() == "state-1" && Has(d, "oauth.redirected"), "a form filled in leads to the address to approve at");
|
||
|
|
Tap(d, "oauth.open");
|
||
|
|
Check(d.opened.back().starts_with("https://oauth.sandbox.bunq.com/auth?") && d.opened.back().ends_with("state=state-1"), "which is the sandbox's when that was chosen");
|
||
|
|
// A code bunq does not know: nostrod's trade for a token is refused, and nothing is connected.
|
||
|
|
Type(d, "oauth.redirected", "http://127.0.0.1/cb?code=not-a-code&state=state-1");
|
||
|
|
Bottom(d);
|
||
|
|
Press(d, "oauth.connect");
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq:oauth+problem"), "a code bunq refuses connects nothing");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
Bottom(d);
|
||
|
|
Tap(d, "oauth.restart");
|
||
|
|
Check(Has(d, "oauth.client") && !Has(d, "oauth.redirected"), "starting over shows the form again");
|
||
|
|
Shows(d.ui, "fake-client", "as it was filled in");
|
||
|
|
Bottom(d);
|
||
|
|
Tap(d, "oauth.environment.0");
|
||
|
|
Tap(d, "oauth.continue");
|
||
|
|
Shows(d.ui, "Open this address and approve the connection", "what to do with the address is said");
|
||
|
|
Tap(d, "oauth.open");
|
||
|
|
Check(d.opened.back().starts_with("https://oauth.bunq.com/auth?"), "the address is opened in the browser");
|
||
|
|
d.opens = false;
|
||
|
|
Tap(d, "oauth.open");
|
||
|
|
Shows(d.ui, "No browser could be opened", "or said not to have been");
|
||
|
|
d.opens = true;
|
||
|
|
Tap(d, "oauth.copy");
|
||
|
|
Check(d.ui.Take().copy == std::optional<std::string>(d.opened.back()), "or copied");
|
||
|
|
Shows(d.ui, "Address copied", "which is said");
|
||
|
|
Bottom(d);
|
||
|
|
Tap(d, "oauth.connect");
|
||
|
|
Shows(d.ui, "that address has no code= in it", "an address without a code is refused");
|
||
|
|
Type(d, "oauth.redirected", "http://127.0.0.1/cb?error=access_denied&error_description=Nope");
|
||
|
|
Bottom(d);
|
||
|
|
Tap(d, "oauth.connect");
|
||
|
|
Shows(d.ui, "bunq did not authorize", "bunq's refusal is said");
|
||
|
|
Retype(d, "oauth.redirected", "http://127.0.0.1/cb?code=code-carol&state=someone-elses");
|
||
|
|
Bottom(d);
|
||
|
|
Tap(d, "oauth.connect");
|
||
|
|
Shows(d.ui, "state differs): start again", "an answer to another request is refused");
|
||
|
|
Retype(d, "oauth.redirected", "http://127.0.0.1/cb?code=code-carol&state=state-1");
|
||
|
|
d.ui.KeyDown(Key::Enter, {});
|
||
|
|
Build(d);
|
||
|
|
Shows(d.ui, "Connecting to bunq", "the right address connects, by Enter too");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Connected Carol", "a connection through OAuth is made");
|
||
|
|
Equal(Line(d, "Connected with"), std::string("OAuth"), "and said to be");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionConnectors), "after the password for changing connections");
|
||
|
|
Press(d, "done.close");
|
||
|
|
Shows(d.ui, "Limited", "and marked in the list of accounts for what it cannot do, not for how it was made");
|
||
|
|
Shows(d.ui, "Shared", "with its account");
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
Shows(d.ui, "bunq · Production · OAuth", "the settings list it with its bank and its way");
|
||
|
|
Tap(d, std::format("connection.Carol.{}", carolIban));
|
||
|
|
Equal(Line(d, "Connected with"), std::string("OAuth"), "its sheet says how it is connected");
|
||
|
|
Equal(Line(d, "Pays"), std::string("Your own accounts only"), "and what that lets it pay");
|
||
|
|
Tap(d, "detail.remove");
|
||
|
|
Shows(d.ui, "The permission itself stays valid", "and removing it what stays valid at its bank");
|
||
|
|
Tap(d, "confirm.no");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
|
||
|
|
// bunq lets it pay the user's own accounts only: a payment to anyone else can only be a draft.
|
||
|
|
const std::string page = std::format("account:{}", carolIban);
|
||
|
|
Press(d, std::format("account.{}", carolIban));
|
||
|
|
Shows(d.ui, "This account's connection pays between", "the account says what its connection can pay");
|
||
|
|
Tap(d, "account.pay");
|
||
|
|
Shows(d.ui, "A payment to anyone else", "the form says what becomes of a payment to anyone else");
|
||
|
|
Check(!d.ui.Find("pay.when.0")->enabled, "and offers no other way to pay");
|
||
|
|
Type(d, "pay.to", bobIban);
|
||
|
|
Type(d, "pay.name", "Bob");
|
||
|
|
Type(d, "pay.amount", "1");
|
||
|
|
Bottom(d);
|
||
|
|
Equal(d.ui.Find("pay.submit")->label, std::string("Save as draft"), "its button says that a payment to someone else is saved as a draft");
|
||
|
|
Press(d, "pay.submit");
|
||
|
|
Shows(d.ui, "Drafted €1.00 to Bob", "and it is made as one");
|
||
|
|
Equal(Action(bus), std::string(Bus::actionChange), "as a change that moves no money");
|
||
|
|
Press(d, "done.close");
|
||
|
|
// To one of the user's own it may pay, and when bunq refuses all the same a draft is offered.
|
||
|
|
Tap(d, "account.pay");
|
||
|
|
Type(d, "pay.to", aliceMain);
|
||
|
|
Type(d, "pay.name", "Alice");
|
||
|
|
Type(d, "pay.amount", "1");
|
||
|
|
Check(d.ui.Find("pay.when.0")->enabled, "a payment to an account of the user's own may be made at once");
|
||
|
|
Hides(d.ui, "A payment to anyone else", "and nothing is said against it");
|
||
|
|
Bottom(d);
|
||
|
|
Equal(d.ui.Find("pay.submit")->label, std::string("Pay"), "and its button pays");
|
||
|
|
bunq.Fail(Fault{.method = "POST", .path = "/user/", .status = 403, .body = R"({"Error":[{"error_description":"Not allowed for this user."}]})"});
|
||
|
|
Press(d, "pay.submit");
|
||
|
|
Shows(d.ui, "This connection cannot pay others", "bunq's refusal of it is said for what it is");
|
||
|
|
Check(Has(d, "problem.draft"), "and a draft is offered");
|
||
|
|
Press(d, "problem.draft");
|
||
|
|
Shows(d.ui, "Drafted €1.00 to Alice", "which a press saves, of what the form still holds");
|
||
|
|
Press(d, "done.close");
|
||
|
|
Equal(d.app.Screen(), page, "which leads back to the account");
|
||
|
|
|
||
|
|
// A request it received cannot be paid from here either.
|
||
|
|
Client other = Client::System();
|
||
|
|
other.Request(aliceMain, carolIban, "Carol", 300, "share");
|
||
|
|
Press(d, "tabs.2");
|
||
|
|
Tap(d, Row(d, "incoming."));
|
||
|
|
Check(Has(d, "detail.pay") && !d.ui.Find("detail.pay")->enabled && d.ui.Find("detail.reject")->enabled, "a request to an account through OAuth can be rejected, not paid");
|
||
|
|
Shows(d.ui, "A request cannot be paid from here", "and why is said");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
Press(d, "tabs.0");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
Tap(d, "settings.checkout");
|
||
|
|
Check(!d.ui.Find(std::format("checkout.{}", carolIban))->enabled && d.ui.Find(std::format("checkout.{}", aliceMain))->enabled, "nor can it pay at a checkout");
|
||
|
|
Shows(d.ui, "Pays your own accounts only", "which is said");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
}
|
||
|
|
|
||
|
|
// An account that goes while the app is looking at it: nostrod no longer knows it, and the app looks again.
|
||
|
|
void Vanishing(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq) {
|
||
|
|
Client other = Client::System();
|
||
|
|
other.AddBunq(daveKey, "*", "");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
const std::string page = std::format("account:{}", daveIban);
|
||
|
|
Press(d, std::format("account.{}", daveIban));
|
||
|
|
Tap(d, "account.request");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "filter");
|
||
|
|
Equal(d.app.Screen(), std::format("{}+filter", page), "the filter is open over the account");
|
||
|
|
TapBeside(d);
|
||
|
|
|
||
|
|
// A payment from it that leaves open whether it was made, and the account gone before its activity is looked
|
||
|
|
// at: the way there leads nowhere.
|
||
|
|
Tap(d, "account.pay");
|
||
|
|
Type(d, "pay.to", bobIban);
|
||
|
|
Type(d, "pay.name", "Bob");
|
||
|
|
Type(d, "pay.amount", "1");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Password, Bus::actionPay);
|
||
|
|
bunq.Fail(Fault{.method = "POST", .path = "/user/", .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||
|
|
Press(d, "pay.submit");
|
||
|
|
Shows(d.ui, "It may have been paid", "a payment without a clear answer");
|
||
|
|
Tap(d, "problem.close");
|
||
|
|
Hides(d.ui, bobIban, "is not left in its form to be sent again");
|
||
|
|
Type(d, "pay.to", bobIban);
|
||
|
|
Type(d, "pay.name", "Bob");
|
||
|
|
Type(d, "pay.amount", "1");
|
||
|
|
bunq.Fail(Fault{.method = "POST", .path = "/user/", .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||
|
|
Press(d, "pay.submit");
|
||
|
|
other.RemoveConnector("Dave");
|
||
|
|
d.app.Start();
|
||
|
|
Settle(d);
|
||
|
|
Tap(d, "problem.activity");
|
||
|
|
Equal(d.app.Screen(), std::string("accounts"), "the activity of an account that went is not gone to");
|
||
|
|
Hides(d.ui, "Play money", "and the account is no longer listed");
|
||
|
|
|
||
|
|
// Paying from an account that went: nostrod refuses, the app reads the connections again, and the form has
|
||
|
|
// no account until one is chosen.
|
||
|
|
other.AddBunq(daveKey, "*", "");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Press(d, std::format("account.{}", daveIban));
|
||
|
|
Tap(d, "account.pay");
|
||
|
|
Type(d, "pay.to", bobIban);
|
||
|
|
Type(d, "pay.name", "Bob");
|
||
|
|
Type(d, "pay.amount", "1");
|
||
|
|
other.RemoveConnector("Dave");
|
||
|
|
Press(d, "pay.submit");
|
||
|
|
Shows(d.ui, "That cannot be done", "a payment from an account that went is refused");
|
||
|
|
Shows(d.ui, "Nothing was sent.", "with nothing sent");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
Equal(d.app.Screen(), std::string("pay"), "the form is still there");
|
||
|
|
Shows(d.ui, "Choose an account", "without an account to pay from");
|
||
|
|
Check(!d.ui.Find("pay.submit")->enabled, "and cannot be sent");
|
||
|
|
Tap(d, "pay.from");
|
||
|
|
Tap(d, std::format("pick.{}", aliceMain));
|
||
|
|
Check(d.ui.Find("pay.submit")->enabled, "until one is chosen");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Equal(d.app.Screen(), std::string("accounts"), "and the page of the account that went is not gone back to");
|
||
|
|
|
||
|
|
// Looking at an account that went: its list says why not, and the app is back at the accounts.
|
||
|
|
other.AddBunq(daveKey, "*", "");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Press(d, std::format("account.{}", daveIban));
|
||
|
|
other.RemoveConnector("Dave");
|
||
|
|
const std::size_t failed = Answers(d, "Transactions failed");
|
||
|
|
Tap(d, "bar.refresh");
|
||
|
|
Check(RunUntil(d.loop, [&d, failed] { return Answers(d, "Transactions failed") > failed; }), "its payments cannot be read");
|
||
|
|
Build(d);
|
||
|
|
Shows(d.ui, "That cannot be done", "which is said");
|
||
|
|
Check(!Has(d, "activity.problem.action"), "with nothing to try again");
|
||
|
|
Settle(d);
|
||
|
|
Equal(d.app.Screen(), std::string("accounts"), "and the app is back at the accounts, without it");
|
||
|
|
}
|
||
|
|
|
||
|
|
// nostrod not answering in time: a reading is only late, a payment may have been made.
|
||
|
|
void Late(Fake::Bus& bus, sd_event* loop) {
|
||
|
|
Driver d(bus, loop);
|
||
|
|
d.timeout = std::chrono::seconds(1);
|
||
|
|
SetPolkit(bus, Fake::Polkit::Silent, Bus::actionView);
|
||
|
|
d.app.Start();
|
||
|
|
Build(d);
|
||
|
|
Check(d.app.Busy() && !Has(d, "overview.action"), "the first screen waits");
|
||
|
|
Check(d.app.Navigate("connections"), "the connections' page");
|
||
|
|
Build(d);
|
||
|
|
Check(d.app.Busy() && !Has(d, "overview.action"), "which waits too");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "No answer yet", "a reading that got no answer in time is said to be late");
|
||
|
|
Check(Has(d, "overview.action"), "there as on the first screen");
|
||
|
|
Press(d, "overview.action");
|
||
|
|
Shows(d.ui, "No answer yet", "and tried again from there, to the same end");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
Shows(d.ui, "No answer yet", "where it is said too");
|
||
|
|
// The settings while the account that pays at checkout cannot be read.
|
||
|
|
SetPolkit(bus, Fake::Polkit::Deny, Bus::actionView);
|
||
|
|
Check(d.app.Navigate("settings"), "the settings");
|
||
|
|
Build(d);
|
||
|
|
Shows(d.ui, "…", "what is being read is waited for");
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Not allowed", "and what could not be read is said in its place");
|
||
|
|
Press(d, "settings.checkout");
|
||
|
|
Shows(d.ui, "Not allowed", "and on its own page");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Allow, Bus::actionView);
|
||
|
|
Press(d, "checkout.problem.action");
|
||
|
|
Hides(d.ui, "Not allowed", "where it can be tried again");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
Press(d, "overview.action");
|
||
|
|
Shows(d.ui, "Main", "as the accounts can");
|
||
|
|
|
||
|
|
SetPolkit(bus, Fake::Polkit::Silent, Bus::actionPay);
|
||
|
|
Tap(d, "home.pay");
|
||
|
|
Type(d, "pay.to", bobIban);
|
||
|
|
Type(d, "pay.name", "Bob");
|
||
|
|
Type(d, "pay.amount", "1");
|
||
|
|
Press(d, "pay.submit");
|
||
|
|
Shows(d.ui, "It may have been paid", "a payment that got no answer in time may have been made");
|
||
|
|
Check(Has(d, "problem.activity"), "and its account's activity is offered");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Password, Bus::actionPay);
|
||
|
|
}
|
||
|
|
|
||
|
|
// The connection to the system bus breaks: what it carried fails, and the next thing asked connects again.
|
||
|
|
void Reconnecting(Fake::Bus& bus, sd_event* loop) {
|
||
|
|
Driver d(bus, loop);
|
||
|
|
d.app.Start();
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Main", "the accounts are read");
|
||
|
|
const std::int32_t connects = d.connects;
|
||
|
|
SetPolkit(bus, Fake::Polkit::Slow, Bus::actionView);
|
||
|
|
Tap(d, "bar.refresh");
|
||
|
|
Tap(d, "nav.cards");
|
||
|
|
const auto failures = [&d] { return std::ranges::count_if(d.answers, [](const std::string& answer) { return answer.ends_with("failed"); }); };
|
||
|
|
Equal(failures(), std::ptrdiff_t{0}, "two readings are under way");
|
||
|
|
bus.DisconnectOwn();
|
||
|
|
Check(RunUntil(d.loop, [&failures] { return failures() == 1; }), "the first of them fails with the connection");
|
||
|
|
Check(d.app.Busy(), "the second is still to fail");
|
||
|
|
// Asked for while the old connection's answers are still coming in: it fails like them.
|
||
|
|
Check(d.app.Navigate("settings"), "the settings");
|
||
|
|
Build(d);
|
||
|
|
Shows(d.ui, "That did not work", "what is asked meanwhile fails too");
|
||
|
|
Settle(d);
|
||
|
|
Equal(failures(), std::ptrdiff_t{2}, "and so does the second reading");
|
||
|
|
Equal(d.connects, connects, "no new connection was made yet");
|
||
|
|
SetPolkit(bus, Fake::Polkit::Allow, Bus::actionView);
|
||
|
|
Check(d.app.Navigate("accounts"), "the accounts");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Equal(d.connects, connects + 1, "the next thing asked connects again");
|
||
|
|
Shows(d.ui, "Main", "and is answered");
|
||
|
|
}
|
||
|
|
|
||
|
|
// The app given nothing but a connection: the system's clock, no desktop to open addresses, and no version.
|
||
|
|
void Bare(Fake::Bus& bus, sd_event* loop) {
|
||
|
|
Driver d(bus, loop, true);
|
||
|
|
d.app.Start();
|
||
|
|
Settle(d);
|
||
|
|
Shows(d.ui, "Main", "it lists the accounts all the same");
|
||
|
|
Tap(d, "home.request");
|
||
|
|
Equal(d.app.Screen(), std::string("request"), "asking from the start");
|
||
|
|
Shows(d.ui, "Into", "asks into the first account");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Press(d, std::format("account.{}", aliceMain));
|
||
|
|
Hides(d.ui, "Today", "payments of October 2026 are not today's by the system's clock");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
Check(Count(d, "Nostro") == 1 && Count(d, "Nostro 1") == 0, "the settings name the app without a version");
|
||
|
|
Tap(d, "settings.about");
|
||
|
|
Shows(d.ui, "Nostro, © 2026 Catcrafts.", "and so does what it says of itself");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
Adding(d, "oauth");
|
||
|
|
Type(d, "oauth.client", "fake-client");
|
||
|
|
Type(d, "oauth.redirect", "http://127.0.0.1/cb");
|
||
|
|
Type(d, "oauth.secret", "fake-secret");
|
||
|
|
Bottom(d);
|
||
|
|
Tap(d, "oauth.continue");
|
||
|
|
const std::string_view state = d.app.OAuthState();
|
||
|
|
Check(state.size() == 32 && std::ranges::all_of(state, [](char c) { return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'); }), "an OAuth request gets a state nobody can guess");
|
||
|
|
Check(Has(d, "oauth.open") && !d.ui.Find("oauth.open")->enabled && d.ui.Find("oauth.copy")->enabled, "and an address that can be copied where it cannot be opened");
|
||
|
|
}
|
||
|
|
|
||
|
|
// nostrod gone, and then the bus: a change says so, and nothing is sent.
|
||
|
|
void Gone(Driver& d, Fake::Bus& bus, pid_t nostrod) {
|
||
|
|
bus.Disconnect(busName);
|
||
|
|
Equal(Fake::Wait(nostrod), 0, "nostrod ends when the bus lets go of it");
|
||
|
|
Press(d, "bar.refresh");
|
||
|
|
Shows(d.ui, "The accounts could not be read again.", "accounts that cannot be read again are said");
|
||
|
|
Shows(d.ui, "Nostro's service is not running.", "with why, in a line");
|
||
|
|
Shows(d.ui, "Main", "and stay as they were known");
|
||
|
|
Press(d, "notes.dismiss");
|
||
|
|
Tap(d, "home.pay");
|
||
|
|
Type(d, "pay.to", bobIban);
|
||
|
|
Type(d, "pay.name", "Bob");
|
||
|
|
Type(d, "pay.amount", "1");
|
||
|
|
Press(d, "pay.submit");
|
||
|
|
Shows(d.ui, "Nostro's service is not running", "a payment without nostrod is not made, and says why");
|
||
|
|
Press(d, "problem.close");
|
||
|
|
Shows(d.ui, bobIban, "its form is still as it was filled in");
|
||
|
|
d.noBus = true;
|
||
|
|
bus.DisconnectOwn();
|
||
|
|
RunUntil(d.loop, [] { return false; }, std::chrono::seconds(1));
|
||
|
|
Press(d, "pay.submit");
|
||
|
|
Shows(d.ui, "The system bus cannot be reached", "nor is one without a system bus");
|
||
|
|
Shows(d.ui, "Connection refused", "which is said");
|
||
|
|
Check(!d.app.Changing(), "and is not under way");
|
||
|
|
}
|
||
|
|
|
||
|
|
// A wider window: the places, and where there is room the accounts themselves, down its side.
|
||
|
|
void Sizes(Driver& d) {
|
||
|
|
d.size = {0, 0, 1280, 800};
|
||
|
|
Build(d);
|
||
|
|
Check(Has(d, "side") && !Has(d, "nav") && Has(d, "nav.accounts") && Has(d, std::format("side.{}", aliceSavings)), "a wide window lists the places and the accounts down its side");
|
||
|
|
Press(d, std::format("side.{}", aliceSavings));
|
||
|
|
Equal(d.app.Screen(), std::format("account:{}", aliceSavings), "an account there leads to its page");
|
||
|
|
Check(Has(d, "side") && Has(d, "bar.back"), "beside which the list stays");
|
||
|
|
Press(d, std::format("side.{}", aliceMain));
|
||
|
|
Equal(d.app.Screen(), std::format("account:{}", aliceMain), "and another account is a press away");
|
||
|
|
Press(d, "nav.cards");
|
||
|
|
Equal(d.app.Screen(), std::string("cards"), "as is another place");
|
||
|
|
Tap(d, Row(d, "card."));
|
||
|
|
const Region* panel = d.ui.Find("dialog.panel");
|
||
|
|
Check(panel != nullptr && panel->box.w == 480 && panel->box.x == 400, "what is asked over a wide window is a dialog in its middle");
|
||
|
|
Tap(d, "detail.close");
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
Tap(d, "settings.about");
|
||
|
|
Check(Has(d, "side") && Has(d, "bar.back") && d.app.Screen() == "about", "a page of the settings has the places beside it too");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
// With the places beside it a form can be left sideways: a key typed into it goes with it all the same.
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
Adding(d, "key");
|
||
|
|
Type(d, "key.key", aliceKey);
|
||
|
|
Shows(d.ui, "Typed:", "a key is typed into its form");
|
||
|
|
Press(d, "nav.cards");
|
||
|
|
Tap(d, "nav.settings");
|
||
|
|
Tap(d, "settings.connections");
|
||
|
|
Adding(d, "key");
|
||
|
|
Equal(d.app.Screen(), std::string("add:bunq:key"), "the form, gone back to");
|
||
|
|
Hides(d.ui, "Typed:", "has not kept the key that was typed before it was left");
|
||
|
|
Tap(d, "nav.accounts");
|
||
|
|
d.size = {0, 0, 700, 800};
|
||
|
|
Build(d);
|
||
|
|
Check(Has(d, "side") && Has(d, "nav.settings") && !Has(d, std::format("side.{}", aliceSavings)), "a window in between lists the places alone");
|
||
|
|
d.size = {0, 0, 400, 800};
|
||
|
|
Build(d);
|
||
|
|
Check(!Has(d, "side") && Has(d, "nav"), "and a narrow one has them along its bottom");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Places by name, for a command line and a debugger.
|
||
|
|
void Routes(Driver& d) {
|
||
|
|
for(const std::string_view place : {"cards", "settings", "accounts"}) {
|
||
|
|
Check(d.app.Navigate(place) && d.app.Screen() == place, std::format("{} is a place", place));
|
||
|
|
}
|
||
|
|
for(const std::string_view page : {"connections", "add", "add:bunq", "add:bunq:key", "add:bunq:oauth", "checkout", "about"}) {
|
||
|
|
Check(d.app.Navigate(page) && d.app.Screen() == page, std::format("{} is a page", page));
|
||
|
|
Settle(d);
|
||
|
|
Check(Has(d, "bar.back"), "with a way back");
|
||
|
|
Tap(d, "bar.back");
|
||
|
|
Equal(d.app.Screen(), std::string("settings"), "which leads to the settings");
|
||
|
|
}
|
||
|
|
for(const std::string_view nowhere : {"add:", "add:thrift", "add:thrift:key", "add:bunq:", "add:bunq:handshake", "add-key", "adding"}) {
|
||
|
|
Check(!d.app.Navigate(nowhere) && d.app.Screen() == "settings", std::format("{} is no step of adding a connection", nowhere));
|
||
|
|
}
|
||
|
|
const std::string account = std::format("account:{}", aliceMain);
|
||
|
|
Check(d.app.Navigate(account) && d.app.Screen() == account, "an account by its IBAN");
|
||
|
|
Settle(d);
|
||
|
|
Check(!d.app.Navigate("account:NL00NOPE") && !d.app.Navigate("nowhere") && d.app.Screen() == account, "and nothing else");
|
||
|
|
Check(d.app.Navigate("accounts"), "back to the start");
|
||
|
|
Settle(d);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(int argc, char* argv[]) {
|
||
|
|
// nostrod, and each of its workers, is this executable again.
|
||
|
|
if(Fake::IsNostrod()) {
|
||
|
|
Fake::Bunq::RedirectFromEnvironment();
|
||
|
|
return NostrodMain(argc, argv);
|
||
|
|
}
|
||
|
|
|
||
|
|
const Test::Directory directory("app");
|
||
|
|
const fs::path state = directory.path / "state";
|
||
|
|
// What nostrod reads from the environment is set before any thread starts, and so is the time zone the app words
|
||
|
|
// its days in.
|
||
|
|
setenv("TZ", "Europe/Amsterdam", 1);
|
||
|
|
tzset();
|
||
|
|
setenv("XDG_DATA_HOME", (directory.path / "data").c_str(), 1);
|
||
|
|
Fake::Bunq::ExportRedirect(port, directory.path / "bunq.pem");
|
||
|
|
setenv("DBUS_SYSTEM_BUS_ADDRESS", Fake::Bus::Address(directory.path / "bus").c_str(), 1);
|
||
|
|
Fake::Bus bus(directory.path / "bus");
|
||
|
|
{
|
||
|
|
std::lock_guard lock(bus.mutex);
|
||
|
|
bus.clientUid = uid;
|
||
|
|
bus.logindNames = {{uid, "alice"}};
|
||
|
|
}
|
||
|
|
|
||
|
|
Fake::Bunq bunq(port);
|
||
|
|
const std::uint64_t alice = bunq.AddPerson("Alice", aliceKey);
|
||
|
|
const std::uint64_t main = bunq.AddAccount(alice, aliceMain, "Main", 100000);
|
||
|
|
bunq.AddAccount(alice, aliceSavings, "Savings", 250000, "MonetaryAccountSavings");
|
||
|
|
bunq.AddAccount(bunq.AddPerson("Bob", "key-bob"), bobIban, "Bob's", 0);
|
||
|
|
const std::uint64_t carol = bunq.AddPerson("Carol", "key-carol");
|
||
|
|
bunq.AddAccount(carol, carolIban, "Shared", 500);
|
||
|
|
bunq.AddGrant(carol, "code-carol", "token-carol");
|
||
|
|
const std::uint64_t dave = bunq.AddPerson("Dave", daveKey);
|
||
|
|
bunq.AddAccount(dave, daveIban, "Play money", 12345);
|
||
|
|
bunq.AddAccount(bunq.AddPerson("Alice", "key-alice-two"), otherAliceIban, "Other", 100);
|
||
|
|
bunq.AddPerson("Eve", "key-eve");
|
||
|
|
|
||
|
|
sd_event* loop = nullptr;
|
||
|
|
sd_event_new(&loop);
|
||
|
|
pid_t nostrod = -1;
|
||
|
|
{
|
||
|
|
Driver d(bus, loop);
|
||
|
|
Starting(d, nostrod, state);
|
||
|
|
Connecting(d, bus);
|
||
|
|
Overview(d, bus, bunq, alice, nostrod);
|
||
|
|
Activity(d, bunq, alice, main);
|
||
|
|
Paying(d, bus, bunq);
|
||
|
|
Requesting(d, bus, bunq);
|
||
|
|
Lists(d, bus, bunq, alice, main);
|
||
|
|
Cards(d, bus, bunq, alice);
|
||
|
|
Settings(d, bus, bunq);
|
||
|
|
OAuth(d, bus, bunq);
|
||
|
|
Vanishing(d, bus, bunq);
|
||
|
|
Sizes(d);
|
||
|
|
Routes(d);
|
||
|
|
Late(bus, loop);
|
||
|
|
Bare(bus, loop);
|
||
|
|
Reconnecting(bus, loop);
|
||
|
|
Gone(d, bus, nostrod);
|
||
|
|
}
|
||
|
|
sd_event_unref(loop);
|
||
|
|
return Test::Result();
|
||
|
|
}
|