This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: numbers are not decoded from gql to value
- Loading branch information
Showing
3 changed files
with
106 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package gqlmodel | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/reearth/reearth-backend/pkg/property" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFromPropertyValueAndType(t *testing.T) { | ||
type args struct { | ||
v interface{} | ||
t ValueType | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *property.Value | ||
}{ | ||
{ | ||
name: "number", | ||
args: args{ | ||
v: 1.1, | ||
t: ValueTypeNumber, | ||
}, | ||
want: property.ValueTypeNumber.ValueFrom(1.1), | ||
}, | ||
{ | ||
name: "json number", | ||
args: args{ | ||
v: json.Number("1.1"), | ||
t: ValueTypeNumber, | ||
}, | ||
want: property.ValueTypeNumber.ValueFrom(1.1), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equal(t, tt.want, FromPropertyValueAndType(tt.args.v, tt.args.t)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package gqlmodel | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/reearth/reearth-backend/pkg/value" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_FromValueType(t *testing.T) { | ||
assert.Equal(t, value.TypeString, FromValueType(ValueTypeString)) | ||
assert.Equal(t, value.TypeNumber, FromValueType(ValueTypeNumber)) | ||
} |