Skip to content

Commit

Permalink
Merge branch 'main' into feat-web/support-geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
caichi-t authored Aug 6, 2024
2 parents 53da0d7 + f3fba16 commit 74e666f
Show file tree
Hide file tree
Showing 40 changed files with 3,783 additions and 474 deletions.
149 changes: 149 additions & 0 deletions server/e2e/integration_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,62 @@ func IntegrationSearchItem(e *httpexpect.Expect, mId string, page, perPage int,
return res
}

func IntegrationItemsAsGeoJSON(e *httpexpect.Expect, mId string, page, perPage int, query string, sort, sortDir string, filter map[string]any) *httpexpect.Value {
res := e.GET("/api/models/{modelId}/items.geojson", mId).
WithHeader("Origin", "https://example.com").
WithHeader("X-Reearth-Debug-User", uId1.String()).
WithHeader("Content-Type", "application/json").
WithQuery("page", page).
WithQuery("perPage", perPage).
Expect().
Status(http.StatusOK).
JSON()

return res
}

func IntegrationItemsWithProjectAsGeoJSON(e *httpexpect.Expect, pId string, mId string, page, perPage int, query string, sort, sortDir string, filter map[string]any) *httpexpect.Value {
res := e.GET("/api/projects/{projectIdOrAlias}/models/{modelIdOrKey}/items.geojson", pId, mId).
WithHeader("Origin", "https://example.com").
WithHeader("X-Reearth-Debug-User", uId1.String()).
WithHeader("Content-Type", "application/json").
WithQuery("page", page).
WithQuery("perPage", perPage).
Expect().
Status(http.StatusOK).
JSON()

return res
}

func IntegrationItemsAsCSV(e *httpexpect.Expect, mId string, page, perPage int, query string, sort, sortDir string, filter map[string]any) *httpexpect.String {
res := e.GET("/api/models/{modelId}/items.csv", mId).
WithHeader("Origin", "https://example.com").
WithHeader("X-Reearth-Debug-User", uId1.String()).
WithHeader("Content-Type", "text/csv").
WithQuery("page", page).
WithQuery("perPage", perPage).
Expect().
Status(http.StatusOK).
Body()

return res
}

func IntegrationItemsWithProjectAsCSV(e *httpexpect.Expect, pId string, mId string, page, perPage int, query string, sort, sortDir string, filter map[string]any) *httpexpect.String {
res := e.GET("/api/projects/{projectIdOrAlias}/models/{modelIdOrKey}/items.csv", pId, mId).
WithHeader("Origin", "https://example.com").
WithHeader("X-Reearth-Debug-User", uId1.String()).
WithHeader("Content-Type", "text/csv").
WithQuery("page", page).
WithQuery("perPage", perPage).
Expect().
Status(http.StatusOK).
Body()

return res
}

