Skip to content

Commit

Permalink
Merge branch 'main' into chore/add-timeline-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
airslice committed Oct 11, 2023
2 parents 4c033ce + 0853baf commit f8e0ece
Show file tree
Hide file tree
Showing 32 changed files with 1,253 additions and 722 deletions.
15 changes: 10 additions & 5 deletions server/e2e/gql_nlslayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ func updateNLSLayer(e *httpexpect.Expect, layerId string) (GraphQLRequest, *http
"disableTypeConversion": true,
},
},
"properties": "sampleProperties",
"defines": map[string]string{
"defineKey": "defineValue",
},
"events": "sampleEvents",
},
},
}
Expand Down Expand Up @@ -239,6 +234,16 @@ func TestNLSLayerCRUD(t *testing.T) {
Value("data").Object().
Value("value").Equal("secondSampleValue")

// Additional check to ensure 'properties' and 'events' are present
res3.Object().
Value("data").Object().
Value("node").Object().
Value("newLayers").Array().First().Object().
Value("config").Object().
ContainsKey("properties").
ContainsKey("events").
ContainsKey("defines")

// Save current config before update
savedConfig := res3.Object().
Value("data").Object().
Expand Down
202 changes: 202 additions & 0 deletions server/e2e/gql_style_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
package e2e

import (
"net/http"
"testing"

"github.com/gavv/httpexpect/v2"
"github.com/reearth/reearth/server/internal/app/config"
)

func addStyle(e *httpexpect.Expect, sId, name string) (GraphQLRequest, *httpexpect.Value, string) {
requestBody := GraphQLRequest{
OperationName: "AddStyle",
Query: `mutation AddStyle( $sceneId: ID!, $name: String!, $value: JSON!) {
addStyle(input: { sceneId: $sceneId, name: $name, value: $value}) {
style {
id
sceneId
name
value
}
}
}`,
Variables: map[string]any{
"sceneId": sId,
"name": name,
"value": map[string]any{
"type": "ExampleType",
"url": "https://example.com/data",
"value": "sampleValue",
"layers": "sampleLayerData",
"jsonProperties": []string{"prop1", "prop2"},
"updateInterval": 10,
"parameters": map[string]any{
"sampleKey": "sampleValue",
},
"time": map[string]any{
"property": "time",
"interval": 5,
"updateClockOnLoad": true,
},
"csv": map[string]any{
"idColumn": "id",
"latColumn": "latitude",
"lngColumn": "longitude",
"heightColumn": "height",
"noHeader": false,
"disableTypeConversion": true,
},
},
},
}

res := e.POST("/api/graphql").
WithHeader("Content-Type", "application/json").
WithJSON(requestBody).
Expect().
Status(http.StatusOK).
JSON()

styleId := res.Path("$.data.addStyle.style.id").String().Raw()
return requestBody, res, styleId
}

func updateStyleName(e *httpexpect.Expect, styleId, newName string) (GraphQLRequest, *httpexpect.Value) {
requestBody := GraphQLRequest{
OperationName: "UpdateStyle",
Query: `mutation UpdateStyle($styleId: ID!, $name: String) {
updateStyle(input: {styleId: $styleId, name: $name}) {
style {
id
name
value
}
}
}`,
Variables: map[string]any{
"styleId": styleId,
"name": newName,
},
}

res := e.POST("/api/graphql").
WithHeader("Content-Type", "application/json").
WithJSON(requestBody).
Expect().
Status(http.StatusOK).
JSON()

return requestBody, res
}

func removeStyle(e *httpexpect.Expect, styleId string) (GraphQLRequest, *httpexpect.Value) {
requestBody := GraphQLRequest{
OperationName: "RemoveStyle",
Query: `mutation RemoveStyle($styleId: ID!) {
removeStyle(input: {styleId: $styleId}) {
styleId
}
}`,
Variables: map[string]any{
"styleId": styleId,
},
}

res := e.POST("/api/graphql").
WithHeader("Content-Type", "application/json").
WithJSON(requestBody).
Expect().
Status(http.StatusOK).
JSON()

return requestBody, res
}

func fetchSceneForStyles(e *httpexpect.Expect, sID string) (GraphQLRequest, *httpexpect.Value) {
fetchSceneRequestBody := GraphQLRequest{
OperationName: "GetScene",
Query: `query GetScene($sceneId: ID!) {
node(id: $sceneId, type: SCENE) {
id
... on Scene {
styles {
id
name
value
}
__typename
}
__typename
}
}`,
Variables: map[string]any{
"sceneId": sID,
},
}

res := e.POST("/api/graphql").
WithHeader("Origin", "https://example.com").
WithHeader("X-Reearth-Debug-User", uID.String()).
WithHeader("Content-Type", "application/json").
WithJSON(fetchSceneRequestBody).
Expect().
Status(http.StatusOK).
JSON()

return fetchSceneRequestBody, res
}

func TestStyleCRUD(t *testing.T) {
e := StartServer(t, &config.Config{
Origins: []string{"https://example.com"},
AuthSrv: config.AuthSrvConfig{
Disabled: true,
},
}, true, baseSeeder)

pId := createProject(e)
_, _, sId := createScene(e, pId)

// fetch scene
_, res := fetchSceneForStyles(e, sId)

res.Object().
Value("data").Object().
Value("node").Object().
Value("styles").Array().
Length().Equal(0)

// Add NLSLayer
_, _, styleId := addStyle(e, sId, "MyStyle")

_, res2 := fetchSceneForStyles(e, sId)

res2.Object().
Value("data").Object().
Value("node").Object().
Value("styles").Array().
Length().Equal(1)

// Update NLSLayer
_, _ = updateStyleName(e, styleId, "NewName")

_, res3 := fetchSceneForStyles(e, sId)

res3.Object().
Value("data").Object().
Value("node").Object().
Value("styles").Array().First().Object().
Value("name").Equal("NewName")

// Remove NLSLayer
_, _ = removeStyle(e, styleId)

_, res4 := fetchSceneForStyles(e, sId)

res4.Object().
Value("data").Object().
Value("node").Object().
Value("styles").Array().
Length().Equal(0)
}
17 changes: 7 additions & 10 deletions server/gql/style.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ type Style {
id: ID!
name: String!
value: JSON!
sceneId: ID!
scene: Scene
}

# InputType
Expand All @@ -13,32 +15,27 @@ input AddStyleInput {
}

input UpdateStyleInput {
StyleId: ID!
sceneId: ID!
styleId: ID!
name: String
value: JSON
}

input RemoveStyleInput {
StyleId: ID!
sceneId: ID!
styleId: ID!
}

# Payload

type AddStylePayload {
scene: Scene!
Style: Style!
style: Style!
}

type UpdateStylePayload {
scene: Scene!
Style: Style!
style: Style!
}

type RemoveStylePayload {
scene: Scene!
StyleId: ID!
styleId: ID!
}

#extend type Query{ }
Expand Down
6 changes: 6 additions & 0 deletions server/gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ models:
resolver: true
stories:
resolver: true
styles:
resolver: true
SceneWidget:
fields:
plugin:
Expand Down Expand Up @@ -397,6 +399,10 @@ models:
scene:
resolver: true
NLSLayerGroup:
fields:
scene:
resolver: true
Style:
fields:
scene:
resolver: true
Loading

0 comments on commit f8e0ece

Please sign in to comment.