Bug Fix for ReqPreProcessor plugin

This commit is contained in:
tanyamadaan
2025-04-03 16:08:57 +05:30
parent 7ea369f3bb
commit 87329bfb9d
4 changed files with 140 additions and 77 deletions

View File

@@ -3,7 +3,6 @@ package main
import (
"context"
"net/http"
"strings"
"github.com/beckn/beckn-onix/pkg/plugin/implementation/reqpreprocessor"
)
@@ -12,9 +11,6 @@ type provider struct{}
func (p provider) New(ctx context.Context, c map[string]string) (func(http.Handler) http.Handler, error) {
config := &reqpreprocessor.Config{}
if contextKeysStr, ok := c["contextKeys"]; ok {
config.ContextKeys = strings.Split(contextKeysStr, ",")
}
if role, ok := c["role"]; ok {
config.Role = role
}

View File

@@ -32,9 +32,9 @@ func TestProviderNew(t *testing.T) {
},
},
{
name: "With Check Keys",
name: "Success with BPP role",
config: map[string]string{
"contextKeys": "message_id,transaction_id",
"role": "bpp",
},
expectedError: false,
expectedStatus: http.StatusOK,
@@ -42,6 +42,29 @@ func TestProviderNew(t *testing.T) {
// Add headers matching the check keys.
req.Header.Set("context", "test-context")
req.Header.Set("transaction_id", "test-transaction")
req.Header.Set("bpp_id", "bpp-456")
},
},
{
name: "Missing role configuration",
config: map[string]string{
// No role specified
},
expectedError: true,
prepareRequest: func(req *http.Request) {
req.Header.Set("context", "test-context")
req.Header.Set("transaction_id", "test-transaction")
},
},
{
name: "Invalid role configuration",
config: map[string]string{
"role": "invalid-role",
},
expectedError: true,
prepareRequest: func(req *http.Request) {
req.Header.Set("context", "test-context")
req.Header.Set("transaction_id", "test-transaction")
},
},
}