@rebasepro/server-core 0.0.1-canary.4d4fb3e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -0
- package/README.md +40 -0
- package/build-errors.txt +52 -0
- package/coverage/clover.xml +3739 -0
- package/coverage/coverage-final.json +31 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +266 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov-report/src/api/ast-schema-editor.ts.html +952 -0
- package/coverage/lcov-report/src/api/errors.ts.html +472 -0
- package/coverage/lcov-report/src/api/graphql/graphql-schema-generator.ts.html +1069 -0
- package/coverage/lcov-report/src/api/graphql/index.html +116 -0
- package/coverage/lcov-report/src/api/index.html +176 -0
- package/coverage/lcov-report/src/api/openapi-generator.ts.html +565 -0
- package/coverage/lcov-report/src/api/rest/api-generator.ts.html +994 -0
- package/coverage/lcov-report/src/api/rest/index.html +131 -0
- package/coverage/lcov-report/src/api/rest/query-parser.ts.html +550 -0
- package/coverage/lcov-report/src/api/schema-editor-routes.ts.html +202 -0
- package/coverage/lcov-report/src/api/server.ts.html +823 -0
- package/coverage/lcov-report/src/auth/admin-routes.ts.html +973 -0
- package/coverage/lcov-report/src/auth/index.html +176 -0
- package/coverage/lcov-report/src/auth/jwt.ts.html +574 -0
- package/coverage/lcov-report/src/auth/middleware.ts.html +745 -0
- package/coverage/lcov-report/src/auth/password.ts.html +310 -0
- package/coverage/lcov-report/src/auth/services.ts.html +2074 -0
- package/coverage/lcov-report/src/collections/index.html +116 -0
- package/coverage/lcov-report/src/collections/loader.ts.html +232 -0
- package/coverage/lcov-report/src/db/auth-schema.ts.html +523 -0
- package/coverage/lcov-report/src/db/data-transformer.ts.html +1753 -0
- package/coverage/lcov-report/src/db/entityService.ts.html +700 -0
- package/coverage/lcov-report/src/db/index.html +146 -0
- package/coverage/lcov-report/src/db/services/EntityFetchService.ts.html +4048 -0
- package/coverage/lcov-report/src/db/services/EntityPersistService.ts.html +883 -0
- package/coverage/lcov-report/src/db/services/RelationService.ts.html +3121 -0
- package/coverage/lcov-report/src/db/services/entity-helpers.ts.html +442 -0
- package/coverage/lcov-report/src/db/services/index.html +176 -0
- package/coverage/lcov-report/src/db/services/index.ts.html +124 -0
- package/coverage/lcov-report/src/generate-drizzle-schema-logic.ts.html +1960 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/src/services/driver-registry.ts.html +631 -0
- package/coverage/lcov-report/src/services/index.html +131 -0
- package/coverage/lcov-report/src/services/postgresDataDriver.ts.html +3025 -0
- package/coverage/lcov-report/src/storage/LocalStorageController.ts.html +1189 -0
- package/coverage/lcov-report/src/storage/S3StorageController.ts.html +970 -0
- package/coverage/lcov-report/src/storage/index.html +161 -0
- package/coverage/lcov-report/src/storage/storage-registry.ts.html +646 -0
- package/coverage/lcov-report/src/storage/types.ts.html +451 -0
- package/coverage/lcov-report/src/utils/drizzle-conditions.ts.html +3082 -0
- package/coverage/lcov-report/src/utils/index.html +116 -0
- package/coverage/lcov.info +7179 -0
- package/dist/common/src/collections/CollectionRegistry.d.ts +48 -0
- package/dist/common/src/collections/index.d.ts +1 -0
- package/dist/common/src/data/buildRebaseData.d.ts +14 -0
- package/dist/common/src/index.d.ts +3 -0
- package/dist/common/src/util/builders.d.ts +57 -0
- package/dist/common/src/util/callbacks.d.ts +6 -0
- package/dist/common/src/util/collections.d.ts +11 -0
- package/dist/common/src/util/common.d.ts +2 -0
- package/dist/common/src/util/conditions.d.ts +26 -0
- package/dist/common/src/util/entities.d.ts +36 -0
- package/dist/common/src/util/enums.d.ts +3 -0
- package/dist/common/src/util/index.d.ts +16 -0
- package/dist/common/src/util/navigation_from_path.d.ts +34 -0
- package/dist/common/src/util/navigation_utils.d.ts +20 -0
- package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
- package/dist/common/src/util/paths.d.ts +14 -0
- package/dist/common/src/util/permissions.d.ts +5 -0
- package/dist/common/src/util/references.d.ts +2 -0
- package/dist/common/src/util/relations.d.ts +12 -0
- package/dist/common/src/util/resolutions.d.ts +72 -0
- package/dist/common/src/util/storage.d.ts +24 -0
- package/dist/index-BeMqpmfQ.js +239 -0
- package/dist/index-BeMqpmfQ.js.map +1 -0
- package/dist/index-bl4J3lNb.js +55823 -0
- package/dist/index-bl4J3lNb.js.map +1 -0
- package/dist/index.es.js +58 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +56062 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/server-core/src/api/ast-schema-editor.d.ts +21 -0
- package/dist/server-core/src/api/collections_for_test/callbacks_test_collection.d.ts +2 -0
- package/dist/server-core/src/api/errors.d.ts +35 -0
- package/dist/server-core/src/api/graphql/graphql-schema-generator.d.ts +35 -0
- package/dist/server-core/src/api/graphql/index.d.ts +1 -0
- package/dist/server-core/src/api/index.d.ts +9 -0
- package/dist/server-core/src/api/openapi-generator.d.ts +2 -0
- package/dist/server-core/src/api/rest/api-generator.d.ts +64 -0
- package/dist/server-core/src/api/rest/index.d.ts +1 -0
- package/dist/server-core/src/api/rest/query-parser.d.ts +9 -0
- package/dist/server-core/src/api/schema-editor-routes.d.ts +3 -0
- package/dist/server-core/src/api/server.d.ts +40 -0
- package/dist/server-core/src/api/types.d.ts +90 -0
- package/dist/server-core/src/auth/admin-routes.d.ts +7 -0
- package/dist/server-core/src/auth/google-oauth.d.ts +20 -0
- package/dist/server-core/src/auth/index.d.ts +12 -0
- package/dist/server-core/src/auth/interfaces.d.ts +270 -0
- package/dist/server-core/src/auth/jwt.d.ts +42 -0
- package/dist/server-core/src/auth/middleware.d.ts +56 -0
- package/dist/server-core/src/auth/password.d.ts +22 -0
- package/dist/server-core/src/auth/rate-limiter.d.ts +31 -0
- package/dist/server-core/src/auth/routes.d.ts +17 -0
- package/dist/server-core/src/bootstrappers/index.d.ts +0 -0
- package/dist/server-core/src/collections/BackendCollectionRegistry.d.ts +13 -0
- package/dist/server-core/src/collections/loader.d.ts +5 -0
- package/dist/server-core/src/db/interfaces.d.ts +18 -0
- package/dist/server-core/src/email/index.d.ts +6 -0
- package/dist/server-core/src/email/smtp-email-service.d.ts +25 -0
- package/dist/server-core/src/email/templates.d.ts +33 -0
- package/dist/server-core/src/email/types.d.ts +110 -0
- package/dist/server-core/src/functions/function-loader.d.ts +17 -0
- package/dist/server-core/src/functions/function-routes.d.ts +10 -0
- package/dist/server-core/src/functions/index.d.ts +3 -0
- package/dist/server-core/src/history/history-routes.d.ts +23 -0
- package/dist/server-core/src/history/index.d.ts +1 -0
- package/dist/server-core/src/index.d.ts +24 -0
- package/dist/server-core/src/init.d.ts +49 -0
- package/dist/server-core/src/serve-spa.d.ts +30 -0
- package/dist/server-core/src/services/driver-registry.d.ts +78 -0
- package/dist/server-core/src/storage/LocalStorageController.d.ts +46 -0
- package/dist/server-core/src/storage/S3StorageController.d.ts +36 -0
- package/dist/server-core/src/storage/index.d.ts +18 -0
- package/dist/server-core/src/storage/routes.d.ts +38 -0
- package/dist/server-core/src/storage/storage-registry.d.ts +78 -0
- package/dist/server-core/src/storage/types.d.ts +91 -0
- package/dist/server-core/src/types/index.d.ts +11 -0
- package/dist/server-core/src/utils/logging.d.ts +9 -0
- package/dist/server-core/src/utils/sql.d.ts +27 -0
- package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
- package/dist/types/src/controllers/auth.d.ts +117 -0
- package/dist/types/src/controllers/client.d.ts +58 -0
- package/dist/types/src/controllers/collection_registry.d.ts +44 -0
- package/dist/types/src/controllers/customization_controller.d.ts +54 -0
- package/dist/types/src/controllers/data.d.ts +141 -0
- package/dist/types/src/controllers/data_driver.d.ts +168 -0
- package/dist/types/src/controllers/database_admin.d.ts +11 -0
- package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
- package/dist/types/src/controllers/effective_role.d.ts +4 -0
- package/dist/types/src/controllers/index.d.ts +17 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
- package/dist/types/src/controllers/navigation.d.ts +213 -0
- package/dist/types/src/controllers/registry.d.ts +51 -0
- package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
- package/dist/types/src/controllers/side_entity_controller.d.ts +89 -0
- package/dist/types/src/controllers/snackbar.d.ts +24 -0
- package/dist/types/src/controllers/storage.d.ts +173 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/rebase_context.d.ts +101 -0
- package/dist/types/src/types/backend.d.ts +533 -0
- package/dist/types/src/types/builders.d.ts +14 -0
- package/dist/types/src/types/chips.d.ts +5 -0
- package/dist/types/src/types/collections.d.ts +812 -0
- package/dist/types/src/types/data_source.d.ts +64 -0
- package/dist/types/src/types/entities.d.ts +145 -0
- package/dist/types/src/types/entity_actions.d.ts +98 -0
- package/dist/types/src/types/entity_callbacks.d.ts +173 -0
- package/dist/types/src/types/entity_link_builder.d.ts +7 -0
- package/dist/types/src/types/entity_overrides.d.ts +9 -0
- package/dist/types/src/types/entity_views.d.ts +61 -0
- package/dist/types/src/types/export_import.d.ts +21 -0
- package/dist/types/src/types/index.d.ts +22 -0
- package/dist/types/src/types/locales.d.ts +4 -0
- package/dist/types/src/types/modify_collections.d.ts +5 -0
- package/dist/types/src/types/plugins.d.ts +225 -0
- package/dist/types/src/types/properties.d.ts +1091 -0
- package/dist/types/src/types/property_config.d.ts +70 -0
- package/dist/types/src/types/relations.d.ts +336 -0
- package/dist/types/src/types/slots.d.ts +228 -0
- package/dist/types/src/types/translations.d.ts +826 -0
- package/dist/types/src/types/user_management_delegate.d.ts +120 -0
- package/dist/types/src/types/websockets.d.ts +78 -0
- package/dist/types/src/users/index.d.ts +2 -0
- package/dist/types/src/users/roles.d.ts +22 -0
- package/dist/types/src/users/user.d.ts +46 -0
- package/history_diff.log +385 -0
- package/jest.config.cjs +16 -0
- package/package.json +86 -0
- package/scratch.ts +8 -0
- package/src/api/ast-schema-editor.ts +289 -0
- package/src/api/collections_for_test/callbacks_test_collection.ts +57 -0
- package/src/api/errors.ts +155 -0
- package/src/api/graphql/graphql-schema-generator.ts +334 -0
- package/src/api/graphql/index.ts +2 -0
- package/src/api/index.ts +11 -0
- package/src/api/openapi-generator.ts +160 -0
- package/src/api/rest/api-generator.ts +466 -0
- package/src/api/rest/index.ts +2 -0
- package/src/api/rest/query-parser.ts +155 -0
- package/src/api/schema-editor-routes.ts +39 -0
- package/src/api/server.ts +245 -0
- package/src/api/types.ts +90 -0
- package/src/auth/admin-routes.ts +488 -0
- package/src/auth/google-oauth.ts +60 -0
- package/src/auth/index.ts +21 -0
- package/src/auth/interfaces.ts +316 -0
- package/src/auth/jwt.ts +164 -0
- package/src/auth/middleware.ts +235 -0
- package/src/auth/password.ts +75 -0
- package/src/auth/rate-limiter.ts +129 -0
- package/src/auth/routes.ts +730 -0
- package/src/bootstrappers/index.ts +1 -0
- package/src/collections/BackendCollectionRegistry.ts +20 -0
- package/src/collections/loader.ts +49 -0
- package/src/db/interfaces.ts +60 -0
- package/src/email/index.ts +17 -0
- package/src/email/smtp-email-service.ts +88 -0
- package/src/email/templates.ts +301 -0
- package/src/email/types.ts +112 -0
- package/src/functions/function-loader.ts +91 -0
- package/src/functions/function-routes.ts +31 -0
- package/src/functions/index.ts +3 -0
- package/src/history/history-routes.ts +128 -0
- package/src/history/index.ts +2 -0
- package/src/index.ts +56 -0
- package/src/init.ts +309 -0
- package/src/serve-spa.ts +81 -0
- package/src/services/driver-registry.ts +182 -0
- package/src/storage/LocalStorageController.ts +368 -0
- package/src/storage/S3StorageController.ts +295 -0
- package/src/storage/index.ts +32 -0
- package/src/storage/routes.ts +247 -0
- package/src/storage/storage-registry.ts +187 -0
- package/src/storage/types.ts +122 -0
- package/src/types/index.ts +27 -0
- package/src/utils/logging.ts +35 -0
- package/src/utils/sql.ts +38 -0
- package/test/admin-routes.test.ts +591 -0
- package/test/api-generator.test.ts +458 -0
- package/test/ast-schema-editor.test.ts +61 -0
- package/test/auth-middleware-hono.test.ts +321 -0
- package/test/auth-routes.test.ts +868 -0
- package/test/driver-registry.test.ts +280 -0
- package/test/errors-hono.test.ts +133 -0
- package/test/errors.test.ts +150 -0
- package/test/jwt-security.test.ts +173 -0
- package/test/jwt.test.ts +311 -0
- package/test/middleware.test.ts +295 -0
- package/test/password.test.ts +165 -0
- package/test/query-parser.test.ts +258 -0
- package/test/rate-limiter.test.ts +102 -0
- package/test/storage-local.test.ts +278 -0
- package/test/storage-registry.test.ts +280 -0
- package/test/storage-routes.test.ts +218 -0
- package/test/storage-s3.test.ts +301 -0
- package/test-ast.ts +28 -0
- package/test_output.txt +1133 -0
- package/tsconfig.json +49 -0
- package/tsconfig.prod.json +20 -0
- package/vite.config.ts +78 -0
- package/vite.config.ts.timestamp-1775065397568-8a853255edf6e.mjs +46 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { mapOperator, parseQueryOptions } from "../src/api/rest/query-parser";
|
|
2
|
+
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
// mapOperator
|
|
5
|
+
// ─────────────────────────────────────────────────────────────
|
|
6
|
+
describe("mapOperator", () => {
|
|
7
|
+
it("maps PostgREST operators to Rebase operators", () => {
|
|
8
|
+
expect(mapOperator("eq")).toBe("==");
|
|
9
|
+
expect(mapOperator("neq")).toBe("!=");
|
|
10
|
+
expect(mapOperator("gt")).toBe(">");
|
|
11
|
+
expect(mapOperator("gte")).toBe(">=");
|
|
12
|
+
expect(mapOperator("lt")).toBe("<");
|
|
13
|
+
expect(mapOperator("lte")).toBe("<=");
|
|
14
|
+
expect(mapOperator("in")).toBe("in");
|
|
15
|
+
expect(mapOperator("nin")).toBe("not-in");
|
|
16
|
+
expect(mapOperator("cs")).toBe("array-contains");
|
|
17
|
+
expect(mapOperator("csa")).toBe("array-contains-any");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("returns null for unknown operators", () => {
|
|
21
|
+
expect(mapOperator("like")).toBeNull();
|
|
22
|
+
expect(mapOperator("between")).toBeNull();
|
|
23
|
+
expect(mapOperator("")).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// ─────────────────────────────────────────────────────────────
|
|
28
|
+
// parseQueryOptions — Pagination
|
|
29
|
+
// ─────────────────────────────────────────────────────────────
|
|
30
|
+
describe("parseQueryOptions — pagination", () => {
|
|
31
|
+
it("parses limit", () => {
|
|
32
|
+
const result = parseQueryOptions({ limit: "25" });
|
|
33
|
+
expect(result.limit).toBe(25);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("parses offset", () => {
|
|
37
|
+
const result = parseQueryOptions({ offset: "50" });
|
|
38
|
+
expect(result.offset).toBe(50);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("calculates offset from page number", () => {
|
|
42
|
+
const result = parseQueryOptions({ page: "3", limit: "10" });
|
|
43
|
+
expect(result.offset).toBe(20); // (3-1) * 10
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("uses default limit of 20 for page calculation when limit not set", () => {
|
|
47
|
+
const result = parseQueryOptions({ page: "2" });
|
|
48
|
+
expect(result.offset).toBe(20); // (2-1) * 20
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("handles no pagination params", () => {
|
|
52
|
+
const result = parseQueryOptions({});
|
|
53
|
+
expect(result.limit).toBeUndefined();
|
|
54
|
+
expect(result.offset).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// ─────────────────────────────────────────────────────────────
|
|
59
|
+
// parseQueryOptions — PostgREST Filters
|
|
60
|
+
// ─────────────────────────────────────────────────────────────
|
|
61
|
+
describe("parseQueryOptions — PostgREST filters", () => {
|
|
62
|
+
it("parses equality filter (implicit eq)", () => {
|
|
63
|
+
const result = parseQueryOptions({ status: "published" });
|
|
64
|
+
expect(result.where?.status).toEqual(["==", "published"]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("parses eq operator explicitly", () => {
|
|
68
|
+
const result = parseQueryOptions({ status: "eq.published" });
|
|
69
|
+
expect(result.where?.status).toEqual(["==", "published"]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("parses gt with number coercion", () => {
|
|
73
|
+
const result = parseQueryOptions({ age: "gt.18" });
|
|
74
|
+
expect(result.where?.age).toEqual([">", 18]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("parses gte operator", () => {
|
|
78
|
+
const result = parseQueryOptions({ price: "gte.9.99" });
|
|
79
|
+
expect(result.where?.price).toEqual([">=", 9.99]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("parses lt operator", () => {
|
|
83
|
+
const result = parseQueryOptions({ count: "lt.100" });
|
|
84
|
+
expect(result.where?.count).toEqual(["<", 100]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("parses lte operator", () => {
|
|
88
|
+
const result = parseQueryOptions({ rating: "lte.5" });
|
|
89
|
+
expect(result.where?.rating).toEqual(["<=", 5]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("parses neq operator", () => {
|
|
93
|
+
const result = parseQueryOptions({ status: "neq.draft" });
|
|
94
|
+
expect(result.where?.status).toEqual(["!=", "draft"]);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("parses boolean true", () => {
|
|
98
|
+
const result = parseQueryOptions({ active: "true" });
|
|
99
|
+
expect(result.where?.active).toEqual(["==", true]);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("parses boolean false", () => {
|
|
103
|
+
const result = parseQueryOptions({ active: "false" });
|
|
104
|
+
expect(result.where?.active).toEqual(["==", false]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("parses null", () => {
|
|
108
|
+
const result = parseQueryOptions({ deleted_at: "null" });
|
|
109
|
+
expect(result.where?.deleted_at).toEqual(["==", null]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("parses numeric strings as numbers", () => {
|
|
113
|
+
const result = parseQueryOptions({ quantity: "42" });
|
|
114
|
+
expect(result.where?.quantity).toEqual(["==", 42]);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("parses in operator with array", () => {
|
|
118
|
+
const result = parseQueryOptions({ role: "in.(admin,editor,viewer)" });
|
|
119
|
+
expect(result.where?.role).toEqual(["in", ["admin", "editor", "viewer"]]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("parses in operator with numeric array", () => {
|
|
123
|
+
const result = parseQueryOptions({ priority: "in.(1,2,3)" });
|
|
124
|
+
expect(result.where?.priority).toEqual(["in", [1, 2, 3]]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("parses array-contains operator", () => {
|
|
128
|
+
const result = parseQueryOptions({ tags: "cs.javascript" });
|
|
129
|
+
expect(result.where?.tags).toEqual(["array-contains", "javascript"]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("skips reserved query keys", () => {
|
|
133
|
+
const result = parseQueryOptions({
|
|
134
|
+
limit: "10",
|
|
135
|
+
offset: "0",
|
|
136
|
+
orderBy: "name:asc",
|
|
137
|
+
status: "eq.active",
|
|
138
|
+
});
|
|
139
|
+
// Only status should be in where
|
|
140
|
+
expect(result.where?.status).toEqual(["==", "active"]);
|
|
141
|
+
expect(result.where?.limit).toBeUndefined();
|
|
142
|
+
expect(result.where?.offset).toBeUndefined();
|
|
143
|
+
expect(result.where?.orderBy).toBeUndefined();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("handles string values with dots that are not operators (fallback to eq)", () => {
|
|
147
|
+
const result = parseQueryOptions({ email: "user@example.com" });
|
|
148
|
+
// "user@example" is not a valid operator, so fallback to eq
|
|
149
|
+
expect(result.where?.email).toBeDefined();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("removes empty where object", () => {
|
|
153
|
+
const result = parseQueryOptions({ limit: "10" });
|
|
154
|
+
expect(result.where).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// ─────────────────────────────────────────────────────────────
|
|
159
|
+
// parseQueryOptions — Legacy JSON where
|
|
160
|
+
// ─────────────────────────────────────────────────────────────
|
|
161
|
+
describe("parseQueryOptions — legacy JSON where", () => {
|
|
162
|
+
it("parses JSON where string", () => {
|
|
163
|
+
const result = parseQueryOptions({
|
|
164
|
+
where: JSON.stringify({ status: ["==", "published"] }),
|
|
165
|
+
});
|
|
166
|
+
expect(result.where?.status).toEqual(["==", "published"]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("accepts object where directly", () => {
|
|
170
|
+
const result = parseQueryOptions({
|
|
171
|
+
where: { status: ["==", "draft"] },
|
|
172
|
+
});
|
|
173
|
+
expect(result.where?.status).toEqual(["==", "draft"]);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("throws for malformed JSON where", () => {
|
|
177
|
+
expect(() => parseQueryOptions({ where: "not valid json{" })).toThrow("Invalid 'where' filter");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("throws for array where", () => {
|
|
181
|
+
expect(() => parseQueryOptions({ where: JSON.stringify([1, 2]) })).toThrow("Filter must be a JSON object");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("throws for null where", () => {
|
|
185
|
+
expect(() => parseQueryOptions({ where: JSON.stringify(null) })).toThrow("Filter must be a JSON object");
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// ─────────────────────────────────────────────────────────────
|
|
190
|
+
// parseQueryOptions — Sorting
|
|
191
|
+
// ─────────────────────────────────────────────────────────────
|
|
192
|
+
describe("parseQueryOptions — sorting", () => {
|
|
193
|
+
it("parses JSON orderBy", () => {
|
|
194
|
+
const orderBy = JSON.stringify([{ field: "name", direction: "asc" }]);
|
|
195
|
+
const result = parseQueryOptions({ orderBy });
|
|
196
|
+
expect(result.orderBy).toEqual([{ field: "name", direction: "asc" }]);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("parses simple field:direction format", () => {
|
|
200
|
+
const result = parseQueryOptions({ orderBy: "created_at:desc" });
|
|
201
|
+
expect(result.orderBy).toEqual([{ field: "created_at", direction: "desc" }]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("defaults direction to asc", () => {
|
|
205
|
+
const result = parseQueryOptions({ orderBy: "name" });
|
|
206
|
+
expect(result.orderBy).toEqual([{ field: "name", direction: "asc" }]);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("handles no orderBy", () => {
|
|
210
|
+
const result = parseQueryOptions({});
|
|
211
|
+
expect(result.orderBy).toBeUndefined();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// ─────────────────────────────────────────────────────────────
|
|
216
|
+
// parseQueryOptions — Relation includes
|
|
217
|
+
// ─────────────────────────────────────────────────────────────
|
|
218
|
+
describe("parseQueryOptions — includes", () => {
|
|
219
|
+
it("parses wildcard include", () => {
|
|
220
|
+
const result = parseQueryOptions({ include: "*" });
|
|
221
|
+
expect(result.include).toEqual(["*"]);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("parses comma-separated includes", () => {
|
|
225
|
+
const result = parseQueryOptions({ include: "author,tags,category" });
|
|
226
|
+
expect(result.include).toEqual(["author", "tags", "category"]);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("trims whitespace in includes", () => {
|
|
230
|
+
const result = parseQueryOptions({ include: " author , tags " });
|
|
231
|
+
expect(result.include).toEqual(["author", "tags"]);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("handles no include", () => {
|
|
235
|
+
const result = parseQueryOptions({});
|
|
236
|
+
expect(result.include).toBeUndefined();
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// ─────────────────────────────────────────────────────────────
|
|
241
|
+
// parseQueryOptions — Field selection
|
|
242
|
+
// ─────────────────────────────────────────────────────────────
|
|
243
|
+
describe("parseQueryOptions — fields", () => {
|
|
244
|
+
it("parses comma-separated fields", () => {
|
|
245
|
+
const result = parseQueryOptions({ fields: "id,name,email" });
|
|
246
|
+
expect(result.fields).toEqual(["id", "name", "email"]);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("trims whitespace", () => {
|
|
250
|
+
const result = parseQueryOptions({ fields: " id , name " });
|
|
251
|
+
expect(result.fields).toEqual(["id", "name"]);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("handles no fields", () => {
|
|
255
|
+
const result = parseQueryOptions({});
|
|
256
|
+
expect(result.fields).toBeUndefined();
|
|
257
|
+
});
|
|
258
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createRateLimiter } from "../src/auth/rate-limiter";
|
|
2
|
+
import { Hono } from "hono";
|
|
3
|
+
import { HonoEnv } from "../src/api/types";
|
|
4
|
+
|
|
5
|
+
describe("Rate Limiter", () => {
|
|
6
|
+
|
|
7
|
+
function createTestApp(options: { windowMs?: number; limit?: number } = {}) {
|
|
8
|
+
const app = new Hono<HonoEnv>();
|
|
9
|
+
const limiter = createRateLimiter({
|
|
10
|
+
windowMs: options.windowMs ?? 60 * 1000, // 1 minute
|
|
11
|
+
limit: options.limit ?? 3,
|
|
12
|
+
keyGenerator: (c) => c.req.header("x-forwarded-for") || "test-ip",
|
|
13
|
+
});
|
|
14
|
+
app.use("/api/*", limiter);
|
|
15
|
+
app.get("/api/test", (c) => c.json({ ok: true }));
|
|
16
|
+
return app;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
it("allows requests under the limit", async () => {
|
|
20
|
+
const app = createTestApp({ limit: 5 });
|
|
21
|
+
|
|
22
|
+
const res = await app.request("/api/test", {
|
|
23
|
+
headers: { "x-forwarded-for": "1.2.3.4" },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(res.status).toBe(200);
|
|
27
|
+
expect(res.headers.get("X-RateLimit-Limit")).toBe("5");
|
|
28
|
+
expect(res.headers.get("X-RateLimit-Remaining")).toBe("4");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("returns 429 when limit is exceeded", async () => {
|
|
32
|
+
const app = createTestApp({ limit: 2 });
|
|
33
|
+
|
|
34
|
+
// First two should pass
|
|
35
|
+
await app.request("/api/test", { headers: { "x-forwarded-for": "10.0.0.1" } });
|
|
36
|
+
await app.request("/api/test", { headers: { "x-forwarded-for": "10.0.0.1" } });
|
|
37
|
+
|
|
38
|
+
// Third should be rate limited
|
|
39
|
+
const res = await app.request("/api/test", {
|
|
40
|
+
headers: { "x-forwarded-for": "10.0.0.1" },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
expect(res.status).toBe(429);
|
|
44
|
+
const body = await res.json() as any;
|
|
45
|
+
expect(body.error.code).toBe("RATE_LIMITED");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("includes Retry-After header when rate limited", async () => {
|
|
49
|
+
const app = createTestApp({ limit: 1 });
|
|
50
|
+
|
|
51
|
+
await app.request("/api/test", { headers: { "x-forwarded-for": "10.0.0.2" } });
|
|
52
|
+
const res = await app.request("/api/test", {
|
|
53
|
+
headers: { "x-forwarded-for": "10.0.0.2" },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(res.headers.get("Retry-After")).toBeDefined();
|
|
57
|
+
expect(res.headers.get("X-RateLimit-Remaining")).toBe("0");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("tracks different IPs separately", async () => {
|
|
61
|
+
const app = createTestApp({ limit: 1 });
|
|
62
|
+
|
|
63
|
+
const res1 = await app.request("/api/test", {
|
|
64
|
+
headers: { "x-forwarded-for": "ip-a" },
|
|
65
|
+
});
|
|
66
|
+
const res2 = await app.request("/api/test", {
|
|
67
|
+
headers: { "x-forwarded-for": "ip-b" },
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(res1.status).toBe(200);
|
|
71
|
+
expect(res2.status).toBe(200);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("decrements remaining count with each request", async () => {
|
|
75
|
+
const app = createTestApp({ limit: 3 });
|
|
76
|
+
const ip = "counter-ip";
|
|
77
|
+
|
|
78
|
+
const r1 = await app.request("/api/test", { headers: { "x-forwarded-for": ip } });
|
|
79
|
+
expect(r1.headers.get("X-RateLimit-Remaining")).toBe("2");
|
|
80
|
+
|
|
81
|
+
const r2 = await app.request("/api/test", { headers: { "x-forwarded-for": ip } });
|
|
82
|
+
expect(r2.headers.get("X-RateLimit-Remaining")).toBe("1");
|
|
83
|
+
|
|
84
|
+
const r3 = await app.request("/api/test", { headers: { "x-forwarded-for": ip } });
|
|
85
|
+
expect(r3.headers.get("X-RateLimit-Remaining")).toBe("0");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("uses custom message", async () => {
|
|
89
|
+
const app = new Hono<HonoEnv>();
|
|
90
|
+
const limiter = createRateLimiter({
|
|
91
|
+
limit: 0,
|
|
92
|
+
message: "Slow down!",
|
|
93
|
+
keyGenerator: () => "always-same",
|
|
94
|
+
});
|
|
95
|
+
app.use("/api/*", limiter);
|
|
96
|
+
app.get("/api/test", (c) => c.json({ ok: true }));
|
|
97
|
+
|
|
98
|
+
const res = await app.request("/api/test");
|
|
99
|
+
const body = await res.json() as any;
|
|
100
|
+
expect(body.error.message).toBe("Slow down!");
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import * as os from "os";
|
|
4
|
+
import { LocalStorageController } from "../src/storage/LocalStorageController";
|
|
5
|
+
|
|
6
|
+
describe("LocalStorageController", () => {
|
|
7
|
+
let controller: LocalStorageController;
|
|
8
|
+
let tempDir: string;
|
|
9
|
+
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
// Create a temporary directory for tests
|
|
12
|
+
tempDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "rebase-storage-test-"));
|
|
13
|
+
controller = new LocalStorageController({
|
|
14
|
+
basePath: tempDir
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(async () => {
|
|
19
|
+
// Clean up temporary directory
|
|
20
|
+
await fs.promises.rm(tempDir, { recursive: true, force: true });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("constructor", () => {
|
|
24
|
+
it("should initialize with basePath", () => {
|
|
25
|
+
expect(controller.getBasePath()).toBe(tempDir);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should return 'local' as type", () => {
|
|
29
|
+
expect(controller.getType()).toBe("local");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("uploadFile", () => {
|
|
34
|
+
it("should upload a file and return metadata", async () => {
|
|
35
|
+
const content = Buffer.from("Hello, World!");
|
|
36
|
+
const file = new File([content], "test.txt", { type: "text/plain" });
|
|
37
|
+
|
|
38
|
+
const result = await controller.uploadFile({
|
|
39
|
+
file,
|
|
40
|
+
fileName: "test.txt",
|
|
41
|
+
path: "uploads"
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(result.path).toContain("uploads");
|
|
45
|
+
expect(result.path).toContain("test.txt");
|
|
46
|
+
|
|
47
|
+
// Verify file exists on disk (uses default bucket)
|
|
48
|
+
const filePath = path.join(tempDir, "default", "uploads", "test.txt");
|
|
49
|
+
const exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
50
|
+
expect(exists).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should create nested directories", async () => {
|
|
54
|
+
const content = Buffer.from("Nested content");
|
|
55
|
+
const file = new File([content], "nested.txt", { type: "text/plain" });
|
|
56
|
+
|
|
57
|
+
await controller.uploadFile({
|
|
58
|
+
file,
|
|
59
|
+
fileName: "nested.txt",
|
|
60
|
+
path: "level1/level2/level3"
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const filePath = path.join(tempDir, "default", "level1", "level2", "level3", "nested.txt");
|
|
64
|
+
const exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
65
|
+
expect(exists).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should handle custom bucket", async () => {
|
|
69
|
+
const content = Buffer.from("Bucket content");
|
|
70
|
+
const file = new File([content], "bucket.txt", { type: "text/plain" });
|
|
71
|
+
|
|
72
|
+
await controller.uploadFile({
|
|
73
|
+
file,
|
|
74
|
+
fileName: "bucket.txt",
|
|
75
|
+
path: "files",
|
|
76
|
+
bucket: "custom-bucket"
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const filePath = path.join(tempDir, "custom-bucket", "files", "bucket.txt");
|
|
80
|
+
const exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
81
|
+
expect(exists).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should store metadata alongside file", async () => {
|
|
85
|
+
const content = Buffer.from("With metadata");
|
|
86
|
+
const file = new File([content], "meta.txt", { type: "text/plain" });
|
|
87
|
+
|
|
88
|
+
await controller.uploadFile({
|
|
89
|
+
file,
|
|
90
|
+
fileName: "meta.txt",
|
|
91
|
+
path: "uploads",
|
|
92
|
+
metadata: { customField: "customValue" }
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Implementation uses .metadata.json extension
|
|
96
|
+
const metadataPath = path.join(tempDir, "default", "uploads", "meta.txt.metadata.json");
|
|
97
|
+
const exists = await fs.promises.access(metadataPath).then(() => true).catch(() => false);
|
|
98
|
+
expect(exists).toBe(true);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("getFile", () => {
|
|
103
|
+
it("should retrieve an uploaded file using local:// URL format", async () => {
|
|
104
|
+
const content = Buffer.from("Retrieve me");
|
|
105
|
+
const file = new File([content], "retrieve.txt", { type: "text/plain" });
|
|
106
|
+
|
|
107
|
+
const uploadResult = await controller.uploadFile({
|
|
108
|
+
file,
|
|
109
|
+
fileName: "retrieve.txt",
|
|
110
|
+
path: "uploads"
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Use the storageUrl from upload result (local:// format)
|
|
114
|
+
const retrieved = await controller.getFile(uploadResult.storageUrl!);
|
|
115
|
+
|
|
116
|
+
expect(retrieved).not.toBeNull();
|
|
117
|
+
expect(retrieved?.name).toBe("retrieve.txt");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("should return null for non-existent file", async () => {
|
|
121
|
+
const result = await controller.getFile("local://default/nonexistent/file.txt");
|
|
122
|
+
expect(result).toBeNull();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("deleteFile", () => {
|
|
127
|
+
it("should delete an uploaded file using local:// URL format", async () => {
|
|
128
|
+
const content = Buffer.from("Delete me");
|
|
129
|
+
const file = new File([content], "delete.txt", { type: "text/plain" });
|
|
130
|
+
|
|
131
|
+
const uploadResult = await controller.uploadFile({
|
|
132
|
+
file,
|
|
133
|
+
fileName: "delete.txt",
|
|
134
|
+
path: "uploads"
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Verify file exists
|
|
138
|
+
const filePath = path.join(tempDir, "default", "uploads", "delete.txt");
|
|
139
|
+
let exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
140
|
+
expect(exists).toBe(true);
|
|
141
|
+
|
|
142
|
+
// Delete the file using local:// URL format
|
|
143
|
+
await controller.deleteFile(uploadResult.storageUrl!);
|
|
144
|
+
|
|
145
|
+
// Verify file no longer exists
|
|
146
|
+
exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
147
|
+
expect(exists).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("should not throw when deleting non-existent file", async () => {
|
|
151
|
+
await expect(controller.deleteFile("local://default/nonexistent/file.txt")).resolves.not.toThrow();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("should also delete metadata file", async () => {
|
|
155
|
+
const content = Buffer.from("Delete with metadata");
|
|
156
|
+
const file = new File([content], "withmeta.txt", { type: "text/plain" });
|
|
157
|
+
|
|
158
|
+
const uploadResult = await controller.uploadFile({
|
|
159
|
+
file,
|
|
160
|
+
fileName: "withmeta.txt",
|
|
161
|
+
path: "uploads",
|
|
162
|
+
metadata: { key: "value" }
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
await controller.deleteFile(uploadResult.storageUrl!);
|
|
166
|
+
|
|
167
|
+
const metadataPath = path.join(tempDir, "default", "uploads", "withmeta.txt.metadata.json");
|
|
168
|
+
const exists = await fs.promises.access(metadataPath).then(() => true).catch(() => false);
|
|
169
|
+
expect(exists).toBe(false);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("list", () => {
|
|
174
|
+
beforeEach(async () => {
|
|
175
|
+
// Upload some test files
|
|
176
|
+
for (let i = 1; i <= 5; i++) {
|
|
177
|
+
const file = new File([`Content ${i}`], `file${i}.txt`, { type: "text/plain" });
|
|
178
|
+
await controller.uploadFile({
|
|
179
|
+
file,
|
|
180
|
+
fileName: `file${i}.txt`,
|
|
181
|
+
path: "listtest"
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("should list files in a directory", async () => {
|
|
187
|
+
const result = await controller.list("listtest", { bucket: "default" });
|
|
188
|
+
|
|
189
|
+
// Items should be the actual files (not metadata files)
|
|
190
|
+
expect(result.items.length).toBeGreaterThanOrEqual(5);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("should return empty list for non-existent directory", async () => {
|
|
194
|
+
const result = await controller.list("nonexistent", { bucket: "default" });
|
|
195
|
+
|
|
196
|
+
expect(result.items).toHaveLength(0);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("getDownloadURL", () => {
|
|
201
|
+
it("should return download URL for existing file", async () => {
|
|
202
|
+
const content = Buffer.from("Download me");
|
|
203
|
+
const file = new File([content], "download.txt", { type: "text/plain" });
|
|
204
|
+
|
|
205
|
+
const uploadResult = await controller.uploadFile({
|
|
206
|
+
file,
|
|
207
|
+
fileName: "download.txt",
|
|
208
|
+
path: "uploads"
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Use the storageUrl from upload result
|
|
212
|
+
const result = await controller.getDownloadURL(uploadResult.storageUrl!);
|
|
213
|
+
|
|
214
|
+
expect(result.url).toBeTruthy();
|
|
215
|
+
expect(result.fileNotFound).toBeFalsy();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("should return fileNotFound for non-existent file", async () => {
|
|
219
|
+
const result = await controller.getDownloadURL("local://default/nonexistent/file.txt");
|
|
220
|
+
|
|
221
|
+
expect(result.fileNotFound).toBe(true);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe("getAbsolutePath", () => {
|
|
226
|
+
it("should return absolute filesystem path without bucket", () => {
|
|
227
|
+
const absPath = controller.getAbsolutePath("uploads/test.txt");
|
|
228
|
+
|
|
229
|
+
// getAbsolutePath uses getFullPath which doesn't include bucket unless specified
|
|
230
|
+
expect(absPath).toBe(path.join(tempDir, "uploads", "test.txt"));
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("should handle custom bucket", () => {
|
|
234
|
+
const absPath = controller.getAbsolutePath("uploads/test.txt", "custom");
|
|
235
|
+
|
|
236
|
+
expect(absPath).toBe(path.join(tempDir, "custom", "uploads", "test.txt"));
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe("validateFile", () => {
|
|
241
|
+
it("should accept valid file", () => {
|
|
242
|
+
const file = new File(["content"], "valid.txt", { type: "text/plain" });
|
|
243
|
+
|
|
244
|
+
// Should not throw
|
|
245
|
+
expect(() => {
|
|
246
|
+
(controller as {validateFile: (f: File) => void}).validateFile(file);
|
|
247
|
+
}).not.toThrow();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("should reject file exceeding max size", () => {
|
|
251
|
+
// Create a controller with small max size
|
|
252
|
+
const smallController = new LocalStorageController({
|
|
253
|
+
basePath: tempDir,
|
|
254
|
+
maxFileSize: 10 // 10 bytes
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const largeContent = Buffer.alloc(100);
|
|
258
|
+
const file = new File([largeContent], "large.txt", { type: "text/plain" });
|
|
259
|
+
|
|
260
|
+
expect(() => {
|
|
261
|
+
(smallController as {validateFile: (f: File) => void}).validateFile(file);
|
|
262
|
+
}).toThrow(/exceeds/i);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("should reject disallowed file types", () => {
|
|
266
|
+
const controllerWithTypes = new LocalStorageController({
|
|
267
|
+
basePath: tempDir,
|
|
268
|
+
allowedMimeTypes: ["image/png", "image/jpeg"]
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const file = new File(["content"], "script.js", { type: "application/javascript" });
|
|
272
|
+
|
|
273
|
+
expect(() => {
|
|
274
|
+
(controllerWithTypes as {validateFile: (f: File) => void}).validateFile(file);
|
|
275
|
+
}).toThrow(/not allowed/i);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
});
|