Skip to content

Commit

Permalink
feat(server): add coreSupport flag to project (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
yk-eukarya committed May 25, 2023
1 parent 7604be6 commit dacc3d4
Show file tree
Hide file tree
Showing 18 changed files with 450 additions and 13 deletions.
6 changes: 6 additions & 0 deletions server/e2e/common.go
Expand Up @@ -91,3 +91,9 @@ func StartServerWithRepos(t *testing.T, cfg *app.Config, repos *repo.Container)

return httpexpect.New(t, "http://"+l.Addr().String())
}

type GraphQLRequest struct {
OperationName string `json:"operationName"`
Query string `json:"query"`
Variables map[string]any `json:"variables"`
}
40 changes: 40 additions & 0 deletions server/e2e/gql_me_test.go
@@ -0,0 +1,40 @@
package e2e

import (
"net/http"
"testing"

"github.com/reearth/reearth/server/internal/app"
)

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

requestBody := GraphQLRequest{
OperationName: "GetMe",
Query: "query GetMe { \n me { \n id \n name \n email\n } \n}",
Variables: map[string]any{},
}

e.POST("/api/graphql").
WithHeader("Origin", "https://example.com").
// WithHeader("authorization", "Bearer test").
WithHeader("X-Reearth-Debug-User", uId.String()).
WithHeader("Content-Type", "application/json").
WithJSON(requestBody).
Expect().
Status(http.StatusOK).
JSON().
Object().
Value("data").Object().
Value("me").Object().
ValueEqual("email", uEmail).
ValueEqual("id", uId.String()).
ValueEqual("name", uName)
}
83 changes: 83 additions & 0 deletions server/e2e/gql_project_test.go
@@ -0,0 +1,83 @@
package e2e

import (
"net/http"
"testing"

"github.com/reearth/reearth/server/internal/app"
)

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

// create project with default coreSupport value (false)
requestBody := GraphQLRequest{
OperationName: "CreateProject",
Query: "mutation CreateProject($teamId: ID!, $visualizer: Visualizer!, $name: String!, $description: String!, $imageUrl: URL) {\n createProject(\n input: {teamId: $teamId, visualizer: $visualizer, name: $name, description: $description, imageUrl: $imageUrl}\n ) {\n project {\n id\n name\n description\n imageUrl\n coreSupport\n __typename\n }\n __typename\n }\n}",
Variables: map[string]any{
"name": "test",
"description": "abc",
"imageUrl": "",
"teamId": wId.String(),
"visualizer": "CESIUM",
},
}

e.POST("/api/graphql").
WithHeader("Origin", "https://example.com").
// WithHeader("authorization", "Bearer test").
WithHeader("X-Reearth-Debug-User", uId.String()).
WithHeader("Content-Type", "application/json").
WithJSON(requestBody).
Expect().
Status(http.StatusOK).
JSON().
Object().
Value("data").Object().
Value("createProject").Object().
Value("project").Object().
// ValueEqual("id", pId.String()).
ValueEqual("name", "test").
ValueEqual("description", "abc").
ValueEqual("imageUrl", "").
ValueEqual("coreSupport", false)

// create coreSupport project
requestBody = GraphQLRequest{
OperationName: "CreateProject",
Query: "mutation CreateProject($teamId: ID!, $visualizer: Visualizer!, $name: String!, $description: String!, $imageUrl: URL, $coreSupport: Boolean) {\n createProject(\n input: {teamId: $teamId, visualizer: $visualizer, name: $name, description: $description, imageUrl: $imageUrl, coreSupport: $coreSupport}\n ) {\n project {\n id\n name\n description\n imageUrl\n coreSupport\n __typename\n }\n __typename\n }\n}",
Variables: map[string]any{
"name": "test",
"description": "abc",
"imageUrl": "",
"teamId": wId.String(),
"visualizer": "CESIUM",
"coreSupport": true,
},
}

e.POST("/api/graphql").
WithHeader("Origin", "https://example.com").
// WithHeader("authorization", "Bearer test").
WithHeader("X-Reearth-Debug-User", uId.String()).
WithHeader("Content-Type", "application/json").
WithJSON(requestBody).
Expect().
Status(http.StatusOK).
JSON().
Object().
Value("data").Object().
Value("createProject").Object().
Value("project").Object().
// ValueEqual("id", pId.String()).
ValueEqual("name", "test").
ValueEqual("description", "abc").
ValueEqual("imageUrl", "").
ValueEqual("coreSupport", true)
}
6 changes: 4 additions & 2 deletions server/e2e/seeder.go
Expand Up @@ -17,6 +17,8 @@ import (

var (
uId = user.NewID()
uEmail = "e2e@e2e.com"
uName = "e2e"
wId = workspace.NewID()
pId = id.NewProjectID()
pAlias = "PROJECT_ALIAS"
Expand All @@ -33,8 +35,8 @@ func baseSeeder(ctx context.Context, r *repo.Container) error {
u := user.New().
ID(uId).
Workspace(wId).
Name("e2e").
Email("e2e@e2e.com").
Name(uName).
Email(uEmail).
MustBuild()
if err := r.User.Save(ctx, u); err != nil {
return err
Expand Down
79 changes: 78 additions & 1 deletion server/internal/adapter/gql/generated.go

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

1 change: 1 addition & 0 deletions server/internal/adapter/gql/gqlmodel/convert_project.go
Expand Up @@ -60,5 +60,6 @@ func ToProject(p *project.Project) *Project {
PublicDescription: p.PublicDescription(),
PublicImage: p.PublicImage(),
PublicNoIndex: p.PublicNoIndex(),
CoreSupport: p.CoreSupport(),
}
}

0 comments on commit dacc3d4

Please sign in to comment.