GET /customer/enakgame/leaderboard ranks the customers of an organization by the EnakCoin they won from games in one week, Monday to Sunday in Asia/Jakarta. Only completed, unflagged sessions count, by the week they started; entry cost is not subtracted. Equal totals rank by who reached theirs first, so no two customers share a rank. Optional date (any day of the week, this week by default), game_id and limit (10, at most 100). The response holds the top ranks and, under me, the customer asking wherever they rank. Other customers are shown by a masked name: the first word whole, the others by their first letter; a word with a digit keeps only its first character. The EnakGame web game shows it: integration-enakgame.md §10 (checklist now §11) and RFC §11. The DB test needs TEST_DATABASE_URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package processor
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMaskCustomerName(t *testing.T) {
|
|
for name, want := range map[string]string{
|
|
"Budi Santoso": "Budi S******",
|
|
"budi": "budi",
|
|
" Siti Nur Aisyah": "Siti N** A*****",
|
|
"Ádám Ő": "Ádám Ő",
|
|
"081234567890": "0***********",
|
|
"Budi2 Santoso": "B**** S******",
|
|
"": "Pemain",
|
|
" ": "Pemain",
|
|
} {
|
|
assert.Equal(t, want, maskCustomerName(name), "%q", name)
|
|
}
|
|
}
|
|
|
|
func TestLeaderboardWeekStart(t *testing.T) {
|
|
monday := time.Date(2026, 10, 12, 0, 0, 0, 0, walletDisplayLocation)
|
|
for _, day := range []time.Time{
|
|
monday,
|
|
time.Date(2026, 10, 14, 12, 0, 0, 0, walletDisplayLocation),
|
|
time.Date(2026, 10, 18, 23, 59, 59, 0, walletDisplayLocation),
|
|
// Sunday 17:00 UTC is already Monday 00:00 in Jakarta.
|
|
time.Date(2026, 10, 11, 17, 0, 0, 0, time.UTC),
|
|
} {
|
|
assert.True(t, monday.Equal(leaderboardWeekStart(day)), "%s", day)
|
|
}
|
|
// Sunday 16:59 UTC is still Sunday in Jakarta, the week before.
|
|
assert.True(t, monday.AddDate(0, 0, -7).Equal(leaderboardWeekStart(time.Date(2026, 10, 11, 16, 59, 0, 0, time.UTC))))
|
|
}
|