# Fortune Tester

<video src="./demo.mp4" controls></video>

This is a tiny powershell script that i use to test the backend quickly.
It probably would be better have unit and integration tests on the backend directly
but alas, there is never any time to do something like this.

You will need for fzf (use scoop / choco) and PSFzf

## ⚙️ Requirements

You’ll need:

* **PowerShell** (obviously)
* **fzf** (for interactive selection)

  * Install via `scoop install fzf` or `choco install fzf`
* **PSFzf** (PowerShell integration for fzf)

---

## 🚀 Getting Started

Load the CLI helpers:

```powershell
. ./fortune.ps1
```

Then launch the interactive test menu:

```powershell
. ./fortune_tests.ps1
```

This will open an `fzf` selector listing all available test functions.

---

## 🧠 How It Works

* Every function inside `fortune_tests.ps1` is automatically registered
* The `Main` function scans and feeds them into `fzf`
* You select a function → provide params → it runs

---

## 🔐 Authentication Helpers

These functions log you in and store tokens globally for reuse:

* `LoginClient`
* `LoginAdmin`
* `LoginSuper`

They automatically populate:

* `$Global:FortuneBetToken`
* `$Global:FortuneBetRefreshToken`

So you don’t have to manually copy tokens 

---

## 📡 Core Command

Everything ultimately goes through:

```powershell
fortune call <METHOD> <PATH> [-Tenant] [-Body @{...}]
```

### Example

```powershell
fortune call GET "leagues" -Tenant
```

---

## 🧪 Adding New Tests

Add a new function inside `fortune_tests.ps1`:

```powershell
function MyNewTest {
  fortune call GET "some-endpoint" -Tenant
}
```

That’s it. It will automatically appear in the selector.

---

## 🧩 Available Test Categories

### Payments

* CryptoPay (deposit, withdrawal)
* Chapa (deposit, banks, withdrawal)
* ArifPay (checkout)

### Direct Deposits

* Create / Approve / Reject
* Bank cycling
* Account management

### Betting

* Event → Odds → Selection pipeline (`EventOddPipe`)
* Bet placement (`CreateBet`)

### Virtual Games

* Providers
* Game listing
* Demo launch

### Admin / Super Admin

* Bank management
* Direct deposit bank setup

---

## 🔄 Token Refresh

```powershell
fortune refresh
```

Uses the stored refresh token to get a new access token.

---

## 🧱 Environment Variables

Defined in `fortune.ps1`:

```powershell
$Global:ApiBase = "http://127.0.0.1:8080/api/v1"
$Global:TenantSlug = "fortunebets"
```

Change these if you’re pointing to a different environment.

---

## 💡 Why This Exists

Because postman takes alot of RAM

---

