Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
reearth-app[bot] committed Sep 2, 2024
2 parents 622138e + 4e8cec9 commit 8fddf3a
Show file tree
Hide file tree
Showing 789 changed files with 15,899 additions and 19,250 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,3 @@ jobs:
test-results/
if-no-files-found: ignore
retention-days: 7
slack-notification:
if: success() || failure()
name: Slack Notification
needs:
- e2e
runs-on: ubuntu-latest
steps:
- name: Slack Notification
uses: Gamesight/slack-workflow-status@master
if: always()
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
4 changes: 3 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"golang.go",
"redhat.vscode-yaml"
"redhat.vscode-yaml",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
Expand Down
29 changes: 21 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"go.testEnvFile": "${workspaceRoot}/.env",
"go.lintTool": "golangci-lint",
"editor.formatOnSave": true,
"yaml.format.enable": false,
"yaml.completion": true,
"yaml.validate": true,
Expand All @@ -17,20 +16,34 @@
},
"json.schemas": [
{
"fileMatch": [
"/server/pkg/builtin/manifest.json"
],
"fileMatch": ["/server/pkg/builtin/manifest.json"],
"url": "./server/schemas/plugin_manifest.json"
},
{
"fileMatch": [
"/server/pkg/builtin/manifest_*.json"
],
"fileMatch": ["/server/pkg/builtin/manifest_*.json"],
"url": "./server/schemas/plugin_manifest_translation.json"
}
],
"[yaml]": {
"editor.formatOnSave": false
},
"prettier.enable": false
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"editor.formatOnSave": true,
"eslint.enable": true,
"eslint.useFlatConfig": true,
"prettier.enable": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
13 changes: 13 additions & 0 deletions server/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
help:
@echo "Usage:"
@echo " make <target>"
@echo ""
@echo "Targets:"
@echo " lint Run golangci-lint with auto-fix"
@echo " test Run unit tests with race detector in short mode"
@echo " e2e Run end-to-end tests"
@echo " build Build the project"
@echo " run-app Run the application"
@echo " run-db Run the MongoDB database using Docker Compose"
@echo " gql Generate GraphQL code"

lint:
golangci-lint run --fix

Expand Down
257 changes: 257 additions & 0 deletions server/e2e/gql_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"net/http"
"testing"

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

