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 Oct 7, 2024
2 parents 9db9f98 + 169aa9e commit d887c51
Show file tree
Hide file tree
Showing 61 changed files with 749 additions and 177 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/decompressor_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
echo "::set-output name=version::$VERSION"
echo "::set-output name=tags::$TAGS"
- name: Build and push docker image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: ./worker
file: ./worker/decompressor.Dockerfile
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy_aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
uses: aws-actions/amazon-ecr-login@v2

- name: Build and push docker image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: ./server
push: true
Expand All @@ -101,7 +101,7 @@ jobs:
uses: aws-actions/amazon-ecr-login@v2

- name: Build and push docker image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: ./worker
push: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}

- name: get latest web artifact
uses: dawidd6/[email protected].2
uses: dawidd6/[email protected].4
with:
github_token: ${{ steps.app-token.outputs.token }}
workflow: ci_web.yml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/server_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
echo "::set-output name=version::$VERSION"
echo "::set-output name=tags::$TAGS"
- name: Fetch reearth-cms-web
uses: dawidd6/action-download-artifact@v3
uses: dawidd6/action-download-artifact@v6
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: ci_web.yml
Expand All @@ -107,7 +107,7 @@ jobs:
- name: Extract reearth-cms-web
run: tar -xvf server/reearth-cms-web.tar.gz; mv reearth-cms-web server/web; ls
- name: Build and push docker image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: ./server
platforms: ${{ steps.options.outputs.platforms }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/worker_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
echo "::set-output name=version::$VERSION"
echo "::set-output name=tags::$TAGS"
- name: Build and push docker image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: ./worker
platforms: ${{ steps.options.outputs.platforms }}
Expand Down
2 changes: 1 addition & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.23.1-alpine AS build
FROM golang:1.23.2-alpine AS build
ARG TAG=release
ARG REV
ARG VERSION
Expand Down
3 changes: 2 additions & 1 deletion server/e2e/gql_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ func createItem(e *httpexpect.Expect, mID, sID string, metaId *string, fields []
) {
item {
id
version
schemaId
isMetadata
isMetadata
fields {
value
type
Expand Down
299 changes: 299 additions & 0 deletions server/e2e/gql_request_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
package e2e

import (
"net/http"
"testing"

"github.com/gavv/httpexpect/v2"
"github.com/google/uuid"
"github.com/reearth/reearth-cms/server/internal/app"
"github.com/reearth/reearth-cms/server/pkg/item"
"github.com/samber/lo"
)

func createRequest(e *httpexpect.Expect, projectId, title string, description, state *string, reviewersId []string, items []any) *httpexpect.Value {
requestBody := GraphQLRequest{
Query: `mutation CreateRequest($projectId: ID!, $title: String!, $description: String, $state: RequestState, $reviewersId: [ID!], $items: [RequestItemInput!]!) {
createRequest(
input: {projectId: $projectId, title: $title, description: $description, state: $state, reviewersId: $reviewersId, items: $items}
) {
request {
id
items {
itemId
version
ref
}
title
description
createdBy {
id
name
email
}
workspaceId
projectId
threadId
reviewersId
state
createdAt
updatedAt
approvedAt
closedAt
}
}
}`,
Variables: map[string]any{
"projectId": projectId,
"title": title,
"description": description,
"state": state,
"reviewersId": reviewersId,
"items": items,
},
}

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

return res
}

func updateRequest(e *httpexpect.Expect, requestId, title string, description, state *string, reviewersId []string, items []any) *httpexpect.Value {
requestBody := GraphQLRequest{
Query: `mutation UpdateRequest($requestId: ID!,$title: String,$description: String,$state: RequestState,$reviewersId: [ID!],$items: [RequestItemInput!]) {
updateRequest(
input: {
requestId: $requestId,
title: $title,
description: $description,
state: $state,
reviewersId: $reviewersId,
items: $items,
}
) {
request {
id
items {
itemId
version
ref
}
title
description
createdBy {
id
name
email
}
workspaceId
projectId
threadId
reviewersId
state
createdAt
updatedAt
approvedAt
closedAt
}
}
}
`,
Variables: map[string]any{
"requestId": requestId,
"title": title,
"description": description,
"state": state,
"reviewersId": reviewersId,
"items": items,
},
}

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

return res
}

func approveRequest(e *httpexpect.Expect, requestId string) *httpexpect.Value {
requestBody := GraphQLRequest{
Query: `mutation ApproveRequest($requestId: ID!) {
approveRequest(input: { requestId: $requestId }) {
request {
id
state
}
}
}
`,
Variables: map[string]any{
"requestId": requestId,
},
}

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

return res
}

func closeAllRequests(e *httpexpect.Expect, projectId string, requestsId []string) *httpexpect.Value {
requestBody := GraphQLRequest{
Query: `mutation DeleteRequest($projectId: ID!, $requestsId: [ID!]!) {
deleteRequest(input: { projectId: $projectId, requestsId: $requestsId }) {
requests
}
}
`,
Variables: map[string]any{
"projectId": projectId,
"requestsId": requestsId,
},
}

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

return res
}

func TestCreateRequest(t *testing.T) {
e := StartServer(t, &app.Config{}, true, baseSeederUser)

pId, _ := createProject(e, wId.String(), "test", "test", "test-1")
mId, _ := createModel(e, pId, "test", "test", "test-1")
fid, _ := createField(e, mId, "text", "text", "text",
false, false, false, false, "Text",
map[string]any{
"text": map[string]any{},
})
sId, _, _ := getModel(e, mId)
iid1, i1 := createItem(e, mId, sId, nil, []map[string]any{
{"schemaFieldId": fid, "value": "test", "type": "Text"},
})
ver1 := i1.Path("$.data.createItem.item.version").Raw().(string)

res := createRequest(e, pId, "test", lo.ToPtr("test"), lo.ToPtr("DRAFT"), []string{uId1.String()}, []any{map[string]any{"itemId": iid1, "version": ver1}})
req := res.Path("$.data.createRequest.request").Object()

req.Value("title").IsEqual("test")
req.Value("description").IsEqual("test")
req.Value("state").IsEqual("DRAFT")
req.Value("reviewersId").IsEqual([]string{uId1.String()})
req.Value("items").IsEqual([]any{map[string]any{"itemId": iid1, "ref": nil, "version": ver1}})
}

func TestUpdateRequest(t *testing.T) {
e := StartServer(t, &app.Config{}, true, baseSeederUser)

pId, _ := createProject(e, wId.String(), "test", "test", "test-1")
mId, _ := createModel(e, pId, "test", "test", "test-1")
fid, _ := createField(e, mId, "text", "text", "text",
false, false, false, false, "Text",
map[string]any{
"text": map[string]any{},
})
sId, _, _ := getModel(e, mId)
iid1, i1 := createItem(e, mId, sId, nil, []map[string]any{
{"schemaFieldId": fid, "value": "test", "type": "Text"},
})
ver1 := i1.Path("$.data.createItem.item.version").Raw().(string)

res := createRequest(e, pId, "test", lo.ToPtr("test"), lo.ToPtr("DRAFT"), []string{uId1.String()}, []any{map[string]any{"itemId": iid1, "version": ver1}})
req := res.Path("$.data.createRequest.request").Object()
rid := req.Value("id").String().Raw()

iid2 := item.NewID().String()
ver2 := uuid.New().String()
res2 := updateRequest(e, rid, "test2", lo.ToPtr("test2"), lo.ToPtr("WAITING"), []string{uId1.String(), uId4.String()}, []any{map[string]any{"itemId": iid1, "version": ver1}, map[string]any{"itemId": iid2, "version": ver2}})
req2 := res2.Path("$.data.updateRequest.request").Object()

req2.Value("title").IsEqual("test2")
req2.Value("description").IsEqual("test2")
req2.Value("state").IsEqual("WAITING")
req2.Value("reviewersId").IsEqual([]string{uId1.String(), uId4.String()})
req2.Value("items").Array().Length().IsEqual(2)
req2.Value("items").IsEqual([]any{map[string]any{"itemId": iid1, "ref": nil, "version": ver1}, map[string]any{"itemId": iid2, "ref": nil, "version": ver2}})
}

func TestApproveRequest(t *testing.T) {
e := StartServer(t, &app.Config{}, true, baseSeederUser)

pId, _ := createProject(e, wId.String(), "test", "test", "test-1")
mId, _ := createModel(e, pId, "test", "test", "test-1")
fid, _ := createField(e, mId, "text", "text", "text",
false, false, false, false, "Text",
map[string]any{
"text": map[string]any{},
})
sId, _, _ := getModel(e, mId)
iid1, i1 := createItem(e, mId, sId, nil, []map[string]any{
{"schemaFieldId": fid, "value": "test", "type": "Text"},
})
ver1 := i1.Path("$.data.createItem.item.version").Raw().(string)

res := createRequest(e, pId, "test", lo.ToPtr("test"), lo.ToPtr("WAITING"), []string{uId1.String()}, []any{map[string]any{"itemId": iid1, "version": ver1}})
req := res.Path("$.data.createRequest.request").Object()
rid := req.Value("id").String().Raw()

res2 := approveRequest(e, rid)
req2 := res2.Path("$.data.approveRequest.request").Object()
req2.Value("id").IsEqual(rid)
req2.Value("state").IsEqual("APPROVED")

_, itm_public := getItem(e, iid1)
itm_public.Path("$.data.node").Object().Value("version").IsEqual(ver1)
itm_public.Path("$.data.node").Object().Value("status").IsEqual("PUBLIC")
}

func TestCloseRequest(t *testing.T) {
e := StartServer(t, &app.Config{}, true, baseSeederUser)

pId, _ := createProject(e, wId.String(), "test", "test", "test-1")
mId, _ := createModel(e, pId, "test", "test", "test-1")
fid, _ := createField(e, mId, "text", "text", "text",
false, false, false, false, "Text",
map[string]any{
"text": map[string]any{},
})
sId, _, _ := getModel(e, mId)
iid1, i1 := createItem(e, mId, sId, nil, []map[string]any{
{"schemaFieldId": fid, "value": "test", "type": "Text"},
})
ver1 := i1.Path("$.data.createItem.item.version").Raw().(string)

res := createRequest(e, pId, "test", lo.ToPtr("test"), lo.ToPtr("DRAFT"), []string{uId1.String()}, []any{map[string]any{"itemId": iid1, "version": ver1}})
req := res.Path("$.data.createRequest.request").Object()
rid := req.Value("id").String().Raw()

res2 := closeAllRequests(e, pId, []string{rid})
res2.Path("$.data.deleteRequest.requests").Array().Value(0).IsEqual(rid)

_, itm_closed := getItem(e, iid1)
itm_closed.Path("$.data.node").Object().Value("version").IsEqual(ver1)
}
Loading

0 comments on commit d887c51

Please sign in to comment.