Skip to content

Commit ba9a2e3

Browse files
author
reearth-app[bot]
committed
Merge branch 'main' into release
2 parents bee7b81 + 69c3c22 commit ba9a2e3

File tree

374 files changed

+11208
-5583
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

374 files changed

+11208
-5583
lines changed

server/.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ REEARTH_COGNITO_REGION=
2323
REEARTH_COGNITO_USERPOOLID=
2424
REEARTH_COGNITO_CLIENTID=
2525

26+
# Local Mock Auth
27+
REEARTH_MOCKAUTH=
28+
2629
# Auth client
2730
#REEARTH_AUTH_ISS=https://hoge.com
2831
#REEARTH_AUTH_AUD=https://api.reearth.example.com

server/Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ help:
1313
@echo " run-app Run the application"
1414
@echo " run-db Run the MongoDB database using Docker Compose"
1515
@echo " gql Generate GraphQL code"
16+
@echo " mockuser Create a mock user by executing a curl request"
1617

1718
lint:
1819
golangci-lint run --fix
@@ -38,4 +39,7 @@ run-db:
3839
gql:
3940
go generate ./internal/adapter/gql
4041

41-
.PHONY: lint test failcheck e2e build run-app run-db gql
42+
mockuser:
43+
curl -H 'Content-Type: application/json' -d '{"email": "[email protected]", "username": "Mock User"}' http://localhost:8080/api/signup
44+
45+
.PHONY: lint test failcheck e2e build run-app run-db gql mockuser

server/e2e/gql_project_test.go

