@terreno/api 0.21.0 → 0.22.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.
Files changed (51) hide show
  1. package/bunfig.toml +1 -1
  2. package/dist/auth.test.js +408 -33
  3. package/dist/models/consentForm.js +2 -1
  4. package/dist/models/consentResponse.js +2 -1
  5. package/dist/models/versionConfig.js +2 -1
  6. package/dist/openApiBuilder.d.ts +18 -0
  7. package/dist/openApiBuilder.js +21 -0
  8. package/dist/openApiBuilder.test.js +16 -0
  9. package/dist/permissions.test.js +10 -43
  10. package/dist/populate.test.js +10 -42
  11. package/dist/syncConsents.test.js +2 -2
  12. package/dist/tests/bunSetup.js +33 -283
  13. package/dist/tests/createTestData.d.ts +9 -0
  14. package/dist/tests/createTestData.js +272 -0
  15. package/dist/tests/models.d.ts +71 -0
  16. package/dist/tests/models.js +134 -0
  17. package/dist/tests/mongoTestSetup.d.ts +7 -0
  18. package/dist/tests/mongoTestSetup.js +150 -0
  19. package/dist/tests/testEnv.d.ts +0 -0
  20. package/dist/tests/testEnv.js +6 -0
  21. package/dist/tests/testHelper.d.ts +22 -0
  22. package/dist/tests/testHelper.js +115 -0
  23. package/dist/tests/types.d.ts +29 -0
  24. package/dist/tests/types.js +2 -0
  25. package/dist/tests.d.ts +10 -78
  26. package/dist/tests.js +24 -264
  27. package/dist/transformers.test.js +14 -50
  28. package/package.json +18 -4
  29. package/src/__snapshots__/openApiBuilder.test.ts.snap +1 -0
  30. package/src/auth.test.ts +277 -29
  31. package/src/models/consentForm.ts +3 -4
  32. package/src/models/consentResponse.ts +6 -4
  33. package/src/models/versionConfig.ts +3 -4
  34. package/src/openApiBuilder.test.ts +9 -0
  35. package/src/openApiBuilder.ts +24 -0
  36. package/src/permissions.test.ts +8 -23
  37. package/src/populate.test.ts +7 -22
  38. package/src/syncConsents.test.ts +1 -1
  39. package/src/tests/bunSetup.ts +22 -249
  40. package/src/tests/createTestData.ts +176 -0
  41. package/src/tests/models.ts +164 -0
  42. package/src/tests/mongoTestSetup.ts +69 -0
  43. package/src/tests/testEnv.ts +4 -0
  44. package/src/tests/testHelper.ts +57 -0
  45. package/src/tests/types.ts +35 -0
  46. package/src/tests.ts +40 -244
  47. package/src/transformers.test.ts +11 -30
  48. package/tsconfig.typedoc.json +4 -0
  49. package/dist/tests/index.d.ts +0 -1
  50. package/dist/tests/index.js +0 -17
  51. package/src/tests/index.ts +0 -1
@@ -10,7 +10,7 @@ import {modelRouter} from "./api";
10
10
  import {addAuthRoutes, setupAuth} from "./auth";
11
11
  import {APIError} from "./errors";
12
12
  import {Permissions} from "./permissions";
13
- import {authAsUser, type Food, FoodModel, getBaseServer, setupDb, UserModel} from "./tests";
13
+ import {authAsUser, type Food, FoodModel, getBaseServer, setupTestData, UserModel} from "./tests";
14
14
  import {AdminOwnerTransformer, defaultResponseHandler, transform} from "./transformers";
15
15
 
