Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): support float fields #1263

Merged
merged 9 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions server/e2e/gql_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type fIds struct {
boolFId string
selectFId string
integerFId string
numberFId string
urlFId string
dateFId string
tagFID string
Expand Down Expand Up @@ -192,6 +193,16 @@ func createFieldOfEachType(t *testing.T, e *httpexpect.Expect, mId string) fIds
},
})

numberFId, _ := createField(e, mId, "number", "number", "number",
false, false, false, false, "Number",
map[string]any{
"number": map[string]any{
"defaultValue": nil,
"min": nil,
"max": nil,
},
})

Comment on lines +196 to +205
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding tests for the "number" field's constraints

While the "number" field is properly added, consider adding tests to validate its defaultValue, min, and max properties to ensure it behaves correctly under various conditions.

urlFId, _ := createField(e, mId, "url", "url", "url",
false, false, false, false, "URL",
map[string]any{
Expand Down Expand Up @@ -260,6 +271,7 @@ func createFieldOfEachType(t *testing.T, e *httpexpect.Expect, mId string) fIds
boolFId,
selectFId,
integerFId,
numberFId,
urlFId,
dateFId,
tagFId,
Expand All @@ -276,6 +288,7 @@ func createFieldOfEachType(t *testing.T, e *httpexpect.Expect, mId string) fIds
boolFId: boolFId,
selectFId: selectFId,
integerFId: integerFId,
numberFId: numberFId,
urlFId: urlFId,
dateFId: dateFId,
tagFID: tagFId,
Expand Down
6 changes: 3 additions & 3 deletions server/e2e/gql_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func TestClearItemValues(t *testing.T) {
})
fields := r1.Path("$.data.createItem.item.fields[:].value").Raw().([]any)
assert.Equal(t, []any{
"Text", "TextArea", "MarkdownText", aid.String(), true, "s1", float64(1), "https://www.1s.com", "2023-01-01T00:00:00Z", tagIds[0], true, "{\n\t\"type\": \"Point\",\n\t\"coordinates\": [102.0, 0.5]\n}", "{\n\t\"type\": \"Point\",\n\t\"coordinates\": [102.0, 0.5]\n}",
"Text", "TextArea", "MarkdownText", aid.String(), true, "s1", float64(1), nil, "https://www.1s.com", "2023-01-01T00:00:00Z", tagIds[0], true, "{\n\t\"type\": \"Point\",\n\t\"coordinates\": [102.0, 0.5]\n}", "{\n\t\"type\": \"Point\",\n\t\"coordinates\": [102.0, 0.5]\n}",
}, fields)
i1ver, _ := getItem(e, iid)
_, r2 := updateItem(e, iid, i1ver, []map[string]any{
Expand All @@ -432,7 +432,7 @@ func TestClearItemValues(t *testing.T) {
})
fields = r2.Path("$.data.updateItem.item.fields[:].value").Raw().([]any)
assert.Equal(t, []any{
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
}, fields)

iid2, _ := createItem(e, mId, sId, nil, []map[string]any{
Expand All @@ -453,7 +453,7 @@ func TestClearItemValues(t *testing.T) {
_, r3 := getItem(e, iid2)
fields2 := r3.Path("$.data.node.fields[:].value").Raw().([]any)
assert.Equal(t, []any{
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
}, fields2)

}
Expand Down
6 changes: 3 additions & 3 deletions server/e2e/integration_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ func TestIntegrationModelImportJSONWithJsonInput(t *testing.T) {
mId, _ := createModel(e, pId, "test", "test", "test-1")
createFieldOfEachType(t, e, mId)

jsonContent := `[{"text": "test1", "bool": true, "integer": 1},{"text": "test2", "bool": false, "integer": 2},{"text": "test3", "bool": null, "integer": null}]`
jsonContent := `[{"text": "test1", "bool": true, "number": 1.1},{"text": "test2", "bool": false, "number": 2},{"text": "test3", "bool": null, "number": null}]`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Action Required: Update Remaining "integer" References to "number"

The search revealed multiple instances of "integer" across the codebase. To maintain consistency and support for floating-point numbers, please update all relevant occurrences from "integer" to "number". Ensure that these changes are reflected in:

  • Field definitions and type declarations.
  • Context paths and API contracts.
  • Associated test cases and schemas.

This will help prevent potential type mismatches and ensure seamless functionality across the system.

🔗 Analysis chain

LGTM! Consider verifying the impact of the field type change.

The change from "integer" to "number" in the test JSON content is good and reflects the new support for floating-point numbers. This update aligns the test case with the new field structure.

To ensure this change doesn't have unintended consequences, please run the following script to check for any other occurrences of "integer" fields that might need updating:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of "integer" fields in the codebase
rg '"integer"' --type go

Length of output: 1553

aId := UploadAsset(e, pId, "./test1.json", jsonContent).Object().Value("id").String().Raw()
res := IntegrationModelImportJSON(e, mId, aId, "json", "insert", false, nil)
res.Object().IsEqual(map[string]any{
Expand Down Expand Up @@ -1573,7 +1573,7 @@ func TestIntegrationItemsAsCSV(t *testing.T) {
})

res := IntegrationItemsAsCSV(e, mId, 1, 10, i1Id, "", "", nil)
expected := fmt.Sprintf("id,location_lat,location_lng,text,textArea,markdown,asset,bool,select,integer,url,date,tag,checkbox\n%s,139.28179282584915,36.58570985749664,test1,,,,,,,,,,\n", i1Id)
expected := fmt.Sprintf("id,location_lat,location_lng,text,textArea,markdown,asset,bool,select,integer,number,url,date,tag,checkbox\n%s,139.28179282584915,36.58570985749664,test1,,,,,,,,,,,\n", i1Id)
res.IsEqual(expected)
}

Expand All @@ -1593,7 +1593,7 @@ func TestIntegrationItemsWithProjectAsCSV(t *testing.T) {
})

res := IntegrationItemsWithProjectAsCSV(e, pId, mId, 1, 10, i1Id, "", "", nil)
expected := fmt.Sprintf("id,location_lat,location_lng,text,textArea,markdown,asset,bool,select,integer,url,date,tag,checkbox\n%s,139.28179282584915,36.58570985749664,test1,,,,,,30,,,,\n", i1Id)
expected := fmt.Sprintf("id,location_lat,location_lng,text,textArea,markdown,asset,bool,select,integer,number,url,date,tag,checkbox\n%s,139.28179282584915,36.58570985749664,test1,,,,,,30,,,,,\n", i1Id)
res.IsEqual(expected)
}

Expand Down
Loading