+99-3
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,15 @@ func TestFindStarredByWorkspace(t *testing.T) {
210210
project2ID := createProject(e, "Project 2")
211211
project3ID := createProject(e, "Project 3")
212212
project4ID := createProject(e, "Project 4")
213+
project5ID := createProject(e, "Project 5")
213214

214215
starProject(e, project1ID)
215216
starProject(e, project3ID)
216217

218+
// star and deleted 'Project 5'
219+
starProject(e, project5ID)
220+
deleteProject(e, project5ID)
221+
217222
requestBody := GraphQLRequest{
218223
OperationName: "GetStarredProjects",
219224
Query: `
@@ -251,6 +256,8 @@ func TestFindStarredByWorkspace(t *testing.T) {
251256
nodeCount := int(nodes.Length().Raw())
252257
assert.Equal(t, 2, nodeCount, "Expected 2 nodes in the response")
253258

259+
nodes.Length().Equal(2) // 'Project 1' and 'Project 3'
260+
254261
starredProjectsMap := make(map[string]bool)
255262
for _, node := range nodes.Iter() {
256263
obj := node.Object()
@@ -275,7 +282,6 @@ func TestFindStarredByWorkspace(t *testing.T) {
275282
assert.True(t, starredProjectsMap[project3ID], "Project 3 should be starred")
276283
assert.False(t, starredProjectsMap[project2ID], "Project 2 should not be starred")
277284
assert.False(t, starredProjectsMap[project4ID], "Project 4 should not be starred")
278-
279285
}
280286

281287
func starProject(e *httpexpect.Expect, projectID string) {
@@ -449,6 +455,96 @@ func TestSortByUpdatedAt(t *testing.T) {
449455

450456
edges.Length().Equal(3)
451457
edges.Element(0).Object().Value("node").Object().Value("name").Equal("project2-test") // 'project2' is first
452-
edges.Element(1).Object().Value("node").Object().Value("name").Equal("project3-test")
453-
edges.Element(2).Object().Value("node").Object().Value("name").Equal("project1-test")
458+
}
459+
460+
// go test -v -run TestDeleteProjects ./e2e/...
461+
462+
func TestDeleteProjects(t *testing.T) {
463+
464+
e := StartServer(t, &config.Config{
465+
Origins: []string{"https://example.com"},
466+
AuthSrv: config.AuthSrvConfig{
467+
Disabled: true,
468+
},
469+
}, true, baseSeeder)
470+
471+
createProject(e, "project1-test")
472+
project2ID := createProject(e, "project2-test")
473+
createProject(e, "project3-test")
474+
475+
// Deleted 'project2'
476+
deleteProject(e, project2ID)
477+
478+
// check
479+
requestBody := GraphQLRequest{
480+
OperationName: "GetDeletedProjects",
481+
Query: `
482+
query GetDeletedProjects($teamId: ID!) {
483+
deletedProjects(teamId: $teamId) {
484+
nodes {
485+
id
486+
name
487+
isDeleted
488+
}
489+
totalCount
490+
}
491+
}`,
492+
Variables: map[string]any{
493+
"teamId": wID,
494+
},
495+
}
496+
deletedProjects := e.POST("/api/graphql").
497+
WithHeader("Origin", "https://example.com").
498+
WithHeader("X-Reearth-Debug-User", uID.String()).
499+
WithHeader("Content-Type", "application/json").
500+
WithJSON(requestBody).
501+
Expect().
502+
Status(http.StatusOK).
503+
JSON().
504+
Object().Value("data").Object().Value("deletedProjects").Object()
505+
506+
deletedProjects.Value("totalCount").Equal(1)
507+
deletedProjects.Value("nodes").Array().Length().Equal(1)
508+
deletedProjects.Value("nodes").Array().First().Object().Value("name").Equal("project2-test")
509+
}
510+
511+
func deleteProject(e *httpexpect.Expect, projectID string) {
512+
513+
updateProjectMutation := GraphQLRequest{
514+
OperationName: "UpdateProject",
515+
Query: `mutation UpdateProject($input: UpdateProjectInput!) {
516+
updateProject(input: $input) {
517+
project {
518+
id
519+
name
520+
isDeleted
521+
updatedAt
522+
__typename
523+
}
524+
__typename
525+
}
526+
}`,
527+
Variables: map[string]any{
528+
"input": map[string]any{
529+
"projectId": projectID,
530+
"deleted": true,
531+
},
532+
},
533+
}
534+
535+
response := e.POST("/api/graphql").
536+
WithHeader("Origin", "https://example.com").
537+
WithHeader("X-Reearth-Debug-User", uID.String()).
538+
WithHeader("Content-Type", "application/json").
539+
WithJSON(updateProjectMutation).
540+
Expect().
541+
Status(http.StatusOK).
542+
JSON().
543+
Object().
544+
Value("data").Object().
545+
Value("updateProject").Object().
546+
Value("project").Object()
547+
548+
response.ValueEqual("id", projectID).
549+
ValueEqual("isDeleted", true)
454550
}

server/e2e/gql_storytelling_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ func TestStoryPublishing(t *testing.T) {
10481048
_, err = buf.ReadFrom(rc)
10491049
assert.NoError(t, err)
10501050

1051-
pub := regexp.MustCompile(fmt.Sprintf(`{"schemaVersion":1,"id":"%s","publishedAt":".*","property":{"tiles":\[{"id":".*"}]},"plugins":{},"layers":null,"widgets":\[],"widgetAlignSystem":null,"tags":\[],"clusters":\[],"story":{"id":"%s","property":{},"pages":\[{"id":"%s","property":{},"title":"test","blocks":\[{"id":"%s","property":{"default":{"text":"test value"},"panel":{"padding":{"top":2,"bottom":3,"left":0,"right":1}}},"plugins":null,"extensionId":"%s","pluginId":"%s"}],"swipeable":true,"swipeableLayers":\[],"layers":\[]}],"position":"left","bgColor":""},"nlsLayers":null,"layerStyles":null,"coreSupport":true,"enableGa":false,"trackingId":""}`, sID, storyID, pageID, blockID, extensionId, pluginId))
1051+
pub := regexp.MustCompile(fmt.Sprintf(`{"schemaVersion":1,"id":"%s","publishedAt":".*","property":{"tiles":\[{"id":".*"}]},"plugins":{},"layers":null,"widgets":\[],"widgetAlignSystem":null,"tags":\[],"clusters":\[],"story":{"id":"%s","title":"","property":{},"pages":\[{"id":"%s","property":{},"title":"test","blocks":\[{"id":"%s","property":{"default":{"text":"test value"},"panel":{"padding":{"top":2,"bottom":3,"left":0,"right":1}}},"plugins":null,"extensionId":"%s","pluginId":"%s"}],"swipeable":true,"swipeableLayers":\[],"layers":\[]}],"position":"left","bgColor":""},"nlsLayers":null,"layerStyles":null,"coreSupport":true,"enableGa":false,"trackingId":""}`, sID, storyID, pageID, blockID, extensionId, pluginId))
10521052
assert.Regexp(t, pub, buf.String())
10531053

10541054
resString := e.GET("/p/test-alias/data.json").

server/e2e/mock_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package e2e
2+
3+
import (
4+
"net/http"
5+
"testing"
6+
7+
"github.com/reearth/reearth/server/internal/app/config"
8+
)
9+
10+
// go test -v -run TestMockAuth ./e2e/...
11+
12+
func TestMockAuth(t *testing.T) {
13+
e := StartServer(t, &config.Config{
14+
Dev: true,
15+
MockAuth: true,
16+
Origins: []string{"https://example.com"},
17+
AuthSrv: config.AuthSrvConfig{
18+
Disabled: true,
19+
},
20+
}, true, nil)
21+
22+
requestBody := map[string]interface{}{
23+
"email": "[email protected]",
24+
"username": "Mock User",
25+
}
26+
27+
response := e.POST("/api/signup").
28+
WithJSON(requestBody).
29+
Expect().
30+
Status(http.StatusOK).
31+
JSON()
32+
33+
response.Object().ContainsKey("id")
34+
response.Object().ValueEqual("email", "[email protected]")
35+
response.Object().ValueEqual("name", "Mock User")
36+
userId := response.Object().Value("id").String().Raw()
37+
38+
// checkj query GetMe
39+
requestBody2 := GraphQLRequest{
40+
OperationName: "GetMe",
41+
Query: "query GetMe { \n me { \n id \n name \n email\n } \n}",
42+
Variables: map[string]any{},
43+
}
44+
response2 := e.POST("/api/graphql").
45+
WithHeader("Origin", "https://example.com").
46+
WithHeader("X-Reearth-Debug-User", userId).
47+
WithHeader("Content-Type", "application/json").
48+
WithJSON(requestBody2).
49+
Expect().
50+
Status(http.StatusOK).
51+
JSON().
52+
Object()
53+
54+
response2.Value("data").Object().Value("me").Object().ContainsKey("id")
55+
response2.Value("data").Object().Value("me").Object().Value("name").String().Equal("Mock User")
56+
response2.Value("data").Object().Value("me").Object().Value("email").String().Equal("[email protected]")
57+
}

server/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/paulmach/go.geojson v1.4.0
2727
github.com/pkg/errors v0.9.1
2828
github.com/ravilushqa/otelgqlgen v0.15.0
29-
github.com/reearth/reearthx v0.0.0-20240809105752-94879dbf747b
29+
github.com/reearth/reearthx v0.0.0-20241016122433-351e92319d1c
3030
github.com/samber/lo v1.39.0
3131
github.com/spf13/afero v1.11.0
3232
github.com/square/mongo-lock v0.0.0-20201208161834-4db518ed7fb2

server/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
509509
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
510510
github.com/ravilushqa/otelgqlgen v0.15.0 h1:U85nrlweMXTGaMChUViYM39/MXBZVeVVlpuHq+6eECQ=
511511
github.com/ravilushqa/otelgqlgen v0.15.0/go.mod h1:o+1Eju0VySmgq2BP8Vupz2YrN21Bj7D7imBqu3m2uB8=
512-
github.com/reearth/reearthx v0.0.0-20240809105752-94879dbf747b h1:Vt1oXaj7pntxlQoKi/zJwvMHovlM86sYweOOx2rlH7Q=
513-
github.com/reearth/reearthx v0.0.0-20240809105752-94879dbf747b/go.mod h1:d1WXkdCVzSoc8pl3vW9/9yKfk4fdoZQZhX8Ot8jqgnc=
512+
github.com/reearth/reearthx v0.0.0-20241016122433-351e92319d1c h1:T9gk3oxbgGsb8SasgjDpwtoxB/T8rdHbGUGymNhAvfc=
513+
github.com/reearth/reearthx v0.0.0-20241016122433-351e92319d1c/go.mod h1:d1WXkdCVzSoc8pl3vW9/9yKfk4fdoZQZhX8Ot8jqgnc=
514514
github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C9WhFzY47SzYBIvzFqSvHIR6ROgDo4TtdTuRaOMjF/s=
515515
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
516516
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

server/gql/project.graphql

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Project implements Node {
2424
enableGa: Boolean!
2525
trackingId: String!
2626
starred: Boolean!
27+
isDeleted: Boolean!
2728
}
2829

2930
type ProjectAliasAvailability {
@@ -80,6 +81,7 @@ input UpdateProjectInput {
8081
trackingId: String
8182
sceneId: ID
8283
starred: Boolean
84+
deleted: Boolean
8385
}
8486

8587
input PublishProjectInput {
@@ -102,6 +104,7 @@ input ExportProjectInput {
102104
}
103105

104106
input ImportProjectInput {
107+
teamId: ID!
105108
file: Upload!
106109
}
107110

@@ -140,13 +143,13 @@ type ProjectEdge {
140143
extend type Query {
141144
projects(
142145
teamId: ID!
143-
includeArchived: Boolean
144146
pagination: Pagination
145147
keyword: String
146148
sort: ProjectSort
147-
): ProjectConnection!
149+
): ProjectConnection! # not included deleted projects
148150
checkProjectAlias(alias: String!): ProjectAliasAvailability!
149151
starredProjects(teamId: ID!): ProjectConnection!
152+
deletedProjects(teamId: ID!): ProjectConnection!
150153
}
151154

152155
extend type Mutation {

server/internal/adapter/context.go

+21
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
contextOperator ContextKey = "operator"
1919
ContextAuthInfo ContextKey = "authinfo"
2020
contextUsecases ContextKey = "usecases"
21+
contextMockAuth ContextKey = "mockauth"
2122
)
2223

2324
var defaultLang = language.English
@@ -44,6 +45,10 @@ func AttachUsecases(ctx context.Context, u *interfaces.Container) context.Contex
4445
return ctx
4546
}
4647

48+
func AttachMockAuth(ctx context.Context, mockAuth bool) context.Context {
49+
return context.WithValue(ctx, contextMockAuth, mockAuth)
50+
}
51+
4752
func User(ctx context.Context) *user.User {
4853
if v := ctx.Value(contextUser); v != nil {
4954
if u, ok := v.(*user.User); ok {
@@ -90,6 +95,13 @@ func AcOperator(ctx context.Context) *accountusecase.Operator {
9095
}
9196

9297
func GetAuthInfo(ctx context.Context) *appx.AuthInfo {
98+
if IsMockAuth(ctx) {
99+
return &appx.AuthInfo{
100+
Sub: user.NewID().String(), // Use it if there is a Mock user in the DB
101+
Name: "Mock User",
102+
103+
}
104+
}
93105
if v := ctx.Value(ContextAuthInfo); v != nil {
94106
if v2, ok := v.(appx.AuthInfo); ok {
95107
return &v2
@@ -101,3 +113,12 @@ func GetAuthInfo(ctx context.Context) *appx.AuthInfo {
101113
func Usecases(ctx context.Context) *interfaces.Container {
102114
return ctx.Value(contextUsecases).(*interfaces.Container)
103115
}
116+
117+
func IsMockAuth(ctx context.Context) bool {
118+
if v := ctx.Value(contextMockAuth); v != nil {
119+
if mockAuth, ok := v.(bool); ok {
120+
return mockAuth
121+
}
122+
}
123+
return false
124+
}

0 commit comments

Comments
 (0)