feat: add terminal-scoped transaction analytics
This commit is contained in:
61
internal/analytics/details_test.go
Normal file
61
internal/analytics/details_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package analytics
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDetailFilterValidate(t *testing.T) {
|
||||
t.Parallel()
|
||||
zero := int64(0)
|
||||
hundred := int64(100)
|
||||
twoHundred := int64(200)
|
||||
tests := []struct {
|
||||
name string
|
||||
filter DetailFilter
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "all transactions", filter: DetailFilter{View: "ALL", Limit: 25}},
|
||||
{name: "allowlisted status", filter: DetailFilter{View: "ALL", Status: "Verified", Limit: 25}},
|
||||
{name: "amount range", filter: DetailFilter{View: "ALL", MinAmountRial: &zero, MaxAmountRial: &hundred, Limit: 25}},
|
||||
{name: "failed observed stage", filter: DetailFilter{View: "FAILED", FailureStage: "REACHED_BANK", Limit: 25}},
|
||||
{name: "unknown view", filter: DetailFilter{View: "EVERYTHING", Limit: 25}, wantErr: true},
|
||||
{name: "unknown status", filter: DetailFilter{View: "ALL", Status: "Successful", Limit: 25}, wantErr: true},
|
||||
{name: "stage outside failed view", filter: DetailFilter{View: "ALL", FailureStage: "NO_ATTEMPT", Limit: 25}, wantErr: true},
|
||||
{name: "descending amount range", filter: DetailFilter{View: "ALL", MinAmountRial: &twoHundred, MaxAmountRial: &hundred, Limit: 25}, wantErr: true},
|
||||
{name: "page too large", filter: DetailFilter{View: "ALL", Limit: 101}, wantErr: true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := tt.filter.Validate()
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("Validate() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionSourceKey(t *testing.T) {
|
||||
t.Parallel()
|
||||
tests := []struct {
|
||||
name, input, want string
|
||||
valid bool
|
||||
}{
|
||||
{name: "valid opaque id", input: "ses_abc-123", want: "abc-123", valid: true},
|
||||
{name: "missing prefix", input: "abc-123"},
|
||||
{name: "empty source", input: "ses_"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, valid := sessionSourceKey(tt.input)
|
||||
if got != tt.want || valid != tt.valid {
|
||||
t.Fatalf("sessionSourceKey(%q) = %q,%v, want %q,%v", tt.input, got, valid, tt.want, tt.valid)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTerminalDisplayName(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := terminalDisplayName("terminal-12345678"); got != "پایانه ۵۶۷۸" {
|
||||
t.Fatalf("terminalDisplayName() = %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user