Skip to content

Commit

Permalink
feat(server): Projects Recycle bin (#1169)
Browse files Browse the repository at this point in the history
Co-authored-by: tomokazu tantaka <[email protected]>
  • Loading branch information
hexaforce and hexaforce authored Oct 10, 2024
1 parent 1d52c95 commit e1f1b0f
Show file tree
Hide file tree
Showing 16 changed files with 384 additions and 30 deletions.
82 changes: 80 additions & 2 deletions server/e2e/gql_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,84 @@ func TestSortByUpdatedAt(t *testing.T) {

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")
}

// go test -v -run TestDeleteProjects ./e2e/...

func TestDeleteProjects(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")

// Deleted 'project2'
requestBody := GraphQLRequest{
OperationName: "UpdateProject",
Query: `mutation UpdateProject($input: UpdateProjectInput!) {
updateProject(input: $input) {
project {
id
name
isDeleted
updatedAt
__typename
}
__typename
}
}`,
Variables: map[string]any{
"input": map[string]any{
"projectId": project2ID,
"deleted": true,
},
},
}

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()

// check
requestBody = GraphQLRequest{
OperationName: "GetDeletedProjects",
Query: `
query GetDeletedProjects($teamId: ID!) {
deletedProjects(teamId: $teamId) {
nodes {
id
name
isDeleted
}
totalCount
}
}`,
Variables: map[string]any{
"teamId": wID,
},
}
deletedProjects := 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("deletedProjects").Object()

deletedProjects.Value("totalCount").Equal(1)
deletedProjects.Value("nodes").Array().Length().Equal(1)
deletedProjects.Value("nodes").Array().First().Object().Value("name").Equal("project2-test")
}
6 changes: 4 additions & 2 deletions server/gql/project.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Project implements Node {
enableGa: Boolean!
trackingId: String!
starred: Boolean!
isDeleted: Boolean!
}

type ProjectAliasAvailability {
Expand Down Expand Up @@ -80,6 +81,7 @@ input UpdateProjectInput {
trackingId: String
sceneId: ID
starred: Boolean
deleted: Boolean
}

input PublishProjectInput {
Expand Down Expand Up @@ -140,13 +142,13 @@ type ProjectEdge {
extend type Query {
projects(
teamId: ID!
includeArchived: Boolean
pagination: Pagination
keyword: String
sort: ProjectSort
): ProjectConnection!
): ProjectConnection! # not included deleted projects
checkProjectAlias(alias: String!): ProjectAliasAvailability!
starredProjects(teamId: ID!): ProjectConnection!
deletedProjects(teamId: ID!): ProjectConnection!
}

extend type Mutation {
Expand Down
Loading

0 comments on commit e1f1b0f

Please sign in to comment.