12e616ceae
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 11s
CI / integration (pull_request) Successful in 21s
CI / ui (pull_request) Successful in 1m28s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m45s
The merchant accepts payments as a sole proprietor on НПД, which is outside 54-ФЗ: there is no online cash register, YooKassa does not serve receipts for that regime at all (checked with their support), and each operation is reported by the merchant to «Мой налог», which issues the чек. So no `receipt` is sent with a payment or a refund. This also removes a failure class rather than just code: a malformed receipt was an API error at payment creation, which broke the purchase outright. The fiscal code is kept dormant rather than deleted. All of it now sits behind one switch, `BACKEND_YOOKASSA_VAT_CODE`: unset — the default — builds and sends nothing; a 54-ФЗ rate code turns «Чеки от ЮKassa» back on unchanged. The return is foreseeable, which is why the switch exists: НПД carries an annual income ceiling, and losing the regime puts 54-ФЗ back in force, at which point this is a deploy-variable edit instead of writing the integration again. The D36 email anchor still gates a direct purchase. It had two justifications — a recovery anchor and the receipt address — and only the second is gone; without an email a paying customer who loses the account loses the chips with it. What was missing is that the rule was enforced but never communicated: the wallet showed the packs to a player signed in through VK or Telegram in a browser, and tapping Buy produced a bare "something went wrong". It now says "add an email in your profile" in the buy tab instead, linking to the profile; spending already-earned chips is untouched. The predicate is a pure function so it is covered by the node-env unit tests rather than needing a browser. Tests: the receipt-off default is pinned by an integration test asserting a purchase carries no receipt, and the dormant path by one that switches a VAT code on and checks the receipt reappears with the right fiscal attributes; plus unit coverage for the enable predicate and the wallet's email rule. A note for whoever runs the numbers next: the shared (svelte + i18n) chunk is now 40 bytes under its 31 KB gzip budget. Decision D51 revised.
126 lines
3.8 KiB
Go
126 lines
3.8 KiB
Go
package yookassa
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func testShops() Shops {
|
|
return Shops{
|
|
ChannelWeb: {ShopID: "100500", SecretKey: "web-secret"},
|
|
ChannelAndroid: {ShopID: "100700", SecretKey: "android-secret"},
|
|
}
|
|
}
|
|
|
|
func TestShopsShopRouting(t *testing.T) {
|
|
s := testShops()
|
|
for channel, wantShopID := range map[string]string{
|
|
ChannelWeb: "100500",
|
|
ChannelAndroid: "100700",
|
|
"ios": "100500", // an unconfigured channel falls back to web
|
|
"": "100500", // so does an unknown platform subtype
|
|
} {
|
|
got, ok := s.Shop(channel)
|
|
if !ok || got.ShopID != wantShopID {
|
|
t.Errorf("Shop(%q) = %q ok=%v, want %q", channel, got.ShopID, ok, wantShopID)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestShopsShopWithoutWebFallback(t *testing.T) {
|
|
// Only android configured: an unknown channel has nowhere safe to fall back to.
|
|
s := Shops{ChannelAndroid: {ShopID: "100700", SecretKey: "android-secret"}}
|
|
if got, ok := s.Shop(ChannelAndroid); !ok || got.ShopID != "100700" {
|
|
t.Errorf("Shop(android) = %q ok=%v, want the android shop", got.ShopID, ok)
|
|
}
|
|
if _, ok := s.Shop("ios"); ok {
|
|
t.Error("Shop(ios) resolved with no web shop configured")
|
|
}
|
|
if _, ok := (Shops{}).Shop(ChannelWeb); ok {
|
|
t.Error("an empty set resolved a shop")
|
|
}
|
|
}
|
|
|
|
func TestShopsByShopIDDoesNotGuess(t *testing.T) {
|
|
s := testShops()
|
|
channel, cfg, ok := s.ByShopID("100700")
|
|
if !ok || channel != ChannelAndroid || cfg.SecretKey != "android-secret" {
|
|
t.Errorf("ByShopID(100700) = %q/%q ok=%v, want the android shop", channel, cfg.SecretKey, ok)
|
|
}
|
|
// An unrecognised shop id means the notification was not meant for us; guessing at credentials
|
|
// would verify a foreign payment against our own shop.
|
|
for _, id := range []string{"999999", ""} {
|
|
if _, _, ok := s.ByShopID(id); ok {
|
|
t.Errorf("ByShopID(%q) resolved a shop", id)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestShopsIgnoreHalfConfiguredEntries(t *testing.T) {
|
|
s := Shops{
|
|
ChannelWeb: {ShopID: "100500"}, // no secret key
|
|
ChannelAndroid: {SecretKey: "android-secret"},
|
|
}
|
|
if s.Configured() {
|
|
t.Error("Configured() = true with no complete shop")
|
|
}
|
|
if _, ok := s.Shop(ChannelWeb); ok {
|
|
t.Error("Shop(web) resolved a shop with no secret key")
|
|
}
|
|
if _, _, ok := s.ByShopID("100500"); ok {
|
|
t.Error("ByShopID matched a shop with no secret key")
|
|
}
|
|
}
|
|
|
|
func TestShopsConfigured(t *testing.T) {
|
|
if !testShops().Configured() {
|
|
t.Error("Configured() = false with two complete shops")
|
|
}
|
|
if (Shops{}).Configured() {
|
|
t.Error("Configured() = true for an empty set")
|
|
}
|
|
}
|
|
|
|
func TestSingleItemReceiptTruncatesLongTitles(t *testing.T) {
|
|
long := strings.Repeat("ф", 200) // Cyrillic: truncation must count runes, not bytes
|
|
r := SingleItemReceipt("buyer@example.test", long, Amount{Value: "1.00", Currency: "RUB"}, VatCodeNone)
|
|
got := []rune(r.Items[0].Description)
|
|
if len(got) != maxDescriptionRunes {
|
|
t.Errorf("description = %d runes, want %d", len(got), maxDescriptionRunes)
|
|
}
|
|
for _, c := range got {
|
|
if c != 'ф' {
|
|
t.Fatalf("truncation cut a multi-byte rune: %q", string(got))
|
|
}
|
|
}
|
|
if r.Items[0].Quantity != 1 {
|
|
t.Errorf("quantity = %v, want 1 (a chip pack is bought once)", r.Items[0].Quantity)
|
|
}
|
|
}
|
|
|
|
func TestValidVatCode(t *testing.T) {
|
|
// VatCodeOff is a legal configuration: it means "send no receipt", the state a merchant outside
|
|
// 54-ФЗ runs in.
|
|
for _, code := range []int{VatCodeOff, 1, 4, 11, 12} {
|
|
if !ValidVatCode(code) {
|
|
t.Errorf("vat code %d rejected, want accepted", code)
|
|
}
|
|
}
|
|
for _, code := range []int{-1, 13} {
|
|
if ValidVatCode(code) {
|
|
t.Errorf("vat code %d accepted, want rejected", code)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestReceiptEnabled(t *testing.T) {
|
|
if ReceiptEnabled(VatCodeOff) {
|
|
t.Error("receipts reported enabled with no VAT rate configured")
|
|
}
|
|
for _, code := range []int{1, 4, 11} {
|
|
if !ReceiptEnabled(code) {
|
|
t.Errorf("receipts reported disabled for vat code %d", code)
|
|
}
|
|
}
|
|
}
|