fixed failing tests
This commit is contained in:
@@ -32,9 +32,9 @@ type FPInput struct {
|
||||
|
||||
// ReuseInput defines lookup and comparison inputs for idempotency reuse checks.
|
||||
type ReuseInput struct {
|
||||
OrganizationID bson.ObjectID
|
||||
IdempotencyKey string
|
||||
Fingerprint string
|
||||
OrganizationRef bson.ObjectID
|
||||
IdempotencyKey string
|
||||
Fingerprint string
|
||||
}
|
||||
|
||||
// CreateInput wraps create operation with reuse-check context for duplicate races.
|
||||
|
||||
@@ -19,9 +19,9 @@ func TestTryReuse_NotFound(t *testing.T) {
|
||||
}
|
||||
|
||||
payment, reused, err := svc.TryReuse(context.Background(), store, ReuseInput{
|
||||
OrganizationID: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "hash-1",
|
||||
OrganizationRef: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "hash-1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("TryReuse returned error: %v", err)
|
||||
@@ -47,9 +47,9 @@ func TestTryReuse_ParamMismatch(t *testing.T) {
|
||||
}
|
||||
|
||||
_, _, err := svc.TryReuse(context.Background(), store, ReuseInput{
|
||||
OrganizationID: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "new-hash",
|
||||
OrganizationRef: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "new-hash",
|
||||
})
|
||||
if !errors.Is(err, ErrIdempotencyParamMismatch) {
|
||||
t.Fatalf("expected ErrIdempotencyParamMismatch, got %v", err)
|
||||
@@ -71,9 +71,9 @@ func TestTryReuse_Success(t *testing.T) {
|
||||
}
|
||||
|
||||
payment, reused, err := svc.TryReuse(context.Background(), store, ReuseInput{
|
||||
OrganizationID: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "hash-1",
|
||||
OrganizationRef: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "hash-1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("TryReuse returned error: %v", err)
|
||||
@@ -98,9 +98,9 @@ func TestCreateOrReuse_CreateSuccess(t *testing.T) {
|
||||
got, reused, err := svc.CreateOrReuse(context.Background(), store, CreateInput{
|
||||
Payment: newPayment,
|
||||
Reuse: ReuseInput{
|
||||
OrganizationID: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "hash-1",
|
||||
OrganizationRef: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "hash-1",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -136,9 +136,9 @@ func TestCreateOrReuse_DuplicateReturnsExisting(t *testing.T) {
|
||||
got, reused, err := svc.CreateOrReuse(context.Background(), store, CreateInput{
|
||||
Payment: newPayment,
|
||||
Reuse: ReuseInput{
|
||||
OrganizationID: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "hash-1",
|
||||
OrganizationRef: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "hash-1",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -168,9 +168,9 @@ func TestCreateOrReuse_DuplicateParamMismatch(t *testing.T) {
|
||||
_, _, err := svc.CreateOrReuse(context.Background(), store, CreateInput{
|
||||
Payment: &model.Payment{PaymentRef: "pay-new"},
|
||||
Reuse: ReuseInput{
|
||||
OrganizationID: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "new-hash",
|
||||
OrganizationRef: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "new-hash",
|
||||
},
|
||||
})
|
||||
if !errors.Is(err, ErrIdempotencyParamMismatch) {
|
||||
@@ -190,9 +190,9 @@ func TestCreateOrReuse_DuplicateWithoutReusableRecordReturnsDuplicate(t *testing
|
||||
_, _, err := svc.CreateOrReuse(context.Background(), store, CreateInput{
|
||||
Payment: &model.Payment{PaymentRef: "pay-new"},
|
||||
Reuse: ReuseInput{
|
||||
OrganizationID: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "hash-1",
|
||||
OrganizationRef: bson.NewObjectID(),
|
||||
IdempotencyKey: "idem-1",
|
||||
Fingerprint: "hash-1",
|
||||
},
|
||||
})
|
||||
if !errors.Is(err, storage.ErrDuplicatePayment) {
|
||||
|
||||
@@ -27,7 +27,7 @@ func (s *svc) TryReuse(
|
||||
) (payment *model.Payment, reused bool, err error) {
|
||||
logger := s.logger
|
||||
logger.Debug("Starting Try reuse",
|
||||
mzap.ObjRef("organization_ref", payment.OrganizationRef),
|
||||
mzap.ObjRef("organization_ref", in.OrganizationRef),
|
||||
zap.Bool("has_idempotency_key", strings.TrimSpace(in.IdempotencyKey) != ""),
|
||||
)
|
||||
defer func(start time.Time) {
|
||||
@@ -54,7 +54,7 @@ func (s *svc) TryReuse(
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
payment, err = store.GetByIdempotencyKey(ctx, in.OrganizationID, idempotencyKey)
|
||||
payment, err = store.GetByIdempotencyKey(ctx, in.OrganizationRef, idempotencyKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, storage.ErrPaymentNotFound) || errors.Is(err, merrors.ErrNoData) {
|
||||
return nil, false, nil
|
||||
@@ -79,7 +79,7 @@ func (s *svc) CreateOrReuse(
|
||||
) (payment *model.Payment, reused bool, err error) {
|
||||
logger := s.logger
|
||||
logger.Debug("Starting Create or reuse",
|
||||
zap.String("organization_ref", in.Reuse.OrganizationID.Hex()),
|
||||
zap.String("organization_ref", in.Reuse.OrganizationRef.Hex()),
|
||||
zap.Bool("has_payment", in.Payment != nil),
|
||||
zap.Bool("has_idempotency_key", strings.TrimSpace(in.Reuse.IdempotencyKey) != ""),
|
||||
)
|
||||
@@ -130,7 +130,7 @@ func (s *svc) CreateOrReuse(
|
||||
}
|
||||
|
||||
func validateReuseInput(in ReuseInput) (string, string, error) {
|
||||
if in.OrganizationID.IsZero() {
|
||||
if in.OrganizationRef.IsZero() {
|
||||
return "", "", merrors.InvalidArgument("organization_id is required")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user