From f4a07499a69e758690313380a0138052ead5f327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Fri, 27 Sep 2024 12:30:45 +0200 Subject: [PATCH] fix: change `ModelMap` to contain any possible property, not just strings --- .changeset/cuddly-wasps-try.md | 5 +++++ sdk/model_map.go | 2 +- test/utils.go | 10 ++++++++++ test/webhook_test.go | 9 +++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .changeset/cuddly-wasps-try.md diff --git a/.changeset/cuddly-wasps-try.md b/.changeset/cuddly-wasps-try.md new file mode 100644 index 0000000..cfb8ec6 --- /dev/null +++ b/.changeset/cuddly-wasps-try.md @@ -0,0 +1,5 @@ +--- +"fingerprint-pro-server-api-go-sdk": major +--- + +Change `ModelMap` to contain any possible property, not just strings diff --git a/sdk/model_map.go b/sdk/model_map.go index 92b3bee..9c2a772 100644 --- a/sdk/model_map.go +++ b/sdk/model_map.go @@ -2,4 +2,4 @@ package sdk type Model struct{} -type ModelMap map[string]string +type ModelMap map[string]any diff --git a/test/utils.go b/test/utils.go index 2c1df2f..04c0988 100644 --- a/test/utils.go +++ b/test/utils.go @@ -6,6 +6,16 @@ import ( "os" ) +func readFromFileAndUnmarshalWithError(path string, i interface{}) error { + data, err := os.ReadFile(path) + + if err != nil { + return err + } + + return json.Unmarshal(data, &i) +} + func readFromFileAndUnmarshal(path string, i interface{}) { data, err := os.ReadFile(path) diff --git a/test/webhook_test.go b/test/webhook_test.go index f66ac71..bdcbd28 100644 --- a/test/webhook_test.go +++ b/test/webhook_test.go @@ -1,6 +1,7 @@ package test import ( + "github.com/fingerprintjs/fingerprint-pro-server-api-go-sdk/v6/sdk" "github.com/fingerprintjs/fingerprint-pro-server-api-go-sdk/v6/sdk/webhook" "github.com/stretchr/testify/assert" "testing" @@ -9,6 +10,14 @@ import ( const secret = "secret" const data = "data" +func TestWebhookModel(t *testing.T) { + t.Run("Check if webhook response can be unmarshalled", func(t *testing.T) { + var mockResponse sdk.WebhookVisit + err := readFromFileAndUnmarshalWithError("../test/mocks/webhook.json", &mockResponse) + assert.NoError(t, err) + }) +} + func TestIsValidWebhookSignature(t *testing.T) { const validHeader = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db"