Skip to content

Commit

Permalink
Merge branch 'main' into chore-server/items-as-csv-to-usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkarel authored Dec 2, 2024
2 parents 833b541 + eeca1e8 commit f27d71e
Show file tree
Hide file tree
Showing 44 changed files with 3,816 additions and 118 deletions.
199 changes: 199 additions & 0 deletions server/e2e/integration_schema_export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package e2e

import (
"net/http"
"testing"

"github.com/reearth/reearth-cms/server/internal/app"
"github.com/reearth/reearth-cms/server/pkg/id"
)

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

// /api/schemata/{schemaId}/schema.json
e.GET("/api/schemata/{schemaId}/schema.json", sid1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/schemata/{schemaId}/schema.json", id.NewSchemaID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/schemata/{schemaId}/schema.json", sid1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": sid1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
"asset": map[string]any{
"type": "string",
"format": "binary",
},
sfKey1.String(): map[string]any{
"type": "string",
},
},
"type": "object",
})

// /api/projects/{projectIdOrKey}/schemata/{schemaId}/schema.json
e.GET("/api/projects/{projectIdOrKey}/schemata/{schemaId}/schema.json", pid, sid1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/projects/{projectIdOrKey}/schemata/{schemaId}/schema.json", pid, id.NewSchemaID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/projects/{projectIdOrKey}/schemata/{schemaId}/schema.json", pid, sid1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": sid1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
"asset": map[string]any{
"type": "string",
"format": "binary",
},
sfKey1.String(): map[string]any{
"type": "string",
},
},
"type": "object",
})

// /api/projects/{projectIdOrKey}/models/{modelId}/schema.json
e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/schema.json", pid, mId1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/schema.json", pid, id.NewModelID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/schema.json", pid, mId1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": mId1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
"asset": map[string]any{
"type": "string",
"format": "binary",
},
sfKey1.String(): map[string]any{
"type": "string",
},
},
"type": "object",
"description": "m1 desc",
"title": "m1",
})

// /api/projects/{projectIdOrKey}/models/{modelId}/metadata_schema.json
e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/metadata_schema.json", pid, mId1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/metadata_schema.json", pid, id.NewModelID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/metadata_schema.json", pid, mId1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": mId1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
sfKey4.String(): map[string]any{
"type": "boolean",
},
},
"type": "object",
"description": "m1 desc",
"title": "m1",
})

// /api/models/{modelId}/schema.json
e.GET("/api/models/{modelId}/schema.json", mId1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/models/{modelId}/schema.json", id.NewModelID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/models/{modelId}/schema.json", mId1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": mId1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
"asset": map[string]any{
"type": "string",
"format": "binary",
},
sfKey1.String(): map[string]any{
"type": "string",
},
},
"type": "object",
"description": "m1 desc",
"title": "m1",
})

// /api/models/{modelId}/metadata_schema.json
e.GET("/api/models/{modelId}/metadata_schema.json", mId1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/models/{modelId}/metadata_schema.json", id.NewModelID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/models/{modelId}/metadata_schema.json", mId1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": mId1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
sfKey4.String(): map[string]any{
"type": "boolean",
},
},
"type": "object",
"description": "m1 desc",
"title": "m1",
})
}
43 changes: 43 additions & 0 deletions server/e2e/publicapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,49 @@ func TestPublicAPI(t *testing.T) {
// publicAPIField2Key should be removed
})

// schema export json
e.GET("/api/p/{project}/{model}/schema.json", publicAPIProjectAlias, id.RandomKey()).
Expect().
Status(http.StatusNotFound)

e.GET("/api/p/{project}/{model}/schema.json", publicAPIProjectAlias, publicAPIModelKey).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": publicAPIModelID,
"properties": map[string]any{
"asset": map[string]any{
"title": "asset",
"type": "string",
"format": "binary",
},
"asset2": map[string]any{
"title": "asset2",
"type": "string",
"format": "binary",
},
"geometry-editor": map[string]any{
"title": "geometry-editor",
"type": "object",
},
"geometry-object": map[string]any{
"title": "geometry-object",
"type": "object",
},
"test-field-1": map[string]any{
"title": "test-field-1",
"type": "string",
},
"test-field-2": map[string]any{
"title": "test-field-2",
"type": "string",
},
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
})

// make the project private
prj.Publication().SetScope(project.PublicationScopePrivate)
lo.Must0(repos.Project.Save(ctx, prj))
Expand Down
Loading

0 comments on commit f27d71e

Please sign in to comment.