// GET /models/{modelId}/items
func TestIntegrationItemListAPI(t *testing.T) {
e := StartServer(t, &app.Config{}, true, baseSeeder)
Expand Down Expand Up @@ -1163,6 +1219,99 @@ func TestIntegrationSearchItem(t *testing.T) {
// endregion
}

// GET /models/{modelId}/items.geojson
func TestIntegrationItemsAsGeoJSON(t *testing.T) {
e, _ := StartGQLServer(t, &app.Config{}, true, baseSeederUser)

pId, _ := createProject(e, wId.String(), "test", "test", "test-1")
mId, _ := createModel(e, pId, "test", "test", "test-1")
fids := createFieldOfEachType(t, e, mId)
sId, _, _ := getModel(e, mId)
i1Id, _ := createItem(e, mId, sId, nil, []map[string]any{
{"schemaFieldId": fids.textFId, "value": "test1", "type": "Text"},
{"schemaFieldId": fids.geometryObjectFid, "value": "{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}", "type": "GeometryObject"},
})

res := IntegrationItemsAsGeoJSON(e, mId, 1, 10, i1Id, "", "", nil)
res.Object().Value("type").String().IsEqual("FeatureCollection")
features := res.Object().Value("features").Array()
features.Length().IsEqual(1)
f := features.Value(0).Object()
f.Value("id").String().IsEqual(i1Id)
f.Value("type").String().IsEqual("Feature")
f.Value("properties").Object().Value("text").String().IsEqual("test1")
g := f.Value("geometry").Object()
g.Value("type").String().IsEqual("Point")
g.Value("coordinates").Array().IsEqual([]float64{139.28179282584915, 36.58570985749664})
}

// GET /projects/{projectIdOrAlias}/models/{modelIdOrKey}/items.geojson
func TestIntegrationItemsWithProjectAsGeoJSON(t *testing.T) {
e, _ := StartGQLServer(t, &app.Config{}, true, baseSeederUser)

pId, _ := createProject(e, wId.String(), "test", "test", "test-1")
mId, _ := createModel(e, pId, "test", "test", "test-1")
fids := createFieldOfEachType(t, e, mId)
sId, _, _ := getModel(e, mId)
i1Id, _ := createItem(e, mId, sId, nil, []map[string]any{
{"schemaFieldId": fids.textFId, "value": "test1", "type": "Text"},
{"schemaFieldId": fids.integerFId, "value": 30, "type": "Integer"},
{"schemaFieldId": fids.geometryObjectFid, "value": "{\"coordinates\":[[139.65439725962517,36.34793305387103],[139.61688622815393,35.910803456352724]],\"type\":\"LineString\"}", "type": "GeometryObject"},
{"schemaFieldId": fids.geometryEditorFid, "value": "{\"coordinates\": [[[138.90306434425662,36.11737907906834],[138.90306434425662,36.33622175736386],[138.67187898370287,36.33622175736386],[138.67187898370287,36.11737907906834],[138.90306434425662,36.11737907906834]]],\"type\": \"Polygon\"}", "type": "GeometryEditor"},
})

res := IntegrationItemsWithProjectAsGeoJSON(e, pId, mId, 1, 10, i1Id, "", "", nil)
res.Object().Value("type").String().IsEqual("FeatureCollection")
features := res.Object().Value("features").Array()
features.Length().IsEqual(1)
f := features.Value(0).Object()
f.Value("id").String().IsEqual(i1Id)
f.Value("type").String().IsEqual("Feature")
f.Value("properties").Object().Value("text").String().IsEqual("test1")
f.Value("properties").Object().Value("integer").Number().IsEqual(30)
g := f.Value("geometry").Object()
g.Value("type").String().IsEqual("LineString")
g.Value("coordinates").Array().IsEqual([][]float64{{139.65439725962517, 36.34793305387103}, {139.61688622815393, 35.910803456352724}})
}

// GET /models/{modelId}/items.csv
func TestIntegrationItemsAsCSV(t *testing.T) {
e, _ := StartGQLServer(t, &app.Config{}, true, baseSeederUser)

pId, _ := createProject(e, wId.String(), "test", "test", "test-1")
mId, _ := createModel(e, pId, "test", "test", "test-1")
fids := createFieldOfEachType(t, e, mId)
sId, _, _ := getModel(e, mId)
i1Id, _ := createItem(e, mId, sId, nil, []map[string]any{
{"schemaFieldId": fids.textFId, "value": "test1", "type": "Text"},
{"schemaFieldId": fids.geometryObjectFid, "value": "{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}", "type": "GeometryObject"},
})

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)
res.IsEqual(expected)
}

// GET /projects/{projectIdOrAlias}/models/{modelIdOrKey}/items.csv
func TestIntegrationItemsWithProjectAsCSV(t *testing.T) {
e, _ := StartGQLServer(t, &app.Config{}, true, baseSeederUser)

pId, _ := createProject(e, wId.String(), "test", "test", "test-1")
mId, _ := createModel(e, pId, "test", "test", "test-1")
fids := createFieldOfEachType(t, e, mId)
sId, _, _ := getModel(e, mId)
i1Id, _ := createItem(e, mId, sId, nil, []map[string]any{
{"schemaFieldId": fids.textFId, "value": "test1", "type": "Text"},
{"schemaFieldId": fids.integerFId, "value": 30, "type": "Integer"},
{"schemaFieldId": fids.geometryObjectFid, "value": "{\"coordinates\":[[139.65439725962517,36.34793305387103],[139.61688622815393,35.910803456352724]],\"type\":\"LineString\"}", "type": "GeometryObject"},
{"schemaFieldId": fids.geometryEditorFid, "value": "{\"coordinates\":[139.28179282584915,36.58570985749664],\"type\":\"Point\"}", "type": "GeometryEditor"},
})

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)
res.IsEqual(expected)
}

