Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
feat(BUX-525): remove unused graphql methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pawellewandowski98 committed Jan 29, 2024
1 parent 3ed84e6 commit be6ada0
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 127 deletions.
2 changes: 1 addition & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 0 additions & 21 deletions model_ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
29 changes: 0 additions & 29 deletions model_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
})
}
17 changes: 0 additions & 17 deletions model_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
59 changes: 0 additions & 59 deletions model_metadata_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bux

import (
"bytes"
"encoding/hex"
"encoding/json"
"testing"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit be6ada0

Please sign in to comment.