52 lines
1.8 KiB
Go
52 lines
1.8 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAccountCopyDeepCopiesMetadata(t *testing.T) {
|
|
account := &Account{
|
|
AccountPublic: AccountPublic{
|
|
AccountBase: AccountBase{
|
|
Metadata: &AccountMetadata{
|
|
PersonalLedgerProvisioning: &LedgerProvisioningMetadata{
|
|
Source: "invitation",
|
|
InvitationRef: "invitation-ref",
|
|
TargetCurrencies: []string{"RUB", "USDT"},
|
|
Created: []string{"RUB"},
|
|
AlreadyExisting: []string{"USDT"},
|
|
Failed: []LedgerProvisioningFailure{{Currency: "EUR", ErrorClass: "timeout"}},
|
|
Outcome: "partial_failure",
|
|
LastErrorClass: "timeout",
|
|
LastAttemptAt: time.Now().UTC(),
|
|
},
|
|
},
|
|
},
|
|
UserDataBase: UserDataBase{Login: "invitee@example.com"},
|
|
},
|
|
Password: "secret",
|
|
Status: AccountActive,
|
|
}
|
|
|
|
copied := account.Copy()
|
|
copied.Metadata.PersonalLedgerProvisioning.TargetCurrencies[0] = "EUR"
|
|
copied.Metadata.PersonalLedgerProvisioning.Created[0] = "EUR"
|
|
copied.Metadata.PersonalLedgerProvisioning.AlreadyExisting[0] = "EUR"
|
|
copied.Metadata.PersonalLedgerProvisioning.Failed[0].ErrorClass = "ledger_unavailable"
|
|
|
|
metadata := account.Metadata.PersonalLedgerProvisioning
|
|
if metadata.TargetCurrencies[0] != "RUB" {
|
|
t.Fatalf("expected original target currency to remain RUB, got %q", metadata.TargetCurrencies[0])
|
|
}
|
|
if metadata.Created[0] != "RUB" {
|
|
t.Fatalf("expected original created currency to remain RUB, got %q", metadata.Created[0])
|
|
}
|
|
if metadata.AlreadyExisting[0] != "USDT" {
|
|
t.Fatalf("expected original existing currency to remain USDT, got %q", metadata.AlreadyExisting[0])
|
|
}
|
|
if metadata.Failed[0].ErrorClass != "timeout" {
|
|
t.Fatalf("expected original failure class to remain timeout, got %q", metadata.Failed[0].ErrorClass)
|
|
}
|
|
}
|