From be6ada0b2836d316e27d416618e877f619897676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Mon, 29 Jan 2024 11:01:26 +0100 Subject: [PATCH] feat(BUX-525): remove unused graphql methods --- go.mod | 2 +- model_ids.go | 21 --------------- model_ids_test.go | 29 --------------------- model_metadata.go | 17 ------------ model_metadata_test.go | 59 ------------------------------------------ 5 files changed, 1 insertion(+), 127 deletions(-) diff --git a/go.mod b/go.mod index e76d4128..1a91ebd1 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/BuxOrg/bux go 1.21.5 require ( - github.com/99designs/gqlgen v0.17.42 github.com/DATA-DOG/go-sqlmock v1.5.2 github.com/bitcoin-sv/go-broadcast-client v0.16.0 github.com/bitcoin-sv/go-paymail v0.12.1 @@ -42,6 +41,7 @@ require ( ) require ( + github.com/99designs/gqlgen v0.17.42 // indirect github.com/acobaugh/osrelease v0.1.0 // indirect github.com/bitcoinschema/go-bpu v0.1.3 // indirect github.com/bitcoinsv/bsvd v0.0.0-20190609155523-4c29707f7173 // indirect diff --git a/model_ids.go b/model_ids.go index db47f2b8..22180364 100644 --- a/model_ids.go +++ b/model_ids.go @@ -4,7 +4,6 @@ import ( "database/sql/driver" "encoding/json" - "github.com/99designs/gqlgen/graphql" "github.com/BuxOrg/bux/utils" "github.com/mrz1836/go-datastore" "gorm.io/gorm" @@ -53,23 +52,3 @@ func (IDs) GormDBDataType(db *gorm.DB, _ *schema.Field) string { } return datastore.JSON } - -// UnmarshalIDs will marshal the custom type -func UnmarshalIDs(v interface{}) (IDs, error) { - if v == nil { - return nil, nil - } - - // Try to unmarshal - ids, err := graphql.UnmarshalAny(v) - if err != nil { - return nil, err - } - - // Cast interface back to IDs (safely) - if idCast, ok := ids.(IDs); ok { - return idCast, nil - } - - return nil, ErrCannotConvertToIDs -} diff --git a/model_ids_test.go b/model_ids_test.go index 13490cd8..fafd7c01 100644 --- a/model_ids_test.go +++ b/model_ids_test.go @@ -75,32 +75,3 @@ func TestIDs_Value(t *testing.T) { assert.Equal(t, "[\"test1\"]", value) }) } - -// TestUnmarshalIDs will test the method UnmarshalIDs() -func TestUnmarshalIDs(t *testing.T) { - - t.Parallel() - - t.Run("nil value", func(t *testing.T) { - i, err := UnmarshalIDs(nil) - require.NoError(t, err) - assert.Equal(t, 0, len(i)) - assert.IsType(t, IDs{}, i) - }) - - t.Run("empty string", func(t *testing.T) { - i, err := UnmarshalIDs("\"\"") - assert.Error(t, err) - assert.Equal(t, 0, len(i)) - assert.IsType(t, IDs{}, i) - }) - - t.Run("valid set of ids", func(t *testing.T) { - i, err := UnmarshalIDs(IDs{"test1", "test2"}) - require.NoError(t, err) - assert.Equal(t, 2, len(i)) - assert.IsType(t, IDs{}, i) - assert.Equal(t, "test1", i[0]) - assert.Equal(t, "test2", i[1]) - }) -} diff --git a/model_metadata.go b/model_metadata.go index af2091ee..16fe44de 100644 --- a/model_metadata.go +++ b/model_metadata.go @@ -5,7 +5,6 @@ import ( "database/sql/driver" "encoding/json" - "github.com/99designs/gqlgen/graphql" "github.com/BuxOrg/bux/utils" "github.com/mrz1836/go-datastore" "go.mongodb.org/mongo-driver/bson" @@ -186,19 +185,3 @@ func (x *XpubMetadata) UnmarshalBSONValue(t bsontype.Type, data []byte) error { return nil } - -// MarshalMetadata will marshal the custom type -func MarshalMetadata(m Metadata) graphql.Marshaler { - if m == nil { - return graphql.Null - } - return graphql.MarshalMap(m) -} - -// UnmarshalMetadata will unmarshal the custom type -func UnmarshalMetadata(v interface{}) (Metadata, error) { - if v == nil { - return nil, nil - } - return graphql.UnmarshalMap(v) -} diff --git a/model_metadata_test.go b/model_metadata_test.go index 45523cff..256d0a56 100644 --- a/model_metadata_test.go +++ b/model_metadata_test.go @@ -1,7 +1,6 @@ package bux import ( - "bytes" "encoding/hex" "encoding/json" "testing" @@ -124,64 +123,6 @@ func TestXpubMetadata_Value(t *testing.T) { }) } -// TestMetaDataScan will test the db Scanner of the Metadata model -func TestMetadata_UnmarshalMetadata(t *testing.T) { - t.Parallel() - - t.Run("nil value", func(t *testing.T) { - m, err := UnmarshalMetadata(nil) - require.NoError(t, err) - assert.Equal(t, 0, len(m)) - assert.IsType(t, Metadata{}, m) - }) - - t.Run("empty string", func(t *testing.T) { - m, err := UnmarshalMetadata("\"\"") - assert.Error(t, err) - assert.Equal(t, 0, len(m)) - assert.IsType(t, Metadata{}, m) - }) - - t.Run("empty string - incorrectly coded", func(t *testing.T) { - m, err := UnmarshalMetadata("") - assert.Error(t, err) - assert.Equal(t, 0, len(m)) - assert.IsType(t, Metadata{}, m) - }) - - t.Run("object", func(t *testing.T) { - m, err := UnmarshalMetadata(map[string]interface{}{"test": "test2"}) - require.NoError(t, err) - assert.Equal(t, 1, len(m)) - assert.IsType(t, Metadata{}, m) - assert.Equal(t, "test2", m["test"]) - }) -} - -// TestMetadata_MarshalMetadata will test the db Valuer of the Metadata model -func TestMetadata_MarshalMetadata(t *testing.T) { - t.Parallel() - - t.Run("empty object", func(t *testing.T) { - m := Metadata{} - writer := MarshalMetadata(m) - require.NotNil(t, writer) - b := bytes.NewBufferString("") - writer.MarshalGQL(b) - assert.Equal(t, "{}\n", b.String()) - }) - - t.Run("map present", func(t *testing.T) { - m := Metadata{} - m["test"] = "test2" - writer := MarshalMetadata(m) - require.NotNil(t, writer) - b := bytes.NewBufferString("") - writer.MarshalGQL(b) - assert.Equal(t, "{\"test\":\"test2\"}\n", b.String()) - }) -} - // TestMetadata_MarshalBSONValue will test the method MarshalBSONValue() func TestMetadata_MarshalBSONValue(t *testing.T) { t.Parallel()