16
16
  describe("query and transform", () => {
@@ -22,29 +22,9 @@ describe("query and transform", () => {
22
22
  beforeEach(async () => {
23
23
  process.env.REFRESH_TOKEN_SECRET = "testsecret1234";
24
24
 
25
- [admin, notAdmin] = await setupDb();
26
-
27
- await Promise.all([
28
- FoodModel.create({
29
- calories: 1,
30
- created: new Date(),
31
- name: "Spinach",
32
- ownerId: notAdmin._id,
33
- }),
34
- FoodModel.create({
35
- calories: 100,
36
- created: Date.now() - 10,
37
- hidden: true,
38
- name: "Apple",
39
- ownerId: admin._id,
40
- }),
41
- FoodModel.create({
42
- calories: 100,
43
- created: Date.now() - 10,
44
- name: "Carrots",
45
- ownerId: admin._id,
46
- }),
47
- ]);
25
+ const testData = await setupTestData();
26
+ admin = testData.users.admin;
27
+ notAdmin = testData.users.notAdmin;
48
28
  app = getBaseServer();
49
29
  setupAuth(app, UserModel as any);
50
30
  addAuthRoutes(app, UserModel as any);
@@ -83,19 +63,19 @@ describe("query and transform", () => {
83
63
  it("filters list for non-admin", async () => {
84
64
  const agent = await authAsUser(app, "notAdmin");
85
65
  const foodRes = await agent.get("/food").expect(200);
86
- expect(foodRes.body.data).toHaveLength(2);
66
+ expect(foodRes.body.data).toHaveLength(3);
87
67
  });
88
68
 
89
69
  it("does not filter list for admin", async () => {
90
70
  const agent = await authAsUser(app, "admin");
91
71
  const foodRes = await agent.get("/food").expect(200);
92
- expect(foodRes.body.data).toHaveLength(3);
72
+ expect(foodRes.body.data).toHaveLength(4);
93
73
  });
94
74
 
95
75
  it("admin read transform", async () => {
96
76
  const agent = await authAsUser(app, "admin");
97
77
  const foodRes = await agent.get("/food").expect(200);
98
- expect(foodRes.body.data).toHaveLength(3);
78
+ expect(foodRes.body.data).toHaveLength(4);
99
79
  const spinach = foodRes.body.data.find((food: Food) => food.name === "Spinach");
100
80
  expect(spinach.created).toBeDefined();
101
81
  expect(spinach.id).toBeDefined();
@@ -116,7 +96,7 @@ describe("query and transform", () => {
116
96
  it("owner read transform", async () => {
117
97
  const agent = await authAsUser(app, "notAdmin");
118
98
  const foodRes = await agent.get("/food").expect(200);
119
- expect(foodRes.body.data).toHaveLength(2);
99
+ expect(foodRes.body.data).toHaveLength(3);
120
100
  const spinach = foodRes.body.data.find((food: Food) => food.name === "Spinach");
121
101
  expect(spinach.id).toBeDefined();
122
102
  expect(spinach.name).toBe("Spinach");
@@ -149,7 +129,7 @@ describe("query and transform", () => {
149
129
  it("auth read transform", async () => {
150
130
  const agent = await authAsUser(app, "notAdmin");
151
131
  const foodRes = await agent.get("/food").expect(200);
152
- expect(foodRes.body.data).toHaveLength(2);
132
+ expect(foodRes.body.data).toHaveLength(3);
153
133
  const spinach = foodRes.body.data.find((food: Food) => food.name === "Spinach");
154
134
  expect(spinach.id).toBeDefined();
155
135
  expect(spinach.name).toBe("Spinach");
@@ -192,9 +172,10 @@ describe("query and transform", () => {
192
172
 
193
173
  it("anon read transform", async () => {
194
174
  const res = await server.get("/food");
195
- expect(res.body.data).toHaveLength(2);
175
+ expect(res.body.data).toHaveLength(3);
196
176
  expect(res.body.data.find((f: Food) => f.name === "Spinach")).toBeDefined();
197
177
  expect(res.body.data.find((f: Food) => f.name === "Carrots")).toBeDefined();
178
+ expect(res.body.data.find((f: Food) => f.name === "Pizza")).toBeDefined();
198
179
  });
199
180
 
200
181
  it("anon write transform fails", async () => {
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["node_modules", "src/tests.ts", "src/tests/**", "**/*.test.ts"]
4
+ }
@@ -1 +0,0 @@
1
- export * from "./bunSetup";
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./bunSetup"), exports);
@@ -1 +0,0 @@
1
- export * from "./bunSetup";