@terreno/api 0.31.0 → 56.0.0-beta.2
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/dist/api.d.ts +10 -0
- package/dist/api.js +110 -361
- package/dist/auth.d.ts +26 -0
- package/dist/auth.js +121 -26
- package/dist/betterAuth.d.ts +5 -0
- package/dist/betterAuthSetup.js +23 -4
- package/dist/docLoader.js +12 -9
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +29 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +29 -1
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +16 -1
- package/dist/openApiCompat.d.ts +10 -1
- package/dist/openApiCompat.js +115 -47
- package/dist/permissions.d.ts +27 -0
- package/dist/permissions.js +42 -1
- package/dist/plugins.d.ts +13 -0
- package/dist/plugins.js +47 -1
- package/dist/realtime/changeStreamWatcher.d.ts +100 -3
- package/dist/realtime/changeStreamWatcher.js +542 -137
- package/dist/realtime/realtimeApp.d.ts +2 -0
- package/dist/realtime/realtimeApp.js +83 -27
- package/dist/realtime/sessionRevalidation.d.ts +90 -0
- package/dist/realtime/sessionRevalidation.js +438 -0
- package/dist/realtime/socketAuth.d.ts +97 -0
- package/dist/realtime/socketAuth.js +272 -0
- package/dist/realtime/socketUser.d.ts +54 -0
- package/dist/realtime/socketUser.js +75 -5
- package/dist/realtime/types.d.ts +54 -0
- package/dist/secretProviders.d.ts +23 -0
- package/dist/secretProviders.js +9 -3
- package/dist/sync/executors.d.ts +198 -0
- package/dist/sync/executors.js +670 -0
- package/dist/sync/loadHarness.js +807 -0
- package/dist/sync/models.d.ts +216 -0
- package/dist/sync/models.js +644 -0
- package/dist/sync/mutationHandler.d.ts +97 -0
- package/dist/sync/mutationHandler.js +886 -0
- package/dist/sync/registry.d.ts +73 -0
- package/dist/sync/registry.js +223 -0
- package/dist/sync/routes.d.ts +62 -0
- package/dist/sync/routes.js +936 -0
- package/dist/sync/scripts/compactTombstones.d.ts +47 -0
- package/dist/sync/scripts/compactTombstones.js +270 -0
- package/dist/sync/serialize.d.ts +20 -0
- package/dist/{tests/bunSetup.js → sync/serialize.js} +35 -68
- package/dist/sync/socketHandlers.d.ts +54 -0
- package/dist/sync/socketHandlers.js +470 -0
- package/dist/sync/streams.d.ts +85 -0
- package/dist/sync/streams.js +221 -0
- package/dist/sync/syncApp.d.ts +29 -0
- package/dist/sync/syncApp.js +44 -0
- package/dist/sync/syncBatch.d.ts +71 -0
- package/dist/sync/syncBatch.js +252 -0
- package/dist/sync/syncSeqPlugin.d.ts +8 -0
- package/dist/sync/syncSeqPlugin.js +899 -0
- package/dist/sync/types.d.ts +254 -0
- package/dist/sync/types.js +9 -0
- package/dist/terrenoApp.js +90 -27
- package/dist/vendor/wesleytodd-openapi/index.d.ts +1 -1
- package/dist/vendor/wesleytodd-openapi/lib/ui.d.ts +2 -1
- package/package.json +7 -6
- package/src/__tests__/openApiCompat.test.ts +20 -0
- package/src/api.errors.test.ts +32 -23
- package/src/api.test.ts +12 -0
- package/src/api.ts +87 -296
- package/src/auth.test.ts +202 -0
- package/src/auth.ts +134 -23
- package/src/betterAuth.ts +6 -0
- package/src/betterAuthSetup.test.ts +34 -0
- package/src/betterAuthSetup.ts +20 -1
- package/src/configuration.test.ts +59 -38
- package/src/configurationPlugin.test.ts +72 -42
- package/src/docLoader.ts +3 -1
- package/src/errors.ts +33 -0
- package/src/expressServer.test.ts +7 -1
- package/src/index.ts +42 -0
- package/src/middleware.test.ts +56 -1
- package/src/middleware.ts +15 -0
- package/src/openApiCompat.ts +99 -45
- package/src/permissions.test.ts +101 -17
- package/src/permissions.ts +49 -0
- package/src/plugins.test.ts +64 -0
- package/src/plugins.ts +56 -0
- package/src/realtime/changeStreamWatcher.ts +552 -114
- package/src/realtime/realtime.test.ts +157 -0
- package/src/realtime/realtimeApp.ts +82 -14
- package/src/realtime/realtimeAppSetup.test.ts +25 -27
- package/src/realtime/sessionRevalidation.test.ts +423 -0
- package/src/realtime/sessionRevalidation.ts +273 -0
- package/src/realtime/socketAuth.test.ts +355 -0
- package/src/realtime/socketAuth.ts +228 -0
- package/src/realtime/socketUser.ts +69 -0
- package/src/realtime/types.ts +54 -0
- package/src/secretProviders.test.ts +7 -1
- package/src/secretProviders.ts +15 -3
- package/src/secretProvidersGcpClient.test.ts +66 -0
- package/src/sync/ensureSyncIndexes.test.ts +144 -0
- package/src/sync/executors.test.ts +882 -0
- package/src/sync/executors.ts +705 -0
- package/src/sync/integration.test.ts +1160 -0
- package/src/sync/loadHarness.ts +618 -0
- package/src/sync/models.ts +641 -0
- package/src/sync/mutationHandler.test.ts +1252 -0
- package/src/sync/mutationHandler.ts +850 -0
- package/src/sync/registry.ts +232 -0
- package/src/sync/routes.ts +812 -0
- package/src/sync/scripts/compactTombstones.test.ts +249 -0
- package/src/sync/scripts/compactTombstones.ts +145 -0
- package/src/sync/serialize.ts +48 -0
- package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
- package/src/sync/socketHandlers.ts +320 -0
- package/src/sync/streams.ts +188 -0
- package/src/sync/sync.test.ts +582 -0
- package/src/sync/syncApp.ts +44 -0
- package/src/sync/syncBatch.ts +219 -0
- package/src/sync/syncFrontier.test.ts +494 -0
- package/src/sync/syncPhaseC.test.ts +718 -0
- package/src/sync/syncRoutes.test.ts +865 -0
- package/src/sync/syncSeqPlugin.ts +730 -0
- package/src/sync/syncSocket.test.ts +1440 -0
- package/src/sync/types.ts +270 -0
- package/src/terrenoApp.ts +37 -17
- package/src/tests/bunSetup.ts +8 -0
- package/tsconfig.json +4 -4
- package/tsconfig.typedoc.json +7 -1
- package/dist/__tests__/openApiCompat.test.js +0 -317
- package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
- package/dist/__tests__/versionCheckPlugin.test.js +0 -597
- package/dist/actions.openApi.test.d.ts +0 -1
- package/dist/actions.openApi.test.js +0 -253
- package/dist/actions.test.d.ts +0 -1
- package/dist/actions.test.js +0 -1087
- package/dist/api.arrayOperations.test.d.ts +0 -1
- package/dist/api.arrayOperations.test.js +0 -878
- package/dist/api.asyncHandler.test.d.ts +0 -1
- package/dist/api.asyncHandler.test.js +0 -236
- package/dist/api.coverage.test.d.ts +0 -1
- package/dist/api.coverage.test.js +0 -192
- package/dist/api.errorPaths.test.d.ts +0 -1
- package/dist/api.errorPaths.test.js +0 -887
- package/dist/api.errors.test.d.ts +0 -1
- package/dist/api.errors.test.js +0 -185
- package/dist/api.hooks.test.d.ts +0 -1
- package/dist/api.hooks.test.js +0 -950
- package/dist/api.query.test.d.ts +0 -1
- package/dist/api.query.test.js +0 -948
- package/dist/api.test.d.ts +0 -1
- package/dist/api.test.js +0 -2820
- package/dist/auth.compile.test.d.ts +0 -1
- package/dist/auth.compile.test.js +0 -201
- package/dist/auth.coverage.test.d.ts +0 -1
- package/dist/auth.coverage.test.js +0 -202
- package/dist/auth.test.d.ts +0 -1
- package/dist/auth.test.js +0 -2286
- package/dist/betterAuth.test.d.ts +0 -1
- package/dist/betterAuth.test.js +0 -181
- package/dist/betterAuthApp.test.d.ts +0 -1
- package/dist/betterAuthApp.test.js +0 -242
- package/dist/betterAuthSetup.test.d.ts +0 -1
- package/dist/betterAuthSetup.test.js +0 -762
- package/dist/config.test.d.ts +0 -1
- package/dist/config.test.js +0 -353
- package/dist/configuration.test.d.ts +0 -1
- package/dist/configuration.test.js +0 -980
- package/dist/configurationPlugin.test.d.ts +0 -1
- package/dist/configurationPlugin.test.js +0 -827
- package/dist/consentApp.test.d.ts +0 -1
- package/dist/consentApp.test.js +0 -1411
- package/dist/docLoader.test.d.ts +0 -1
- package/dist/docLoader.test.js +0 -137
- package/dist/envConfigurationPlugin.test.d.ts +0 -1
- package/dist/envConfigurationPlugin.test.js +0 -369
- package/dist/errors.test.d.ts +0 -1
- package/dist/errors.test.js +0 -607
- package/dist/expressServer.test.d.ts +0 -1
- package/dist/expressServer.test.js +0 -1249
- package/dist/githubAuth.test.d.ts +0 -1
- package/dist/githubAuth.test.js +0 -1142
- package/dist/httpClient.test.d.ts +0 -1
- package/dist/httpClient.test.js +0 -1471
- package/dist/logger.test.d.ts +0 -1
- package/dist/logger.test.js +0 -685
- package/dist/middleware.test.d.ts +0 -1
- package/dist/middleware.test.js +0 -241
- package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
- package/dist/notifiers/googleChatNotifier.test.js +0 -298
- package/dist/notifiers/slackNotifier.test.d.ts +0 -1
- package/dist/notifiers/slackNotifier.test.js +0 -297
- package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
- package/dist/notifiers/zoomNotifier.test.js +0 -373
- package/dist/openApi.test.d.ts +0 -1
- package/dist/openApi.test.js +0 -620
- package/dist/openApiBuilder.test.d.ts +0 -1
- package/dist/openApiBuilder.test.js +0 -599
- package/dist/openApiEtag.test.d.ts +0 -1
- package/dist/openApiEtag.test.js +0 -86
- package/dist/openApiValidator.test.d.ts +0 -1
- package/dist/openApiValidator.test.js +0 -795
- package/dist/permissions.middleware.test.d.ts +0 -1
- package/dist/permissions.middleware.test.js +0 -308
- package/dist/permissions.test.d.ts +0 -1
- package/dist/permissions.test.js +0 -439
- package/dist/plugins.test.d.ts +0 -1
- package/dist/plugins.test.js +0 -902
- package/dist/populate.test.d.ts +0 -1
- package/dist/populate.test.js +0 -370
- package/dist/realtime/realtime.test.d.ts +0 -10
- package/dist/realtime/realtime.test.js +0 -4213
- package/dist/realtime/realtimeAppSetup.test.d.ts +0 -1
- package/dist/realtime/realtimeAppSetup.test.js +0 -213
- package/dist/requestContext.test.d.ts +0 -1
- package/dist/requestContext.test.js +0 -412
- package/dist/scriptRunner.test.d.ts +0 -1
- package/dist/scriptRunner.test.js +0 -386
- package/dist/secretProviders.test.d.ts +0 -1
- package/dist/secretProviders.test.js +0 -726
- package/dist/syncConsents.test.d.ts +0 -1
- package/dist/syncConsents.test.js +0 -522
- package/dist/terrenoApp.test.d.ts +0 -1
- package/dist/terrenoApp.test.js +0 -489
- package/dist/tests/bunSetup.d.ts +0 -1
- package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
- package/dist/tests/fixtures/compileAuthEntry.js +0 -37
- package/dist/tests/testEnv.d.ts +0 -0
- package/dist/tests/testEnv.js +0 -6
- package/dist/transformers.test.d.ts +0 -1
- package/dist/transformers.test.js +0 -423
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -242
- /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
package/dist/permissions.test.js
DELETED
|
@@ -1,439 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
// noExplicitAny: test mock typing
|
|
43
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
44
|
-
var bun_test_1 = require("bun:test");
|
|
45
|
-
var supertest_1 = __importDefault(require("supertest"));
|
|
46
|
-
var api_1 = require("./api");
|
|
47
|
-
var auth_1 = require("./auth");
|
|
48
|
-
var permissions_1 = require("./permissions");
|
|
49
|
-
var tests_1 = require("./tests");
|
|
50
|
-
(0, bun_test_1.describe)("permissions", function () {
|
|
51
|
-
var server;
|
|
52
|
-
var app;
|
|
53
|
-
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
-
return __generator(this, function (_a) {
|
|
55
|
-
switch (_a.label) {
|
|
56
|
-
case 0:
|
|
57
|
-
process.env.REFRESH_TOKEN_SECRET = "testsecret1234";
|
|
58
|
-
return [4 /*yield*/, (0, tests_1.setupTestData)()];
|
|
59
|
-
case 1:
|
|
60
|
-
_a.sent();
|
|
61
|
-
app = (0, tests_1.getBaseServer)();
|
|
62
|
-
(0, auth_1.setupAuth)(app, tests_1.UserModel);
|
|
63
|
-
(0, auth_1.addAuthRoutes)(app, tests_1.UserModel);
|
|
64
|
-
app.use("/food", (0, api_1.modelRouter)(tests_1.FoodModel, {
|
|
65
|
-
allowAnonymous: true,
|
|
66
|
-
permissions: {
|
|
67
|
-
create: [permissions_1.Permissions.IsAuthenticated],
|
|
68
|
-
delete: [permissions_1.Permissions.IsAdmin],
|
|
69
|
-
list: [permissions_1.Permissions.IsAny],
|
|
70
|
-
read: [permissions_1.Permissions.IsAny],
|
|
71
|
-
update: [permissions_1.Permissions.IsOwner],
|
|
72
|
-
},
|
|
73
|
-
}));
|
|
74
|
-
app.use("/required", (0, api_1.modelRouter)(tests_1.RequiredModel, {
|
|
75
|
-
permissions: {
|
|
76
|
-
create: [permissions_1.Permissions.IsAuthenticated],
|
|
77
|
-
delete: [permissions_1.Permissions.IsAdmin],
|
|
78
|
-
list: [permissions_1.Permissions.IsAny],
|
|
79
|
-
read: [permissions_1.Permissions.IsAny],
|
|
80
|
-
update: [permissions_1.Permissions.IsOwner],
|
|
81
|
-
},
|
|
82
|
-
}));
|
|
83
|
-
server = (0, supertest_1.default)(app);
|
|
84
|
-
return [2 /*return*/];
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}); });
|
|
88
|
-
(0, bun_test_1.describe)("anonymous food", function () {
|
|
89
|
-
(0, bun_test_1.it)("list", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
-
var res;
|
|
91
|
-
return __generator(this, function (_a) {
|
|
92
|
-
switch (_a.label) {
|
|
93
|
-
case 0: return [4 /*yield*/, server.get("/food").expect(200)];
|
|
94
|
-
case 1:
|
|
95
|
-
res = _a.sent();
|
|
96
|
-
(0, bun_test_1.expect)(res.body.data).toHaveLength(4);
|
|
97
|
-
return [2 /*return*/];
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}); });
|
|
101
|
-
(0, bun_test_1.it)("get", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
102
|
-
var res, res2;
|
|
103
|
-
return __generator(this, function (_a) {
|
|
104
|
-
switch (_a.label) {
|
|
105
|
-
case 0: return [4 /*yield*/, server.get("/food").expect(200)];
|
|
106
|
-
case 1:
|
|
107
|
-
res = _a.sent();
|
|
108
|
-
(0, bun_test_1.expect)(res.body.data).toHaveLength(4);
|
|
109
|
-
return [4 /*yield*/, server.get("/food/".concat(res.body.data[0]._id)).expect(200)];
|
|
110
|
-
case 2:
|
|
111
|
-
res2 = _a.sent();
|
|
112
|
-
(0, bun_test_1.expect)(res.body.data[0]._id).toBe(res2.body.data._id);
|
|
113
|
-
return [2 /*return*/];
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}); });
|
|
117
|
-
(0, bun_test_1.it)("post", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
118
|
-
var res;
|
|
119
|
-
return __generator(this, function (_a) {
|
|
120
|
-
switch (_a.label) {
|
|
121
|
-
case 0: return [4 /*yield*/, server.post("/food").send({
|
|
122
|
-
calories: 15,
|
|
123
|
-
name: "Broccoli",
|
|
124
|
-
})];
|
|
125
|
-
case 1:
|
|
126
|
-
res = _a.sent();
|
|
127
|
-
(0, bun_test_1.expect)(res.status).toBe(405);
|
|
128
|
-
return [2 /*return*/];
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}); });
|
|
132
|
-
(0, bun_test_1.it)("patch", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
-
var res, res2;
|
|
134
|
-
return __generator(this, function (_a) {
|
|
135
|
-
switch (_a.label) {
|
|
136
|
-
case 0: return [4 /*yield*/, server.get("/food")];
|
|
137
|
-
case 1:
|
|
138
|
-
res = _a.sent();
|
|
139
|
-
return [4 /*yield*/, server.patch("/food/".concat(res.body.data[0]._id)).send({
|
|
140
|
-
name: "Broccoli",
|
|
141
|
-
})];
|
|
142
|
-
case 2:
|
|
143
|
-
res2 = _a.sent();
|
|
144
|
-
(0, bun_test_1.expect)(res2.status).toBe(403);
|
|
145
|
-
return [2 /*return*/];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}); });
|
|
149
|
-
(0, bun_test_1.it)("delete", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
150
|
-
var res, res2;
|
|
151
|
-
return __generator(this, function (_a) {
|
|
152
|
-
switch (_a.label) {
|
|
153
|
-
case 0: return [4 /*yield*/, server.get("/food")];
|
|
154
|
-
case 1:
|
|
155
|
-
res = _a.sent();
|
|
156
|
-
return [4 /*yield*/, server.delete("/food/".concat(res.body.data[0]._id))];
|
|
157
|
-
case 2:
|
|
158
|
-
res2 = _a.sent();
|
|
159
|
-
(0, bun_test_1.expect)(res2.status).toBe(405);
|
|
160
|
-
return [2 /*return*/];
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
}); });
|
|
164
|
-
});
|
|
165
|
-
(0, bun_test_1.describe)("non admin food", function () {
|
|
166
|
-
var agent;
|
|
167
|
-
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
168
|
-
return __generator(this, function (_a) {
|
|
169
|
-
switch (_a.label) {
|
|
170
|
-
case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "notAdmin")];
|
|
171
|
-
case 1:
|
|
172
|
-
agent = _a.sent();
|
|
173
|
-
return [2 /*return*/];
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}); });
|
|
177
|
-
(0, bun_test_1.it)("list", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
178
|
-
var res;
|
|
179
|
-
return __generator(this, function (_a) {
|
|
180
|
-
switch (_a.label) {
|
|
181
|
-
case 0: return [4 /*yield*/, agent.get("/food").expect(200)];
|
|
182
|
-
case 1:
|
|
183
|
-
res = _a.sent();
|
|
184
|
-
(0, bun_test_1.expect)(res.body.data).toHaveLength(4);
|
|
185
|
-
return [2 /*return*/];
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}); });
|
|
189
|
-
(0, bun_test_1.it)("get", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
190
|
-
var res, res2;
|
|
191
|
-
return __generator(this, function (_a) {
|
|
192
|
-
switch (_a.label) {
|
|
193
|
-
case 0: return [4 /*yield*/, agent.get("/food").expect(200)];
|
|
194
|
-
case 1:
|
|
195
|
-
res = _a.sent();
|
|
196
|
-
(0, bun_test_1.expect)(res.body.data).toHaveLength(4);
|
|
197
|
-
return [4 /*yield*/, server.get("/food/".concat(res.body.data[0]._id)).expect(200)];
|
|
198
|
-
case 2:
|
|
199
|
-
res2 = _a.sent();
|
|
200
|
-
(0, bun_test_1.expect)(res.body.data[0]._id).toBe(res2.body.data._id);
|
|
201
|
-
return [2 /*return*/];
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}); });
|
|
205
|
-
(0, bun_test_1.it)("post", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
206
|
-
return __generator(this, function (_a) {
|
|
207
|
-
switch (_a.label) {
|
|
208
|
-
case 0: return [4 /*yield*/, agent
|
|
209
|
-
.post("/food")
|
|
210
|
-
.send({
|
|
211
|
-
calories: 15,
|
|
212
|
-
name: "Broccoli",
|
|
213
|
-
})
|
|
214
|
-
.expect(201)];
|
|
215
|
-
case 1:
|
|
216
|
-
_a.sent();
|
|
217
|
-
return [2 /*return*/];
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}); });
|
|
221
|
-
(0, bun_test_1.it)("patch own item", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
222
|
-
var res, spinach, res2;
|
|
223
|
-
return __generator(this, function (_a) {
|
|
224
|
-
switch (_a.label) {
|
|
225
|
-
case 0: return [4 /*yield*/, agent.get("/food")];
|
|
226
|
-
case 1:
|
|
227
|
-
res = _a.sent();
|
|
228
|
-
spinach = res.body.data.find(function (food) { return food.name === "Spinach"; });
|
|
229
|
-
return [4 /*yield*/, agent
|
|
230
|
-
.patch("/food/".concat(spinach._id))
|
|
231
|
-
.send({
|
|
232
|
-
name: "Broccoli",
|
|
233
|
-
})
|
|
234
|
-
.expect(200)];
|
|
235
|
-
case 2:
|
|
236
|
-
res2 = _a.sent();
|
|
237
|
-
(0, bun_test_1.expect)(res2.body.data.name).toBe("Broccoli");
|
|
238
|
-
return [2 /*return*/];
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}); });
|
|
242
|
-
(0, bun_test_1.it)("patch other item", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
243
|
-
var res, spinach;
|
|
244
|
-
return __generator(this, function (_a) {
|
|
245
|
-
switch (_a.label) {
|
|
246
|
-
case 0: return [4 /*yield*/, agent.get("/food")];
|
|
247
|
-
case 1:
|
|
248
|
-
res = _a.sent();
|
|
249
|
-
spinach = res.body.data.find(function (food) { return food.name === "Apple"; });
|
|
250
|
-
return [4 /*yield*/, agent
|
|
251
|
-
.patch("/food/".concat(spinach._id))
|
|
252
|
-
.send({
|
|
253
|
-
name: "Broccoli",
|
|
254
|
-
})
|
|
255
|
-
.expect(403)];
|
|
256
|
-
case 2:
|
|
257
|
-
_a.sent();
|
|
258
|
-
return [2 /*return*/];
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
}); });
|
|
262
|
-
(0, bun_test_1.it)("delete", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
263
|
-
var res, res2;
|
|
264
|
-
return __generator(this, function (_a) {
|
|
265
|
-
switch (_a.label) {
|
|
266
|
-
case 0: return [4 /*yield*/, agent.get("/food")];
|
|
267
|
-
case 1:
|
|
268
|
-
res = _a.sent();
|
|
269
|
-
return [4 /*yield*/, agent.delete("/food/".concat(res.body.data[0]._id))];
|
|
270
|
-
case 2:
|
|
271
|
-
res2 = _a.sent();
|
|
272
|
-
(0, bun_test_1.expect)(res2.status).toBe(405);
|
|
273
|
-
return [2 /*return*/];
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
}); });
|
|
277
|
-
});
|
|
278
|
-
(0, bun_test_1.describe)("admin food", function () {
|
|
279
|
-
var agent;
|
|
280
|
-
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
281
|
-
return __generator(this, function (_a) {
|
|
282
|
-
switch (_a.label) {
|
|
283
|
-
case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "admin")];
|
|
284
|
-
case 1:
|
|
285
|
-
agent = _a.sent();
|
|
286
|
-
return [2 /*return*/];
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}); });
|
|
290
|
-
(0, bun_test_1.it)("list", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
291
|
-
var res;
|
|
292
|
-
return __generator(this, function (_a) {
|
|
293
|
-
switch (_a.label) {
|
|
294
|
-
case 0: return [4 /*yield*/, agent.get("/food")];
|
|
295
|
-
case 1:
|
|
296
|
-
res = _a.sent();
|
|
297
|
-
(0, bun_test_1.expect)(res.body.data).toHaveLength(4);
|
|
298
|
-
return [2 /*return*/];
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
}); });
|
|
302
|
-
(0, bun_test_1.it)("get", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
303
|
-
var res, res2;
|
|
304
|
-
return __generator(this, function (_a) {
|
|
305
|
-
switch (_a.label) {
|
|
306
|
-
case 0: return [4 /*yield*/, agent.get("/food")];
|
|
307
|
-
case 1:
|
|
308
|
-
res = _a.sent();
|
|
309
|
-
(0, bun_test_1.expect)(res.body.data).toHaveLength(4);
|
|
310
|
-
return [4 /*yield*/, agent.get("/food/".concat(res.body.data[0]._id))];
|
|
311
|
-
case 2:
|
|
312
|
-
res2 = _a.sent();
|
|
313
|
-
(0, bun_test_1.expect)(res.body.data[0]._id).toBe(res2.body.data._id);
|
|
314
|
-
return [2 /*return*/];
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
}); });
|
|
318
|
-
(0, bun_test_1.it)("post", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
319
|
-
var res;
|
|
320
|
-
return __generator(this, function (_a) {
|
|
321
|
-
switch (_a.label) {
|
|
322
|
-
case 0: return [4 /*yield*/, agent.post("/food").send({
|
|
323
|
-
calories: 15,
|
|
324
|
-
name: "Broccoli",
|
|
325
|
-
})];
|
|
326
|
-
case 1:
|
|
327
|
-
res = _a.sent();
|
|
328
|
-
(0, bun_test_1.expect)(res.status).toBe(201);
|
|
329
|
-
return [2 /*return*/];
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}); });
|
|
333
|
-
(0, bun_test_1.it)("patch", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
334
|
-
var res;
|
|
335
|
-
return __generator(this, function (_a) {
|
|
336
|
-
switch (_a.label) {
|
|
337
|
-
case 0: return [4 /*yield*/, agent.get("/food")];
|
|
338
|
-
case 1:
|
|
339
|
-
res = _a.sent();
|
|
340
|
-
return [4 /*yield*/, agent
|
|
341
|
-
.patch("/food/".concat(res.body.data[0]._id))
|
|
342
|
-
.send({
|
|
343
|
-
name: "Broccoli",
|
|
344
|
-
})
|
|
345
|
-
.expect(200)];
|
|
346
|
-
case 2:
|
|
347
|
-
_a.sent();
|
|
348
|
-
return [2 /*return*/];
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
}); });
|
|
352
|
-
(0, bun_test_1.it)("delete", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
353
|
-
var res;
|
|
354
|
-
return __generator(this, function (_a) {
|
|
355
|
-
switch (_a.label) {
|
|
356
|
-
case 0: return [4 /*yield*/, agent.get("/food")];
|
|
357
|
-
case 1:
|
|
358
|
-
res = _a.sent();
|
|
359
|
-
return [4 /*yield*/, agent.delete("/food/".concat(res.body.data[0]._id)).expect(204)];
|
|
360
|
-
case 2:
|
|
361
|
-
_a.sent();
|
|
362
|
-
return [2 /*return*/];
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
}); });
|
|
366
|
-
(0, bun_test_1.it)("handles validation errors", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
367
|
-
return __generator(this, function (_a) {
|
|
368
|
-
switch (_a.label) {
|
|
369
|
-
case 0: return [4 /*yield*/, agent
|
|
370
|
-
.post("/required")
|
|
371
|
-
.send({
|
|
372
|
-
about: "Whoops forgot required",
|
|
373
|
-
})
|
|
374
|
-
.expect(400)];
|
|
375
|
-
case 1:
|
|
376
|
-
_a.sent();
|
|
377
|
-
return [2 /*return*/];
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
}); });
|
|
381
|
-
});
|
|
382
|
-
});
|
|
383
|
-
(0, bun_test_1.describe)("permissions module", function () {
|
|
384
|
-
(0, bun_test_1.describe)("OwnerQueryFilter", function () {
|
|
385
|
-
(0, bun_test_1.it)("returns ownerId filter when user is provided", function () {
|
|
386
|
-
var user = { id: "user-123" };
|
|
387
|
-
var filter = (0, permissions_1.OwnerQueryFilter)(user);
|
|
388
|
-
(0, bun_test_1.expect)(filter).toEqual({ ownerId: "user-123" });
|
|
389
|
-
});
|
|
390
|
-
(0, bun_test_1.it)("returns null when user is undefined", function () {
|
|
391
|
-
var filter = (0, permissions_1.OwnerQueryFilter)(undefined);
|
|
392
|
-
(0, bun_test_1.expect)(filter).toBeNull();
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
(0, bun_test_1.describe)("Permissions.IsAuthenticatedOrReadOnly", function () {
|
|
396
|
-
(0, bun_test_1.it)("returns true for authenticated non-anonymous users", function () {
|
|
397
|
-
var user = { id: "user-123", isAnonymous: false };
|
|
398
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsAuthenticatedOrReadOnly("create", user)).toBe(true);
|
|
399
|
-
});
|
|
400
|
-
(0, bun_test_1.it)("returns true for read methods when user is anonymous", function () {
|
|
401
|
-
var user = { id: "user-123", isAnonymous: true };
|
|
402
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsAuthenticatedOrReadOnly("list", user)).toBe(true);
|
|
403
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsAuthenticatedOrReadOnly("read", user)).toBe(true);
|
|
404
|
-
});
|
|
405
|
-
(0, bun_test_1.it)("returns false for write methods when user is anonymous", function () {
|
|
406
|
-
var user = { id: "user-123", isAnonymous: true };
|
|
407
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsAuthenticatedOrReadOnly("create", user)).toBe(false);
|
|
408
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsAuthenticatedOrReadOnly("update", user)).toBe(false);
|
|
409
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsAuthenticatedOrReadOnly("delete", user)).toBe(false);
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
(0, bun_test_1.describe)("Permissions.IsOwnerOrReadOnly", function () {
|
|
413
|
-
(0, bun_test_1.it)("returns true when no object is provided", function () {
|
|
414
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsOwnerOrReadOnly("update", { id: "user-123" }, undefined)).toBe(true);
|
|
415
|
-
});
|
|
416
|
-
(0, bun_test_1.it)("returns true for admin users", function () {
|
|
417
|
-
var user = { admin: true, id: "admin-123" };
|
|
418
|
-
var obj = { ownerId: "other-user" };
|
|
419
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsOwnerOrReadOnly("update", user, obj)).toBe(true);
|
|
420
|
-
});
|
|
421
|
-
(0, bun_test_1.it)("returns true when user is owner", function () {
|
|
422
|
-
var user = { id: "user-123" };
|
|
423
|
-
var obj = { ownerId: "user-123" };
|
|
424
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsOwnerOrReadOnly("update", user, obj)).toBe(true);
|
|
425
|
-
});
|
|
426
|
-
(0, bun_test_1.it)("returns true for read methods when not owner", function () {
|
|
427
|
-
var user = { id: "user-123" };
|
|
428
|
-
var obj = { ownerId: "other-user" };
|
|
429
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsOwnerOrReadOnly("list", user, obj)).toBe(true);
|
|
430
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsOwnerOrReadOnly("read", user, obj)).toBe(true);
|
|
431
|
-
});
|
|
432
|
-
(0, bun_test_1.it)("returns false for write methods when not owner", function () {
|
|
433
|
-
var user = { id: "user-123" };
|
|
434
|
-
var obj = { ownerId: "other-user" };
|
|
435
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsOwnerOrReadOnly("update", user, obj)).toBe(false);
|
|
436
|
-
(0, bun_test_1.expect)(permissions_1.Permissions.IsOwnerOrReadOnly("delete", user, obj)).toBe(false);
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
});
|
package/dist/plugins.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|