// POST /models/{modelId}/items
func TestIntegrationCreateItemAPI(t *testing.T) {
e := StartServer(t, &app.Config{}, true, baseSeeder)
Expand Down
56 changes: 28 additions & 28 deletions server/e2e/integration_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import (

// POST /api/models/{modelId}/fields
func TestIntegrationFieldCreateAPI(t *testing.T) {
endpoint := "/api/models/{modelId}/fields"
endpoint := "/api/schemata/{schemaId}/fields"
e := StartServer(t, &app.Config{}, true, baseSeeder)

e.POST(endpoint, id.NewModelID()).
e.POST(endpoint, id.NewSchemaID()).
Expect().
Status(http.StatusUnauthorized)

e.POST(endpoint, id.NewModelID()).
e.POST(endpoint, id.NewSchemaID()).
WithHeader("authorization", "secret_abc").
Expect().
Status(http.StatusUnauthorized)

e.POST(endpoint, id.NewModelID()).
e.POST(endpoint, id.NewSchemaID()).
WithHeader("authorization", "Bearer secret_abc").
Expect().
Status(http.StatusUnauthorized)

e.POST(endpoint, id.NewModelID()).
e.POST(endpoint, id.NewSchemaID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)
Expand All @@ -38,7 +38,7 @@ func TestIntegrationFieldCreateAPI(t *testing.T) {
Expect().
Status(http.StatusBadRequest)

obj1 := e.POST(endpoint, mId1).
obj1 := e.POST(endpoint, sid1).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"key": "fKey1",
Expand Down Expand Up @@ -72,10 +72,10 @@ func TestIntegrationFieldCreateAPI(t *testing.T) {

// PATCH /api/models/{modelId}/fields/{FieldIdOrKey}
func TestIntegrationFieldUpdateAPI(t *testing.T) {
endpoint := "/api/models/{modelId}/fields/{fieldIdOrKey}"
endpoint := "/api/schemata/{schemaId}/fields/{fieldIdOrKey}"
e := StartServer(t, &app.Config{}, true, baseSeeder)

obj := e.POST("/api/models/{modelId}/fields", mId1).
obj := e.POST("/api/schemata/{schemaId}/fields", sid1).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"key": "fKey1",
Expand All @@ -91,22 +91,22 @@ func TestIntegrationFieldUpdateAPI(t *testing.T) {
Expect().
Status(http.StatusUnauthorized)

e.PATCH(endpoint, id.NewModelID(), id.NewFieldID()).
e.PATCH(endpoint, id.NewSchemaID(), id.NewFieldID()).
WithHeader("authorization", "secret_abc").
Expect().
Status(http.StatusUnauthorized)

e.PATCH(endpoint, id.NewModelID(), id.NewFieldID()).
e.PATCH(endpoint, id.NewSchemaID(), id.NewFieldID()).
WithHeader("authorization", "Bearer secret_abc").
Expect().
Status(http.StatusUnauthorized)

e.PATCH(endpoint, id.NewModelID(), id.NewFieldID()).
e.PATCH(endpoint, id.NewSchemaID(), id.NewFieldID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.PATCH(endpoint, id.NewModelID(), fId).
e.PATCH(endpoint, id.NewSchemaID(), fId).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)
Expand All @@ -117,7 +117,7 @@ func TestIntegrationFieldUpdateAPI(t *testing.T) {
Expect().
Status(http.StatusBadRequest)

e.PATCH(endpoint, mId1, fId).
e.PATCH(endpoint, sid1, fId).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"key": "fKey1Updated",
Expand All @@ -135,7 +135,7 @@ func TestIntegrationFieldUpdateAPI(t *testing.T) {
HasValue("multiple", true).
HasValue("required", true)

e.PATCH(endpoint, mId1, "fKey1Updated").
e.PATCH(endpoint, sid1, "fKey1Updated").
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"key": "fKey1Updated1",
Expand Down Expand Up @@ -174,10 +174,10 @@ func TestIntegrationFieldUpdateAPI(t *testing.T) {

// DELETE /api/models/{modelId}/fields/{FieldIdOrKey}
func TestIntegrationFieldDeleteAPI(t *testing.T) {
endpoint := "/api/models/{modelId}/fields/{fieldIdOrKey}"
endpoint := "/api/schemata/{schemaId}/fields/{fieldIdOrKey}"
e := StartServer(t, &app.Config{}, true, baseSeeder)

obj := e.POST("/api/models/{modelId}/fields", mId1).
obj := e.POST("/api/schemata/{schemaId}/fields", sid1).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"key": "fKey1",
Expand All @@ -189,26 +189,26 @@ func TestIntegrationFieldDeleteAPI(t *testing.T) {
Status(http.StatusOK)
fId := obj.JSON().Object().Value("id").String().Raw()

e.DELETE(endpoint, id.NewModelID(), id.NewFieldID()).
e.DELETE(endpoint, id.NewSchemaID(), id.NewFieldID()).
Expect().
Status(http.StatusUnauthorized)

e.DELETE(endpoint, id.NewModelID(), id.NewFieldID()).
e.DELETE(endpoint, id.NewSchemaID(), id.NewFieldID()).
WithHeader("authorization", "secret_abc").
Expect().
Status(http.StatusUnauthorized)

e.DELETE(endpoint, id.NewModelID(), id.NewFieldID()).
e.DELETE(endpoint, id.NewSchemaID(), id.NewFieldID()).
WithHeader("authorization", "Bearer secret_abc").
Expect().
Status(http.StatusUnauthorized)

e.DELETE(endpoint, id.NewModelID(), id.NewFieldID()).
e.DELETE(endpoint, id.NewSchemaID(), id.NewFieldID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.DELETE(endpoint, id.NewModelID(), fId).
e.DELETE(endpoint, id.NewSchemaID(), fId).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)
Expand All @@ -219,15 +219,15 @@ func TestIntegrationFieldDeleteAPI(t *testing.T) {
Expect().
Status(http.StatusBadRequest)

e.DELETE(endpoint, mId1, fId).
e.DELETE(endpoint, sid1, fId).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
Object().
HasValue("id", fId)

obj = e.POST("/api/models/{modelId}/fields", mId1).
obj = e.POST("/api/schemata/{schemaId}/fields", sid1).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"key": "fKey1",
Expand All @@ -239,7 +239,7 @@ func TestIntegrationFieldDeleteAPI(t *testing.T) {
Status(http.StatusOK)
fId = obj.JSON().Object().Value("id").String().Raw()

e.DELETE(endpoint, mId1, "fKey1").
e.DELETE(endpoint, sid1, "fKey1").
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
Expand Down Expand Up @@ -340,7 +340,7 @@ func TestIntegrationFieldUpdateWithProjectAPI(t *testing.T) {
endpoint := "/api/projects/{projectIdOrAlias}/models/{modelIdOrKey}/fields/{fieldIdOrKey}"
e := StartServer(t, &app.Config{}, true, baseSeeder)

obj := e.POST("/api/models/{modelId}/fields", mId1).
obj := e.POST("/api/schemata/{schemaId}/fields", sid1).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"key": "fKey1",
Expand Down Expand Up @@ -436,7 +436,7 @@ func TestIntegrationFieldDeleteWithProjectAPI(t *testing.T) {
endpoint := "/api/projects/{projectIdOrAlias}/models/{modelIdOrKey}/fields/{fieldIdOrKey}"
e := StartServer(t, &app.Config{}, true, baseSeeder)

obj := e.POST("/api/models/{modelId}/fields", mId1).
obj := e.POST("/api/schemata/{schemaId}/fields", sid1).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"key": "fKey1",
Expand Down Expand Up @@ -480,7 +480,7 @@ func TestIntegrationFieldDeleteWithProjectAPI(t *testing.T) {
Object().
HasValue("id", fId)

obj = e.POST("/api/models/{modelId}/fields", mId1).
obj = e.POST("/api/schemata/{schemaId}/fields", sid1).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"key": "fKey1",
Expand All @@ -500,7 +500,7 @@ func TestIntegrationFieldDeleteWithProjectAPI(t *testing.T) {
Object().
HasValue("id", fId)

obj = e.POST("/api/models/{modelId}/fields", mId1).
obj = e.POST("/api/schemata/{schemaId}/fields", sid1).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"key": "fKey1",
Expand Down
Loading

0 comments on commit 74e666f

Please sign in to comment.