@terreno/api 57.2.0 → 57.3.0
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/README.md +17 -7
- package/dist/actions.js +19 -7
- package/dist/api.d.ts +4 -0
- package/dist/api.js +12 -24
- package/dist/auth.d.ts +23 -10
- package/dist/auth.js +97 -32
- package/dist/authRecovery.d.ts +5 -0
- package/dist/authRecovery.js +350 -0
- package/dist/authTokens.d.ts +8 -0
- package/dist/authTokens.js +162 -0
- package/dist/betterAuth.d.ts +33 -0
- package/dist/betterAuthApp.d.ts +4 -0
- package/dist/betterAuthApp.js +26 -8
- package/dist/betterAuthSetup.d.ts +44 -2
- package/dist/betterAuthSetup.js +288 -18
- package/dist/collectionRegistry.d.ts +38 -0
- package/dist/collectionRegistry.js +72 -0
- package/dist/configurationApp.d.ts +11 -2
- package/dist/configurationApp.js +2 -4
- package/dist/docLoader.js +35 -6
- package/dist/expressServer.d.ts +26 -3
- package/dist/expressServer.js +79 -11
- package/dist/index.d.ts +16 -0
- package/dist/index.js +38 -2
- package/dist/mcp/auth.d.ts +1 -0
- package/dist/mcp/auth.js +47 -25
- package/dist/mcp/handlers.d.ts +1 -1
- package/dist/mcp/handlers.js +67 -233
- package/dist/mcp/query.d.ts +2 -2
- package/dist/mcp/registry.d.ts +1 -5
- package/dist/mcp/registry.js +31 -20
- package/dist/mcp/schemaGenerator.d.ts +2 -7
- package/dist/mcp/schemaGenerator.js +41 -116
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +1 -0
- package/dist/mcp/serviceTokens.d.ts +16 -0
- package/dist/mcp/serviceTokens.js +345 -0
- package/dist/mcp/types.d.ts +2 -2
- package/dist/models/mcpServiceToken.d.ts +3 -0
- package/dist/models/mcpServiceToken.js +208 -0
- package/dist/openApiBuilder.d.ts +5 -4
- package/dist/openApiBuilder.js +61 -8
- package/dist/openApiCompat.js +1 -1
- package/dist/openApiValidator.js +0 -2
- package/dist/plugins.d.ts +14 -1
- package/dist/plugins.js +17 -6
- package/dist/populate.d.ts +2 -2
- package/dist/populate.js +47 -42
- package/dist/rateLimit/applyTrustProxy.d.ts +3 -0
- package/dist/rateLimit/applyTrustProxy.js +17 -0
- package/dist/rateLimit/createStore.d.ts +2 -0
- package/dist/rateLimit/createStore.js +28 -0
- package/dist/rateLimit/memoryStore.d.ts +2 -0
- package/dist/rateLimit/memoryStore.js +108 -0
- package/dist/rateLimit/middleware.d.ts +11 -0
- package/dist/rateLimit/middleware.js +110 -0
- package/dist/rateLimit/mongoStore.d.ts +3 -0
- package/dist/rateLimit/mongoStore.js +122 -0
- package/dist/rateLimit/policies.d.ts +14 -0
- package/dist/rateLimit/policies.js +151 -0
- package/dist/rateLimit/redisStore.d.ts +3 -0
- package/dist/rateLimit/redisStore.js +155 -0
- package/dist/rateLimit/types.d.ts +54 -0
- package/dist/rateLimit/types.js +9 -0
- package/dist/rbac/access.js +5 -1
- package/dist/rbac/assertAllowed.d.ts +9 -0
- package/dist/rbac/assertAllowed.js +182 -0
- package/dist/rbac/modelRouterAccess.d.ts +1 -0
- package/dist/rbac/modelRouterAccess.js +8 -4
- package/dist/rbac/permissionUtils.js +3 -2
- package/dist/rbac/resolve.js +5 -4
- package/dist/rbac/routes.js +15 -6
- package/dist/realtime/deprecation.d.ts +12 -0
- package/dist/realtime/deprecation.js +32 -0
- package/dist/realtime/realtimeApp.d.ts +1 -1
- package/dist/realtime/realtimeApp.js +10 -11
- package/dist/realtime/registry.d.ts +0 -31
- package/dist/realtime/registry.js +44 -31
- package/dist/realtime/socketAuth.d.ts +5 -5
- package/dist/realtime/socketAuth.js +11 -1
- package/dist/realtime/socketUser.d.ts +5 -1
- package/dist/realtime/types.d.ts +14 -4
- package/dist/schemaMetadata.d.ts +56 -0
- package/dist/schemaMetadata.js +513 -0
- package/dist/seedRunner.d.ts +88 -0
- package/dist/seedRunner.js +627 -0
- package/dist/sync/executors.d.ts +12 -2
- package/dist/sync/executors.js +8 -10
- package/dist/sync/loadHarness.js +28 -19
- package/dist/sync/models.js +26 -24
- package/dist/sync/mutationHandler.d.ts +9 -0
- package/dist/sync/mutationHandler.js +11 -6
- package/dist/sync/registrationSideEffects.d.ts +35 -0
- package/dist/sync/registrationSideEffects.js +151 -0
- package/dist/sync/registry.d.ts +2 -52
- package/dist/sync/registry.js +38 -187
- package/dist/sync/routes.js +3 -2
- package/dist/sync/scripts/compactTombstones.js +0 -2
- package/dist/sync/syncApp.d.ts +3 -3
- package/dist/sync/syncApp.js +4 -4
- package/dist/sync/syncBatch.js +3 -2
- package/dist/sync/syncSeqPlugin.d.ts +1 -1
- package/dist/sync/syncSeqPlugin.js +20 -16
- package/dist/terrenoApp.d.ts +19 -5
- package/dist/terrenoApp.js +66 -18
- package/dist/tests/models.d.ts +2 -0
- package/dist/tests/models.js +6 -0
- package/dist/types/authToken.d.ts +33 -0
- package/dist/types/authToken.js +2 -0
- package/dist/types/mcpServiceToken.d.ts +41 -0
- package/dist/types/mcpServiceToken.js +2 -0
- package/dist/webhooks/headerValue.d.ts +2 -0
- package/dist/webhooks/headerValue.js +14 -0
- package/dist/webhooks/idempotency/memoryStore.d.ts +10 -0
- package/dist/webhooks/idempotency/memoryStore.js +65 -0
- package/dist/webhooks/idempotency/mongoStore.d.ts +4 -0
- package/dist/webhooks/idempotency/mongoStore.js +150 -0
- package/dist/webhooks/idempotency/webhookReceipt.d.ts +62 -0
- package/dist/webhooks/idempotency/webhookReceipt.js +39 -0
- package/dist/webhooks/rawBody.d.ts +14 -0
- package/dist/webhooks/rawBody.js +22 -0
- package/dist/webhooks/timingSafeEqual.d.ts +4 -0
- package/dist/webhooks/timingSafeEqual.js +17 -0
- package/dist/webhooks/verifiers/hmac.d.ts +15 -0
- package/dist/webhooks/verifiers/hmac.js +49 -0
- package/dist/webhooks/verifiers/sendgrid.d.ts +10 -0
- package/dist/webhooks/verifiers/sendgrid.js +56 -0
- package/dist/webhooks/verifiers/stripe.d.ts +9 -0
- package/dist/webhooks/verifiers/stripe.js +99 -0
- package/dist/webhooks/verifiers/twilio.d.ts +9 -0
- package/dist/webhooks/verifiers/twilio.js +112 -0
- package/dist/webhooks/webhooksApp.d.ts +33 -0
- package/dist/webhooks/webhooksApp.js +195 -0
- package/package.json +4 -5
- package/src/__snapshots__/openApi.test.ts.snap +270 -0
- package/src/__snapshots__/openApiBuilder.test.ts.snap +30 -12
- package/src/__snapshots__/schemaMetadata.test.ts.snap +197 -0
- package/src/actions.ts +20 -13
- package/src/adminModelRouter.test.ts +133 -0
- package/src/api.arrayOperations.test.ts +43 -31
- package/src/api.hooks.test.ts +38 -29
- package/src/api.query.test.ts +31 -31
- package/src/api.test.ts +95 -96
- package/src/api.ts +16 -27
- package/src/auth.test.ts +107 -51
- package/src/auth.ts +98 -29
- package/src/authRecovery.test.ts +281 -0
- package/src/authRecovery.ts +279 -0
- package/src/authTokens.test.ts +94 -0
- package/src/authTokens.ts +118 -0
- package/src/authVerification.test.ts +293 -0
- package/src/betterAuth.ts +24 -0
- package/src/betterAuthApp.test.ts +1 -0
- package/src/betterAuthApp.ts +27 -9
- package/src/betterAuthSetup.test.ts +568 -38
- package/src/betterAuthSetup.ts +260 -5
- package/src/collectionRegistry.test.ts +165 -0
- package/src/collectionRegistry.ts +115 -0
- package/src/configurationApp.ts +13 -7
- package/src/docLoader.test.ts +45 -1
- package/src/docLoader.ts +37 -6
- package/src/express.d.ts +1 -0
- package/src/expressServer.test.ts +130 -66
- package/src/expressServer.ts +75 -19
- package/src/githubAuth.test.ts +60 -55
- package/src/index.ts +58 -0
- package/src/mcp/auth.test.ts +47 -0
- package/src/mcp/auth.ts +32 -11
- package/src/mcp/handlers.ts +45 -172
- package/src/mcp/integration.test.ts +59 -9
- package/src/mcp/query.ts +2 -4
- package/src/mcp/registry.ts +29 -20
- package/src/mcp/schemaGenerator.test.ts +8 -0
- package/src/mcp/schemaGenerator.ts +49 -131
- package/src/mcp/server.ts +2 -0
- package/src/mcp/serviceTokens.test.ts +330 -0
- package/src/mcp/serviceTokens.ts +307 -0
- package/src/mcp/toolGenerator.test.ts +1 -1
- package/src/mcp/types.ts +2 -6
- package/src/models/mcpServiceToken.test.ts +129 -0
- package/src/models/mcpServiceToken.ts +158 -0
- package/src/openApi.test.ts +80 -64
- package/src/openApiBuilder.test.ts +95 -7
- package/src/openApiBuilder.ts +46 -9
- package/src/openApiCompat.ts +1 -1
- package/src/openApiValidator.test.ts +49 -54
- package/src/openApiValidator.ts +1 -3
- package/src/plugins.test.ts +14 -0
- package/src/plugins.ts +34 -9
- package/src/populate.test.ts +34 -0
- package/src/populate.ts +40 -29
- package/src/rateLimit/applyTrustProxy.ts +17 -0
- package/src/rateLimit/createStore.ts +25 -0
- package/src/rateLimit/memoryStore.ts +40 -0
- package/src/rateLimit/middleware.ts +79 -0
- package/src/rateLimit/mongoStore.test.ts +80 -0
- package/src/rateLimit/mongoStore.ts +76 -0
- package/src/rateLimit/policies.ts +130 -0
- package/src/rateLimit/rateLimit.test.ts +328 -0
- package/src/rateLimit/redisStore.ioredis.test.ts +29 -0
- package/src/rateLimit/redisStore.test.ts +114 -0
- package/src/rateLimit/redisStore.ts +85 -0
- package/src/rateLimit/types.ts +64 -0
- package/src/rbac/access.ts +5 -1
- package/src/rbac/assertAllowed.test.ts +325 -0
- package/src/rbac/assertAllowed.ts +157 -0
- package/src/rbac/backfillAdmins.test.ts +124 -0
- package/src/rbac/fieldViews.test.ts +89 -0
- package/src/rbac/modelRouterAccess.test.ts +126 -0
- package/src/rbac/modelRouterAccess.ts +5 -2
- package/src/rbac/permissionUtils.ts +3 -2
- package/src/rbac/realtimeAccess.test.ts +109 -1
- package/src/rbac/resolve.ts +5 -4
- package/src/rbac/roleManager.test.ts +169 -0
- package/src/rbac/routes.test.ts +233 -0
- package/src/rbac/routes.ts +16 -6
- package/src/realtime/deprecation.test.ts +60 -0
- package/src/realtime/deprecation.ts +32 -0
- package/src/realtime/realtime.test.ts +8 -4
- package/src/realtime/realtimeApp.ts +10 -11
- package/src/realtime/realtimeAppSetup.test.ts +32 -5
- package/src/realtime/registry.ts +48 -42
- package/src/realtime/sessionRevalidation.test.ts +57 -44
- package/src/realtime/socketAuth.test.ts +75 -23
- package/src/realtime/socketAuth.ts +17 -6
- package/src/realtime/socketUser.ts +5 -3
- package/src/realtime/types.ts +14 -4
- package/src/schemaMetadata.test.ts +405 -0
- package/src/schemaMetadata.ts +593 -0
- package/src/scrubAdminFields.test.ts +105 -0
- package/src/seedRunner.test.ts +591 -0
- package/src/seedRunner.ts +464 -0
- package/src/sync/docMatchesMutationData.test.ts +16 -0
- package/src/sync/ensureSyncIndexes.test.ts +54 -15
- package/src/sync/executors.test.ts +40 -0
- package/src/sync/executors.ts +24 -12
- package/src/sync/integration.test.ts +15 -7
- package/src/sync/loadHarness.ts +28 -19
- package/src/sync/models.ts +32 -18
- package/src/sync/mutationHandler.test.ts +16 -16
- package/src/sync/mutationHandler.ts +9 -7
- package/src/sync/registrationSideEffects.test.ts +126 -0
- package/src/sync/registrationSideEffects.ts +131 -0
- package/src/sync/registry.ts +45 -171
- package/src/sync/routes.ts +3 -2
- package/src/sync/scripts/compactTombstones.ts +0 -2
- package/src/sync/sessionRevalidationIntegration.test.ts +12 -11
- package/src/sync/sync.test.ts +25 -23
- package/src/sync/syncApp.ts +4 -4
- package/src/sync/syncBatch.ts +3 -2
- package/src/sync/syncFrontier.test.ts +17 -15
- package/src/sync/syncPhaseC.test.ts +54 -43
- package/src/sync/syncRoutes.test.ts +51 -36
- package/src/sync/syncSeqPlugin.ts +66 -44
- package/src/sync/syncSocket.test.ts +112 -81
- package/src/terrenoApp.mcpServiceTokens.test.ts +173 -0
- package/src/terrenoApp.ts +87 -15
- package/src/tests/models.ts +14 -1
- package/src/types/authToken.ts +43 -0
- package/src/types/mcpServiceToken.ts +54 -0
- package/src/webhooks/headerValue.test.ts +22 -0
- package/src/webhooks/headerValue.ts +12 -0
- package/src/webhooks/idempotency/memoryStore.ts +34 -0
- package/src/webhooks/idempotency/mongoStore.test.ts +274 -0
- package/src/webhooks/idempotency/mongoStore.ts +83 -0
- package/src/webhooks/idempotency/webhookReceipt.ts +70 -0
- package/src/webhooks/rawBody.test.ts +74 -0
- package/src/webhooks/rawBody.ts +23 -0
- package/src/webhooks/timingSafeEqual.ts +16 -0
- package/src/webhooks/verifiers/hmac.test.ts +110 -0
- package/src/webhooks/verifiers/hmac.ts +54 -0
- package/src/webhooks/verifiers/providerVerifiers.test.ts +388 -0
- package/src/webhooks/verifiers/sendgrid.ts +59 -0
- package/src/webhooks/verifiers/stripe.ts +67 -0
- package/src/webhooks/verifiers/twilio.ts +69 -0
- package/src/webhooks/webhooksApp.test.ts +221 -0
- package/src/webhooks/webhooksApp.ts +144 -0
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
// noExplicitAny: test mock typing
|
|
2
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
3
1
|
import {beforeEach, describe, expect, it} from "bun:test";
|
|
4
2
|
import type express from "express";
|
|
5
3
|
import supertest from "supertest";
|
|
6
4
|
import type TestAgent from "supertest/lib/agent";
|
|
7
5
|
|
|
8
6
|
import {modelRouter} from "./api";
|
|
9
|
-
import {addAuthRoutes, setupAuth} from "./auth";
|
|
7
|
+
import {type UserModel as AuthUserModel, addAuthRoutes, setupAuth} from "./auth";
|
|
10
8
|
import {Permissions} from "./permissions";
|
|
11
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
authAsUser,
|
|
11
|
+
type Food,
|
|
12
|
+
type FoodCategory,
|
|
13
|
+
FoodModel,
|
|
14
|
+
getBaseServer,
|
|
15
|
+
setupDb,
|
|
16
|
+
UserModel,
|
|
17
|
+
} from "./tests";
|
|
12
18
|
import {AdminOwnerTransformer} from "./transformers";
|
|
13
19
|
|
|
20
|
+
type TestUser = Awaited<ReturnType<typeof setupDb>>[number];
|
|
21
|
+
|
|
14
22
|
describe("model array operations", () => {
|
|
15
23
|
let _server: TestAgent;
|
|
16
24
|
let app: express.Application;
|
|
17
|
-
let admin:
|
|
25
|
+
let admin: TestUser;
|
|
18
26
|
let spinach: Food;
|
|
19
27
|
let apple: Food;
|
|
20
28
|
let agent: TestAgent;
|
|
@@ -56,8 +64,8 @@ describe("model array operations", () => {
|
|
|
56
64
|
]);
|
|
57
65
|
|
|
58
66
|
app = getBaseServer();
|
|
59
|
-
setupAuth(app, UserModel as
|
|
60
|
-
addAuthRoutes(app, UserModel as
|
|
67
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
68
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
61
69
|
app.use(
|
|
62
70
|
"/food",
|
|
63
71
|
modelRouter(FoodModel, {
|
|
@@ -197,8 +205,12 @@ describe("model array operations", () => {
|
|
|
197
205
|
.expect(200);
|
|
198
206
|
|
|
199
207
|
// Verify the updated category has a newer timestamp
|
|
200
|
-
const updatedCategory = res.body.data.categories.find(
|
|
201
|
-
|
|
208
|
+
const updatedCategory = res.body.data.categories.find(
|
|
209
|
+
(c: FoodCategory) => c._id === firstCategoryId
|
|
210
|
+
);
|
|
211
|
+
const unchangedCategory = res.body.data.categories.find(
|
|
212
|
+
(c: FoodCategory) => c._id === secondCategoryId
|
|
213
|
+
);
|
|
202
214
|
|
|
203
215
|
if (!updatedCategory || !unchangedCategory) {
|
|
204
216
|
throw new Error("Failed to find categories in response");
|
|
@@ -213,13 +225,13 @@ describe("model array operations", () => {
|
|
|
213
225
|
});
|
|
214
226
|
|
|
215
227
|
it("array operations call postUpdate with different copy of document", async () => {
|
|
216
|
-
let postUpdateDoc:
|
|
217
|
-
let postUpdatePrevDoc:
|
|
228
|
+
let postUpdateDoc: Food | undefined;
|
|
229
|
+
let postUpdatePrevDoc: Food | undefined;
|
|
218
230
|
let postUpdateCalled = false;
|
|
219
231
|
|
|
220
232
|
app = getBaseServer();
|
|
221
|
-
setupAuth(app, UserModel as
|
|
222
|
-
addAuthRoutes(app, UserModel as
|
|
233
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
234
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
223
235
|
app.use(
|
|
224
236
|
"/food",
|
|
225
237
|
modelRouter(FoodModel, {
|
|
@@ -231,7 +243,7 @@ describe("model array operations", () => {
|
|
|
231
243
|
read: [Permissions.IsAdmin],
|
|
232
244
|
update: [Permissions.IsAdmin],
|
|
233
245
|
},
|
|
234
|
-
postUpdate: async (doc
|
|
246
|
+
postUpdate: async (doc, _cleanedBody, _request, prevValue) => {
|
|
235
247
|
postUpdateDoc = doc;
|
|
236
248
|
postUpdatePrevDoc = prevValue;
|
|
237
249
|
postUpdateCalled = true;
|
|
@@ -282,10 +294,10 @@ describe("model array operations", () => {
|
|
|
282
294
|
|
|
283
295
|
// Verify the content is different (category updated)
|
|
284
296
|
const updatedCategory = postUpdateDoc.categories.find(
|
|
285
|
-
(c:
|
|
297
|
+
(c: FoodCategory) => c._id.toString() === categoryId.toString()
|
|
286
298
|
);
|
|
287
299
|
const prevCategory = postUpdatePrevDoc.categories.find(
|
|
288
|
-
(c:
|
|
300
|
+
(c: FoodCategory) => c._id.toString() === categoryId.toString()
|
|
289
301
|
);
|
|
290
302
|
|
|
291
303
|
expect(updatedCategory.name).toBe("Updated Category");
|
|
@@ -308,10 +320,10 @@ describe("model array operations", () => {
|
|
|
308
320
|
|
|
309
321
|
// Verify the content is different (category removed)
|
|
310
322
|
const remainingCategories = postUpdateDoc.categories.filter(
|
|
311
|
-
(c:
|
|
323
|
+
(c: FoodCategory) => c._id.toString() === categoryId.toString()
|
|
312
324
|
);
|
|
313
325
|
const prevCategories = postUpdatePrevDoc.categories.filter(
|
|
314
|
-
(c:
|
|
326
|
+
(c: FoodCategory) => c._id.toString() === categoryId.toString()
|
|
315
327
|
);
|
|
316
328
|
|
|
317
329
|
expect(remainingCategories).toHaveLength(0);
|
|
@@ -319,13 +331,13 @@ describe("model array operations", () => {
|
|
|
319
331
|
});
|
|
320
332
|
|
|
321
333
|
it("array operations with string arrays call postUpdate with different copy", async () => {
|
|
322
|
-
let postUpdateDoc:
|
|
323
|
-
let postUpdatePrevDoc:
|
|
334
|
+
let postUpdateDoc: Food | undefined;
|
|
335
|
+
let postUpdatePrevDoc: Food | undefined;
|
|
324
336
|
let postUpdateCalled = false;
|
|
325
337
|
|
|
326
338
|
app = getBaseServer();
|
|
327
|
-
setupAuth(app, UserModel as
|
|
328
|
-
addAuthRoutes(app, UserModel as
|
|
339
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
340
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
329
341
|
app.use(
|
|
330
342
|
"/food",
|
|
331
343
|
modelRouter(FoodModel, {
|
|
@@ -337,7 +349,7 @@ describe("model array operations", () => {
|
|
|
337
349
|
read: [Permissions.IsAdmin],
|
|
338
350
|
update: [Permissions.IsAdmin],
|
|
339
351
|
},
|
|
340
|
-
postUpdate: async (doc
|
|
352
|
+
postUpdate: async (doc, _cleanedBody, _request, prevValue) => {
|
|
341
353
|
postUpdateDoc = doc;
|
|
342
354
|
postUpdatePrevDoc = prevValue;
|
|
343
355
|
postUpdateCalled = true;
|
|
@@ -385,7 +397,7 @@ describe("model array operations", () => {
|
|
|
385
397
|
describe("array operation errors", () => {
|
|
386
398
|
let _server: TestAgent;
|
|
387
399
|
let app: express.Application;
|
|
388
|
-
let admin:
|
|
400
|
+
let admin: TestUser;
|
|
389
401
|
let apple: Food;
|
|
390
402
|
let agent: TestAgent;
|
|
391
403
|
|
|
@@ -406,8 +418,8 @@ describe("array operation errors", () => {
|
|
|
406
418
|
});
|
|
407
419
|
|
|
408
420
|
app = getBaseServer();
|
|
409
|
-
setupAuth(app, UserModel as
|
|
410
|
-
addAuthRoutes(app, UserModel as
|
|
421
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
422
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
411
423
|
});
|
|
412
424
|
|
|
413
425
|
it("array operation preUpdate returning undefined throws error", async () => {
|
|
@@ -422,7 +434,7 @@ describe("array operation errors", () => {
|
|
|
422
434
|
read: [Permissions.IsAdmin],
|
|
423
435
|
update: [Permissions.IsAdmin],
|
|
424
436
|
},
|
|
425
|
-
preUpdate: () => undefined as
|
|
437
|
+
preUpdate: () => undefined as unknown as Food,
|
|
426
438
|
})
|
|
427
439
|
);
|
|
428
440
|
_server = supertest(app);
|
|
@@ -601,7 +613,7 @@ describe("array operation errors", () => {
|
|
|
601
613
|
describe("array operation with undefined preUpdate return", () => {
|
|
602
614
|
let _server: TestAgent;
|
|
603
615
|
let app: express.Application;
|
|
604
|
-
let admin:
|
|
616
|
+
let admin: TestUser;
|
|
605
617
|
let apple: Food;
|
|
606
618
|
let agent: TestAgent;
|
|
607
619
|
|
|
@@ -622,8 +634,8 @@ describe("array operation with undefined preUpdate return", () => {
|
|
|
622
634
|
});
|
|
623
635
|
|
|
624
636
|
app = getBaseServer();
|
|
625
|
-
setupAuth(app, UserModel as
|
|
626
|
-
addAuthRoutes(app, UserModel as
|
|
637
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
638
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
627
639
|
});
|
|
628
640
|
|
|
629
641
|
it("array operation preUpdate returning undefined for array POST throws error", async () => {
|
|
@@ -638,7 +650,7 @@ describe("array operation with undefined preUpdate return", () => {
|
|
|
638
650
|
read: [Permissions.IsAdmin],
|
|
639
651
|
update: [Permissions.IsAdmin],
|
|
640
652
|
},
|
|
641
|
-
preUpdate: () => undefined as
|
|
653
|
+
preUpdate: () => undefined as unknown as Food,
|
|
642
654
|
})
|
|
643
655
|
);
|
|
644
656
|
_server = supertest(app);
|
package/src/api.hooks.test.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// noExplicitAny: test mock typing
|
|
2
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
3
1
|
import {beforeEach, describe, expect, it, type mock} from "bun:test";
|
|
4
2
|
import * as Sentry from "@sentry/bun";
|
|
5
3
|
import type express from "express";
|
|
@@ -7,10 +5,18 @@ import supertest from "supertest";
|
|
|
7
5
|
import type TestAgent from "supertest/lib/agent";
|
|
8
6
|
|
|
9
7
|
import {modelRouter} from "./api";
|
|
10
|
-
import {addAuthRoutes, setupAuth} from "./auth";
|
|
8
|
+
import {type UserModel as AuthUserModel, addAuthRoutes, setupAuth} from "./auth";
|
|
11
9
|
import {APIError} from "./errors";
|
|
12
10
|
import {Permissions} from "./permissions";
|
|
13
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
authAsUser,
|
|
13
|
+
type Food,
|
|
14
|
+
FoodModel,
|
|
15
|
+
getBaseServer,
|
|
16
|
+
setupDb,
|
|
17
|
+
type User,
|
|
18
|
+
UserModel,
|
|
19
|
+
} from "./tests";
|
|
14
20
|
|
|
15
21
|
const captureExceptionMock = Sentry.captureException as unknown as ReturnType<typeof mock>;
|
|
16
22
|
|
|
@@ -22,8 +28,8 @@ describe("pre and post hooks", () => {
|
|
|
22
28
|
beforeEach(async () => {
|
|
23
29
|
await setupDb();
|
|
24
30
|
app = getBaseServer();
|
|
25
|
-
setupAuth(app, UserModel as
|
|
26
|
-
addAuthRoutes(app, UserModel as
|
|
31
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
32
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
27
33
|
agent = await authAsUser(app, "notAdmin");
|
|
28
34
|
captureExceptionMock.mockClear?.();
|
|
29
35
|
});
|
|
@@ -41,15 +47,15 @@ describe("pre and post hooks", () => {
|
|
|
41
47
|
read: [Permissions.IsAny],
|
|
42
48
|
update: [Permissions.IsAny],
|
|
43
49
|
},
|
|
44
|
-
preCreate: (data
|
|
50
|
+
preCreate: (data) => {
|
|
45
51
|
data.calories = 14;
|
|
46
52
|
return data;
|
|
47
53
|
},
|
|
48
|
-
preDelete: (data
|
|
54
|
+
preDelete: (data) => {
|
|
49
55
|
deleteCalled = true;
|
|
50
56
|
return data;
|
|
51
57
|
},
|
|
52
|
-
preUpdate: (data
|
|
58
|
+
preUpdate: (data) => {
|
|
53
59
|
data.calories = 15;
|
|
54
60
|
return data;
|
|
55
61
|
},
|
|
@@ -95,7 +101,7 @@ describe("pre and post hooks", () => {
|
|
|
95
101
|
created: new Date("2021-12-03T00:00:20.000Z"),
|
|
96
102
|
hidden: false,
|
|
97
103
|
name: "Spinach",
|
|
98
|
-
ownerId:
|
|
104
|
+
ownerId: notAdmin?._id,
|
|
99
105
|
source: {
|
|
100
106
|
name: "Brand",
|
|
101
107
|
},
|
|
@@ -142,7 +148,7 @@ describe("pre and post hooks", () => {
|
|
|
142
148
|
let deleteCalled = false;
|
|
143
149
|
app.use(
|
|
144
150
|
"/food",
|
|
145
|
-
modelRouter(FoodModel
|
|
151
|
+
modelRouter(FoodModel, {
|
|
146
152
|
allowAnonymous: true,
|
|
147
153
|
permissions: {
|
|
148
154
|
create: [Permissions.IsAny],
|
|
@@ -151,16 +157,16 @@ describe("pre and post hooks", () => {
|
|
|
151
157
|
read: [Permissions.IsAny],
|
|
152
158
|
update: [Permissions.IsAny],
|
|
153
159
|
},
|
|
154
|
-
postCreate: async (data
|
|
160
|
+
postCreate: async (data) => {
|
|
155
161
|
data.calories = 14;
|
|
156
162
|
await data.save();
|
|
157
163
|
return data;
|
|
158
164
|
},
|
|
159
|
-
postDelete: (data
|
|
165
|
+
postDelete: (data) => {
|
|
160
166
|
deleteCalled = true;
|
|
161
167
|
return data;
|
|
162
168
|
},
|
|
163
|
-
postUpdate: async (data
|
|
169
|
+
postUpdate: async (data) => {
|
|
164
170
|
data.calories = 15;
|
|
165
171
|
await data.save();
|
|
166
172
|
return data;
|
|
@@ -253,8 +259,9 @@ describe("pre and post hooks", () => {
|
|
|
253
259
|
update: [Permissions.IsAny],
|
|
254
260
|
},
|
|
255
261
|
preCreate: () => {
|
|
256
|
-
const error
|
|
257
|
-
|
|
262
|
+
const error = Object.assign(new Error("Some custom error"), {
|
|
263
|
+
disableExternalErrorTracking: true,
|
|
264
|
+
});
|
|
258
265
|
throw error;
|
|
259
266
|
},
|
|
260
267
|
})
|
|
@@ -285,7 +292,7 @@ describe("pre and post hooks", () => {
|
|
|
285
292
|
created: new Date("2021-12-03T00:00:20.000Z"),
|
|
286
293
|
hidden: false,
|
|
287
294
|
name: "Spinach",
|
|
288
|
-
ownerId:
|
|
295
|
+
ownerId: notAdmin?._id,
|
|
289
296
|
source: {
|
|
290
297
|
name: "Brand",
|
|
291
298
|
},
|
|
@@ -336,7 +343,7 @@ describe("pre and post hooks", () => {
|
|
|
336
343
|
created: new Date("2021-12-03T00:00:20.000Z"),
|
|
337
344
|
hidden: false,
|
|
338
345
|
name: "Spinach",
|
|
339
|
-
ownerId:
|
|
346
|
+
ownerId: notAdmin?._id,
|
|
340
347
|
source: {
|
|
341
348
|
name: "Brand",
|
|
342
349
|
},
|
|
@@ -354,8 +361,9 @@ describe("pre and post hooks", () => {
|
|
|
354
361
|
update: [Permissions.IsAny],
|
|
355
362
|
},
|
|
356
363
|
preUpdate: () => {
|
|
357
|
-
const error
|
|
358
|
-
|
|
364
|
+
const error = Object.assign(new Error("Some custom error"), {
|
|
365
|
+
disableExternalErrorTracking: true,
|
|
366
|
+
});
|
|
359
367
|
throw error;
|
|
360
368
|
},
|
|
361
369
|
})
|
|
@@ -385,7 +393,7 @@ describe("pre and post hooks", () => {
|
|
|
385
393
|
created: new Date("2021-12-03T00:00:20.000Z"),
|
|
386
394
|
hidden: false,
|
|
387
395
|
name: "Spinach",
|
|
388
|
-
ownerId:
|
|
396
|
+
ownerId: notAdmin?._id,
|
|
389
397
|
source: {
|
|
390
398
|
name: "Brand",
|
|
391
399
|
},
|
|
@@ -403,8 +411,9 @@ describe("pre and post hooks", () => {
|
|
|
403
411
|
update: [Permissions.IsAny],
|
|
404
412
|
},
|
|
405
413
|
preDelete: () => {
|
|
406
|
-
const error
|
|
407
|
-
|
|
414
|
+
const error = Object.assign(new Error("Some custom error"), {
|
|
415
|
+
disableExternalErrorTracking: true,
|
|
416
|
+
});
|
|
408
417
|
throw error;
|
|
409
418
|
},
|
|
410
419
|
})
|
|
@@ -424,7 +433,7 @@ describe("pre and post hooks", () => {
|
|
|
424
433
|
describe("hook error handling", () => {
|
|
425
434
|
let server: TestAgent;
|
|
426
435
|
let app: express.Application;
|
|
427
|
-
let admin:
|
|
436
|
+
let admin: User;
|
|
428
437
|
let agent: TestAgent;
|
|
429
438
|
let spinach: Food;
|
|
430
439
|
|
|
@@ -443,8 +452,8 @@ describe("hook error handling", () => {
|
|
|
443
452
|
});
|
|
444
453
|
|
|
445
454
|
app = getBaseServer();
|
|
446
|
-
setupAuth(app, UserModel as
|
|
447
|
-
addAuthRoutes(app, UserModel as
|
|
455
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
456
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
448
457
|
captureExceptionMock.mockClear?.();
|
|
449
458
|
});
|
|
450
459
|
|
|
@@ -460,7 +469,7 @@ describe("hook error handling", () => {
|
|
|
460
469
|
read: [Permissions.IsAny],
|
|
461
470
|
update: [Permissions.IsAny],
|
|
462
471
|
},
|
|
463
|
-
preCreate: () => undefined as
|
|
472
|
+
preCreate: () => undefined as unknown as Food,
|
|
464
473
|
})
|
|
465
474
|
);
|
|
466
475
|
server = supertest(app);
|
|
@@ -482,7 +491,7 @@ describe("hook error handling", () => {
|
|
|
482
491
|
read: [Permissions.IsAny],
|
|
483
492
|
update: [Permissions.IsAny],
|
|
484
493
|
},
|
|
485
|
-
preUpdate: () => undefined as
|
|
494
|
+
preUpdate: () => undefined as unknown as Food,
|
|
486
495
|
})
|
|
487
496
|
);
|
|
488
497
|
server = supertest(app);
|
|
@@ -504,7 +513,7 @@ describe("hook error handling", () => {
|
|
|
504
513
|
read: [Permissions.IsAny],
|
|
505
514
|
update: [Permissions.IsAny],
|
|
506
515
|
},
|
|
507
|
-
preDelete: () => undefined as
|
|
516
|
+
preDelete: () => undefined as unknown as Food,
|
|
508
517
|
})
|
|
509
518
|
);
|
|
510
519
|
server = supertest(app);
|
package/src/api.query.test.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// noExplicitAny: test mock typing
|
|
2
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
3
1
|
import {beforeEach, describe, expect, it} from "bun:test";
|
|
4
2
|
import * as Sentry from "@sentry/bun";
|
|
5
3
|
import type express from "express";
|
|
@@ -8,17 +6,19 @@ import supertest from "supertest";
|
|
|
8
6
|
import type TestAgent from "supertest/lib/agent";
|
|
9
7
|
|
|
10
8
|
import {modelRouter} from "./api";
|
|
11
|
-
import {addAuthRoutes, setupAuth} from "./auth";
|
|
9
|
+
import {type UserModel as AuthUserModel, addAuthRoutes, setupAuth} from "./auth";
|
|
12
10
|
import {logRequests} from "./expressServer";
|
|
13
11
|
import {Permissions} from "./permissions";
|
|
14
12
|
import {authAsUser, type Food, FoodModel, getBaseServer, setupDb, UserModel} from "./tests";
|
|
15
13
|
|
|
14
|
+
type TestUser = Awaited<ReturnType<typeof setupDb>>[number];
|
|
15
|
+
|
|
16
16
|
describe("query and list methods", () => {
|
|
17
17
|
let server: TestAgent;
|
|
18
18
|
let app: express.Application;
|
|
19
|
-
let notAdmin:
|
|
20
|
-
let admin:
|
|
21
|
-
let adminOther:
|
|
19
|
+
let notAdmin: TestUser;
|
|
20
|
+
let admin: TestUser;
|
|
21
|
+
let adminOther: TestUser;
|
|
22
22
|
let agent: TestAgent;
|
|
23
23
|
|
|
24
24
|
let spinach: Food;
|
|
@@ -78,8 +78,8 @@ describe("query and list methods", () => {
|
|
|
78
78
|
])) as [Food, Food, Food, Food];
|
|
79
79
|
[spinach, apple, carrots, pizza] = results;
|
|
80
80
|
app = getBaseServer();
|
|
81
|
-
setupAuth(app, UserModel as
|
|
82
|
-
addAuthRoutes(app, UserModel as
|
|
81
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
82
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
83
83
|
app.use(logRequests);
|
|
84
84
|
app.use(
|
|
85
85
|
"/food",
|
|
@@ -126,9 +126,9 @@ describe("query and list methods", () => {
|
|
|
126
126
|
it("list default", async () => {
|
|
127
127
|
const res = await agent.get("/food").expect(200);
|
|
128
128
|
expect(res.body.data).toHaveLength(2);
|
|
129
|
-
expect(res.body.data[0].id).toBe((spinach
|
|
129
|
+
expect(res.body.data[0].id).toBe(String(spinach._id));
|
|
130
130
|
expect(res.body.data[0].ownerId._id).toBe(notAdmin.id);
|
|
131
|
-
expect(res.body.data[1].id).toBe((pizza
|
|
131
|
+
expect(res.body.data[1].id).toBe(String(pizza._id));
|
|
132
132
|
expect(res.body.data[1].ownerId._id).toBe(admin.id);
|
|
133
133
|
expect(res.body.data[0].lastEatenWith).toEqual({
|
|
134
134
|
dressing: "2021-12-03T19:00:30.000Z",
|
|
@@ -141,7 +141,7 @@ describe("query and list methods", () => {
|
|
|
141
141
|
it("list limit", async () => {
|
|
142
142
|
const res = await agent.get("/food?limit=1").expect(200);
|
|
143
143
|
expect(res.body.data).toHaveLength(1);
|
|
144
|
-
expect(res.body.data[0].id).toBe((spinach
|
|
144
|
+
expect(res.body.data[0].id).toBe(String(spinach._id));
|
|
145
145
|
expect(res.body.data[0].ownerId._id).toBe(notAdmin.id);
|
|
146
146
|
expect(res.body.more).toBe(true);
|
|
147
147
|
expect(res.body.total).toBe(3);
|
|
@@ -159,9 +159,9 @@ describe("query and list methods", () => {
|
|
|
159
159
|
expect(res.body.data).toHaveLength(3);
|
|
160
160
|
expect(res.body.more).toBe(true);
|
|
161
161
|
expect(res.body.total).toBe(4);
|
|
162
|
-
expect(res.body.data[0].id).toBe((spinach
|
|
163
|
-
expect(res.body.data[1].id).toBe((pizza
|
|
164
|
-
expect(res.body.data[2].id).toBe((carrots
|
|
162
|
+
expect(res.body.data[0].id).toBe(String(spinach._id));
|
|
163
|
+
expect(res.body.data[1].id).toBe(String(pizza._id));
|
|
164
|
+
expect(res.body.data[2].id).toBe(String(carrots._id));
|
|
165
165
|
|
|
166
166
|
expect(Sentry.captureMessage).toHaveBeenCalledWith(
|
|
167
167
|
'More than 3 results returned for foods without pagination, data may be silently truncated. req.query: {"limit":"4"}'
|
|
@@ -173,7 +173,7 @@ describe("query and list methods", () => {
|
|
|
173
173
|
expect(res.body.data).toHaveLength(1);
|
|
174
174
|
expect(res.body.more).toBe(true);
|
|
175
175
|
expect(res.body.total).toBe(3);
|
|
176
|
-
expect(res.body.data[0].id).toBe((pizza
|
|
176
|
+
expect(res.body.data[0].id).toBe(String(pizza._id));
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
it("list page 0 ", async () => {
|
|
@@ -202,7 +202,7 @@ describe("query and list methods", () => {
|
|
|
202
202
|
expect(res.body.data).toHaveLength(1);
|
|
203
203
|
expect(res.body.more).toBe(false);
|
|
204
204
|
expect(res.body.total).toBe(1);
|
|
205
|
-
expect(res.body.data[0].id).toBe((apple
|
|
205
|
+
expect(res.body.data[0].id).toBe(String(apple._id));
|
|
206
206
|
});
|
|
207
207
|
|
|
208
208
|
it("list applies created_gte and created_lte as a Date range", async () => {
|
|
@@ -291,7 +291,7 @@ describe("query and list methods", () => {
|
|
|
291
291
|
const res = await agent.get("/food?source.name=USDA").expect(200);
|
|
292
292
|
expect(res.body.data).toHaveLength(1);
|
|
293
293
|
expect(res.body.total).toBe(1);
|
|
294
|
-
expect(res.body.data[0].id).toBe((carrots
|
|
294
|
+
expect(res.body.data[0].id).toBe(String(carrots._id));
|
|
295
295
|
});
|
|
296
296
|
|
|
297
297
|
it("query by date", async () => {
|
|
@@ -312,14 +312,14 @@ describe("query and list methods", () => {
|
|
|
312
312
|
)
|
|
313
313
|
.set("authorization", `Bearer ${token}`)
|
|
314
314
|
.expect(200);
|
|
315
|
-
expect(res.body.data.map((d:
|
|
315
|
+
expect(res.body.data.map((d: Food) => d.created)).toEqual(
|
|
316
316
|
expect.arrayContaining([
|
|
317
317
|
"2021-12-03T00:00:20.000Z",
|
|
318
318
|
"2021-12-03T00:00:10.000Z",
|
|
319
319
|
"2021-12-03T00:00:00.000Z",
|
|
320
320
|
])
|
|
321
321
|
);
|
|
322
|
-
expect(res.body.data.map((d:
|
|
322
|
+
expect(res.body.data.map((d: Food) => d.created)).toHaveLength(3);
|
|
323
323
|
|
|
324
324
|
res = await server
|
|
325
325
|
.get(
|
|
@@ -332,10 +332,10 @@ describe("query and list methods", () => {
|
|
|
332
332
|
)
|
|
333
333
|
.set("authorization", `Bearer ${token}`)
|
|
334
334
|
.expect(200);
|
|
335
|
-
expect(res.body.data.map((d:
|
|
335
|
+
expect(res.body.data.map((d: Food) => d.created)).toEqual(
|
|
336
336
|
expect.arrayContaining(["2021-12-03T00:00:10.000Z", "2021-12-03T00:00:00.000Z"])
|
|
337
337
|
);
|
|
338
|
-
expect(res.body.data.map((d:
|
|
338
|
+
expect(res.body.data.map((d: Food) => d.created)).toHaveLength(2);
|
|
339
339
|
|
|
340
340
|
res = await server
|
|
341
341
|
.get(
|
|
@@ -348,7 +348,7 @@ describe("query and list methods", () => {
|
|
|
348
348
|
)
|
|
349
349
|
.set("authorization", `Bearer ${token}`)
|
|
350
350
|
.expect(200);
|
|
351
|
-
const createdDates = res.body.data.map((d:
|
|
351
|
+
const createdDates = res.body.data.map((d: Food) => d.created);
|
|
352
352
|
expect(createdDates).toEqual(expect.arrayContaining(["2021-12-03T00:00:10.000Z"]));
|
|
353
353
|
expect(createdDates).toHaveLength(1);
|
|
354
354
|
});
|
|
@@ -399,7 +399,7 @@ describe("query and list methods", () => {
|
|
|
399
399
|
})}`
|
|
400
400
|
)
|
|
401
401
|
.expect(200);
|
|
402
|
-
const names1 = res.body.data.map((d:
|
|
402
|
+
const names1 = res.body.data.map((d: Food) => d.name);
|
|
403
403
|
expect(names1).toEqual(expect.arrayContaining(["Spinach"]));
|
|
404
404
|
expect(names1).toHaveLength(1);
|
|
405
405
|
|
|
@@ -412,7 +412,7 @@ describe("query and list methods", () => {
|
|
|
412
412
|
})}`
|
|
413
413
|
)
|
|
414
414
|
.expect(200);
|
|
415
|
-
const names2 = res.body.data.map((d:
|
|
415
|
+
const names2 = res.body.data.map((d: Food) => d.name);
|
|
416
416
|
expect(names2).toEqual(expect.arrayContaining(["Spinach", "Carrots"]));
|
|
417
417
|
expect(names2).toHaveLength(2);
|
|
418
418
|
});
|
|
@@ -430,7 +430,7 @@ describe("query and list methods", () => {
|
|
|
430
430
|
expect(res.body.more).toBe(false);
|
|
431
431
|
expect(res.body.total).toBe(2);
|
|
432
432
|
expect(res.body.data).toHaveLength(2);
|
|
433
|
-
const names3 = res.body.data.map((d:
|
|
433
|
+
const names3 = res.body.data.map((d: Food) => d.name);
|
|
434
434
|
expect(names3).toEqual(expect.arrayContaining(["Carrots", "Pizza"]));
|
|
435
435
|
expect(names3).toHaveLength(2);
|
|
436
436
|
});
|
|
@@ -460,7 +460,7 @@ describe("query and list methods", () => {
|
|
|
460
460
|
.get(`/food?${qs.stringify({$or: [{name: "Carrots"}, {name: "Pizza"}]})}`)
|
|
461
461
|
.expect(200);
|
|
462
462
|
expect(res.body.data).toHaveLength(2);
|
|
463
|
-
const ids1 = res.body.data.map((d:
|
|
463
|
+
const ids1 = res.body.data.map((d: Food) => d.id);
|
|
464
464
|
expect(ids1).toEqual(expect.arrayContaining([carrots?._id.toString(), pizza?._id.toString()]));
|
|
465
465
|
expect(ids1).toHaveLength(2);
|
|
466
466
|
});
|
|
@@ -475,7 +475,7 @@ describe("query and list methods", () => {
|
|
|
475
475
|
)
|
|
476
476
|
.expect(200);
|
|
477
477
|
expect(res.body.data).toHaveLength(2);
|
|
478
|
-
const ids2 = res.body.data.map((d:
|
|
478
|
+
const ids2 = res.body.data.map((d: Food) => d.id);
|
|
479
479
|
expect(ids2).toEqual(
|
|
480
480
|
expect.arrayContaining([carrots?._id.toString(), spinach?._id.toString()])
|
|
481
481
|
);
|
|
@@ -558,7 +558,7 @@ describe("query and list methods", () => {
|
|
|
558
558
|
describe("special query params", () => {
|
|
559
559
|
let server: TestAgent;
|
|
560
560
|
let app: express.Application;
|
|
561
|
-
let admin:
|
|
561
|
+
let admin: TestUser;
|
|
562
562
|
|
|
563
563
|
beforeEach(async () => {
|
|
564
564
|
[admin] = await setupDb();
|
|
@@ -572,8 +572,8 @@ describe("special query params", () => {
|
|
|
572
572
|
});
|
|
573
573
|
|
|
574
574
|
app = getBaseServer();
|
|
575
|
-
setupAuth(app, UserModel as
|
|
576
|
-
addAuthRoutes(app, UserModel as
|
|
575
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
576
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
577
577
|
});
|
|
578
578
|
|
|
579
579
|
it("period query param is stripped from query", async () => {
|
|
@@ -629,6 +629,6 @@ describe("special query params", () => {
|
|
|
629
629
|
server = supertest(app);
|
|
630
630
|
|
|
631
631
|
const res = await server.get("/food?hidden=false").expect(200);
|
|
632
|
-
expect(res.body.data.every((f:
|
|
632
|
+
expect(res.body.data.every((f: Food) => f.hidden === false)).toBe(true);
|
|
633
633
|
});
|
|
634
634
|
});
|