func TestCreateProject(t *testing.T) {
Expand Down Expand Up @@ -195,3 +197,258 @@ func TestSortByName(t *testing.T) {
edges.Element(3).Object().Value("node").Object().Value("name").Equal("B-project")
edges.Element(4).Object().Value("node").Object().Value("name").Equal(seedProjectName)
}

func TestFindStarredByWorkspace(t *testing.T) {

e := StartServer(t, &config.Config{
Origins: []string{"https://example.com"},
AuthSrv: config.AuthSrvConfig{
Disabled: true,
},
}, true, baseSeeder)
project1ID := createProject(e, "Project 1")
project2ID := createProject(e, "Project 2")
project3ID := createProject(e, "Project 3")
project4ID := createProject(e, "Project 4")

starProject(e, project1ID)
starProject(e, project3ID)

requestBody := GraphQLRequest{
OperationName: "GetStarredProjects",
Query: `
query GetStarredProjects($teamId: ID!) {
starredProjects(teamId: $teamId) {
nodes {
id
name
starred
}
totalCount
}
}`,
Variables: map[string]any{
"teamId": wID,
},
}

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

starredProjects := response.Value("data").Object().Value("starredProjects").Object()

totalCount := starredProjects.Value("totalCount").Raw()
assert.Equal(t, float64(2), totalCount, "Expected 2 starred projects")

nodes := starredProjects.Value("nodes").Array()
nodeCount := int(nodes.Length().Raw())
assert.Equal(t, 2, nodeCount, "Expected 2 nodes in the response")

starredProjectsMap := make(map[string]bool)
for _, node := range nodes.Iter() {
obj := node.Object()
id := obj.Value("id").String().Raw()
name := obj.Value("name").String().Raw()
starred := obj.Value("starred").Boolean().Raw()

starredProjectsMap[id] = true

if id == project1ID {
assert.Equal(t, "Project 1", name)
assert.True(t, starred)
} else if id == project3ID {
assert.Equal(t, "Project 3", name)
assert.True(t, starred)
} else {
t.Errorf("Unexpected project in starred projects: %s", id)
}
}

assert.True(t, starredProjectsMap[project1ID], "Project 1 should be starred")
assert.True(t, starredProjectsMap[project3ID], "Project 3 should be starred")
assert.False(t, starredProjectsMap[project2ID], "Project 2 should not be starred")
assert.False(t, starredProjectsMap[project4ID], "Project 4 should not be starred")

}

func starProject(e *httpexpect.Expect, projectID string) {
updateProjectMutation := GraphQLRequest{
OperationName: "UpdateProject",
Query: `
mutation UpdateProject($projectId: ID!, $starred: Boolean!) {
updateProject(input: {projectId: $projectId, starred: $starred}) {
project {
id
starred
}
}
}`,
Variables: map[string]any{
"projectId": projectID,
"starred": true,
},
}

response := e.POST("/api/graphql").
WithHeader("Origin", "https://example.com").
WithHeader("X-Reearth-Debug-User", uID.String()).
WithHeader("Content-Type", "application/json").
WithJSON(updateProjectMutation).
Expect().
Status(http.StatusOK).
JSON().
Object().
Value("data").Object().
Value("updateProject").Object().
Value("project").Object()

response.ValueEqual("id", projectID).
ValueEqual("starred", true)
}

func TestSortByUpdatedAt(t *testing.T) {

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

createProject(e, "project1-test")
project2ID := createProject(e, "project2-test")
createProject(e, "project3-test")

requestBody := GraphQLRequest{
OperationName: "UpdateProject",
Query: `mutation UpdateProject($input: UpdateProjectInput!) {
updateProject(input: $input) {
project {
id
name
description
updatedAt
__typename
}
__typename
}
}`,
Variables: map[string]any{
"input": map[string]any{
"projectId": project2ID,
"description": "test updaet",
},
},
}

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

requestBody = GraphQLRequest{
OperationName: "GetProjects",
Query: `
query GetProjects($teamId: ID!, $pagination: Pagination, $keyword: String, $sort: ProjectSort) {
projects(
teamId: $teamId
pagination: $pagination
keyword: $keyword
sort: $sort
) {
edges {
node {
id
...ProjectFragment
scene {
id
__typename
}
__typename
}
__typename
}
nodes {
id
...ProjectFragment
scene {
id
__typename
}
__typename
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
__typename
}
totalCount
__typename
}
}
fragment ProjectFragment on Project {
id
name
description
imageUrl
isArchived
isBasicAuthActive
basicAuthUsername
basicAuthPassword
publicTitle
publicDescription
publicImage
alias
enableGa
trackingId
publishmentStatus
updatedAt
createdAt
coreSupport
starred
__typename
}`,
Variables: map[string]any{
"pagination": map[string]any{
"first": 3, // Get first 3 itme
},
"teamId": wID.String(),
"sort": map[string]string{
"field": "UPDATEDAT",
"direction": "DESC", // Sort DESC by UPDATEDAT
},
},
}

edges := e.POST("/api/graphql").
WithHeader("Origin", "https://example.com").
WithHeader("X-Reearth-Debug-User", uID.String()).
WithHeader("Content-Type", "application/json").
WithJSON(requestBody).
Expect().
Status(http.StatusOK).
JSON().
Object().
Value("data").Object().
Value("projects").Object().
Value("edges").Array()

edges.Length().Equal(3)
edges.Element(0).Object().Value("node").Object().Value("name").Equal("project2-test") // 'project2' is first
edges.Element(1).Object().Value("node").Object().Value("name").Equal("project3-test")
edges.Element(2).Object().Value("node").Object().Value("name").Equal("project1-test")
}
1 change: 1 addition & 0 deletions server/gql/project.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type ProjectEdge {
extend type Query{
projects(teamId: ID!, includeArchived: Boolean, pagination: Pagination, keyword: String, sort: ProjectSort): ProjectConnection!
checkProjectAlias(alias: String!): ProjectAliasAvailability!
starredProjects(teamId: ID!): ProjectConnection!
}

extend type Mutation {
Expand Down
3 changes: 3 additions & 0 deletions server/gql/workspace.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type Policy {
assetStorageSize: FileSize
datasetSchemaCount: Int
datasetCount: Int
nlsLayersCount: Int
pageCount: Int
blocksCount: Int
}

enum Role {
Expand Down
Loading

0 comments on commit 8fddf3a

Please sign in to comment.