feat(gl): expose ledger application and grpc operations
This commit is contained in:
1 parent
0b3eaa0c3d
commit
76905ab451
17 files changed
+1724
-16
No files matched your search
@@ -0,0 +1,73 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gl/domain/ledger"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func TestAppendEventStoresAndReturnsRecordingTime(t *testing.T) {
|
||||
event := repositoryEvent()
|
||||
recordedAt := time.Unix(2, 0).UTC()
|
||||
database := &fakeDatabase{directRows: []Row{fakeRow{values: []any{recordedAt}}}}
|
||||
|
||||
stored, existed, err := NewJournalRepository(database).AppendEvent(context.Background(), event)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if existed || !stored.RecordedAt.Equal(recordedAt) {
|
||||
t.Fatalf("unexpected append result: existed=%v event=%+v", existed, stored)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendEventRejectsConflictingIdempotencyPayload(t *testing.T) {
|
||||
event := repositoryEvent()
|
||||
storedHash := strings.Repeat("b", 64)
|
||||
database := &fakeDatabase{directRows: []Row{
|
||||
fakeRow{err: pgx.ErrNoRows},
|
||||
fakeRow{values: []any{
|
||||
event.ID,
|
||||
event.SourceService,
|
||||
event.IdempotencyKey,
|
||||
event.SourceTransactionID,
|
||||
event.TrackingCode,
|
||||
event.EventVersion,
|
||||
event.State,
|
||||
event.ErrorCode,
|
||||
event.ErrorMessage,
|
||||
event.OccurredAt,
|
||||
time.Unix(2, 0).UTC(),
|
||||
event.CorrelationID,
|
||||
event.ActorID,
|
||||
event.Blockchain.Network,
|
||||
event.Blockchain.TransactionHash,
|
||||
event.Blockchain.LedgerSequence,
|
||||
[]byte(`{}`),
|
||||
storedHash,
|
||||
}},
|
||||
}}
|
||||
|
||||
_, _, err := NewJournalRepository(database).AppendEvent(context.Background(), event)
|
||||
if !errors.Is(err, ErrIdempotencyConflict) {
|
||||
t.Fatalf("expected idempotency conflict, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func repositoryEvent() ledger.TransactionEvent {
|
||||
return ledger.TransactionEvent{
|
||||
ID: "11111111-1111-4111-8111-111111111111",
|
||||
SourceService: "wallet",
|
||||
IdempotencyKey: "wallet:1:status:v1",
|
||||
SourceTransactionID: "1",
|
||||
EventVersion: 1,
|
||||
State: ledger.TransactionStateCreated,
|
||||
OccurredAt: time.Unix(1, 0).UTC(),
|
||||
PayloadHash: strings.Repeat("a", 64),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user