@liminalfunctions/framework 1.0.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 (181) hide show
  1. package/.mocharc.json +5 -0
  2. package/dist/F_Client_Collection_Registry.d.ts +18 -0
  3. package/dist/F_Client_Collection_Registry.js +36 -0
  4. package/dist/F_Client_Collection_Registry.js.map +1 -0
  5. package/dist/F_Collection.d.ts +21 -0
  6. package/dist/F_Collection.js +36 -0
  7. package/dist/F_Collection.js.map +1 -0
  8. package/dist/F_Collection_Registry.d.ts +11 -0
  9. package/dist/F_Collection_Registry.js +18 -0
  10. package/dist/F_Collection_Registry.js.map +1 -0
  11. package/dist/F_Compile.d.ts +4 -0
  12. package/dist/F_Compile.js +298 -0
  13. package/dist/F_Compile.js.map +1 -0
  14. package/dist/F_Security_Models/F_SM_Open_Access.d.ts +11 -0
  15. package/dist/F_Security_Models/F_SM_Open_Access.js +14 -0
  16. package/dist/F_Security_Models/F_SM_Open_Access.js.map +1 -0
  17. package/dist/F_Security_Models/F_SM_Ownership.d.ts +12 -0
  18. package/dist/F_Security_Models/F_SM_Ownership.js +46 -0
  19. package/dist/F_Security_Models/F_SM_Ownership.js.map +1 -0
  20. package/dist/F_Security_Models/F_SM_Role_Membership.d.ts +19 -0
  21. package/dist/F_Security_Models/F_SM_Role_Membership.js +73 -0
  22. package/dist/F_Security_Models/F_SM_Role_Membership.js.map +1 -0
  23. package/dist/F_Security_Models/F_Security_Model.d.ts +41 -0
  24. package/dist/F_Security_Models/F_Security_Model.js +29 -0
  25. package/dist/F_Security_Models/F_Security_Model.js.map +1 -0
  26. package/dist/code_generation/generate_client_library.d.ts +4 -0
  27. package/dist/code_generation/generate_client_library.js +158 -0
  28. package/dist/code_generation/generate_client_library.js.map +1 -0
  29. package/dist/code_generation/templates/.gitignore.mustache +383 -0
  30. package/dist/code_generation/templates/collection.mustache +106 -0
  31. package/dist/code_generation/templates/main.mustache +24 -0
  32. package/dist/code_generation/templates/package.json.mustache +18 -0
  33. package/dist/code_generation/templates/tsconfig.json.mustache +14 -0
  34. package/dist/code_generation/templates/types.mustache +4 -0
  35. package/dist/code_generation/templates/utils.ts.mustache +17 -0
  36. package/dist/code_generation/utils/tab_indent.d.ts +1 -0
  37. package/dist/code_generation/utils/tab_indent.js +4 -0
  38. package/dist/code_generation/utils/tab_indent.js.map +1 -0
  39. package/dist/code_generation/utils/type_from_zod.d.ts +2 -0
  40. package/dist/code_generation/utils/type_from_zod.js +102 -0
  41. package/dist/code_generation/utils/type_from_zod.js.map +1 -0
  42. package/dist/utils/cache.d.ts +13 -0
  43. package/dist/utils/cache.js +101 -0
  44. package/dist/utils/cache.js.map +1 -0
  45. package/dist/utils/mongoose_from_zod.d.ts +13 -0
  46. package/dist/utils/mongoose_from_zod.js +164 -0
  47. package/dist/utils/mongoose_from_zod.js.map +1 -0
  48. package/dist/utils/pretty_print_zod.d.ts +2 -0
  49. package/dist/utils/pretty_print_zod.js +63 -0
  50. package/dist/utils/pretty_print_zod.js.map +1 -0
  51. package/dist/utils/query_object_to_mongodb_query.d.ts +3 -0
  52. package/dist/utils/query_object_to_mongodb_query.js +61 -0
  53. package/dist/utils/query_object_to_mongodb_query.js.map +1 -0
  54. package/dist/utils/query_validator_from_zod.d.ts +6 -0
  55. package/dist/utils/query_validator_from_zod.js +216 -0
  56. package/dist/utils/query_validator_from_zod.js.map +1 -0
  57. package/package.json +36 -0
  58. package/src/F_Collection.ts +50 -0
  59. package/src/F_Collection_Registry.ts +29 -0
  60. package/src/F_Compile.ts +368 -0
  61. package/src/F_Security_Models/F_SM_Open_Access.ts +21 -0
  62. package/src/F_Security_Models/F_SM_Ownership.ts +72 -0
  63. package/src/F_Security_Models/F_SM_Role_Membership.ts +87 -0
  64. package/src/F_Security_Models/F_Security_Model.ts +85 -0
  65. package/src/code_generation/generate_client_library.ts +197 -0
  66. package/src/code_generation/templates/.gitignore.mustache +383 -0
  67. package/src/code_generation/templates/collection.mustache +106 -0
  68. package/src/code_generation/templates/main.mustache +24 -0
  69. package/src/code_generation/templates/package.json.mustache +18 -0
  70. package/src/code_generation/templates/tsconfig.json.mustache +14 -0
  71. package/src/code_generation/templates/types.mustache +4 -0
  72. package/src/code_generation/templates/utils.ts.mustache +17 -0
  73. package/src/code_generation/utils/tab_indent.ts +3 -0
  74. package/src/code_generation/utils/type_from_zod.ts +140 -0
  75. package/src/utils/cache.ts +149 -0
  76. package/src/utils/mongoose_from_zod.ts +191 -0
  77. package/src/utils/pretty_print_zod.ts +75 -0
  78. package/src/utils/query_object_to_mongodb_query.ts +73 -0
  79. package/src/utils/query_validator_from_zod.ts +246 -0
  80. package/test/0_0_mongoose_from_zod.test.ts +260 -0
  81. package/test/0_1_query_validator_from_zod.test.ts +518 -0
  82. package/test/0_2_query_validator_to_mongodb_query.test.ts +365 -0
  83. package/test/0_3_cache.test.ts +204 -0
  84. package/test/1_0_basic_server.test.ts +530 -0
  85. package/test/1_1_security_ownership.test.ts +328 -0
  86. package/test/1_2_role_membership.test.ts +731 -0
  87. package/test/2_0_client_library_basic_type_generation.test.ts +444 -0
  88. package/test/2_0_client_library_query_type_generation.test.ts +352 -0
  89. package/test/2_1_client_library_generation.test.ts +255 -0
  90. package/test/tmp/dist/Brief_News_Category.d.ts +16 -0
  91. package/test/tmp/dist/Brief_News_Category.js +85 -0
  92. package/test/tmp/dist/Brief_News_Category.js.map +1 -0
  93. package/test/tmp/dist/Client.d.ts +19 -0
  94. package/test/tmp/dist/Client.js +97 -0
  95. package/test/tmp/dist/Client.js.map +1 -0
  96. package/test/tmp/dist/Institution.d.ts +18 -0
  97. package/test/tmp/dist/Institution.js +94 -0
  98. package/test/tmp/dist/Institution.js.map +1 -0
  99. package/test/tmp/dist/Project.d.ts +16 -0
  100. package/test/tmp/dist/Project.js +85 -0
  101. package/test/tmp/dist/Project.js.map +1 -0
  102. package/test/tmp/dist/index.d.ts +4 -0
  103. package/test/tmp/dist/index.js +14 -0
  104. package/test/tmp/dist/index.js.map +1 -0
  105. package/test/tmp/dist/types/brief_news_category.d.ts +7 -0
  106. package/test/tmp/dist/types/brief_news_category.js +2 -0
  107. package/test/tmp/dist/types/brief_news_category.js.map +1 -0
  108. package/test/tmp/dist/types/brief_news_category_post.d.ts +7 -0
  109. package/test/tmp/dist/types/brief_news_category_post.js +2 -0
  110. package/test/tmp/dist/types/brief_news_category_post.js.map +1 -0
  111. package/test/tmp/dist/types/brief_news_category_put.d.ts +7 -0
  112. package/test/tmp/dist/types/brief_news_category_put.js +2 -0
  113. package/test/tmp/dist/types/brief_news_category_put.js.map +1 -0
  114. package/test/tmp/dist/types/brief_news_category_query.d.ts +26 -0
  115. package/test/tmp/dist/types/brief_news_category_query.js +2 -0
  116. package/test/tmp/dist/types/brief_news_category_query.js.map +1 -0
  117. package/test/tmp/dist/types/client.d.ts +5 -0
  118. package/test/tmp/dist/types/client.js +2 -0
  119. package/test/tmp/dist/types/client.js.map +1 -0
  120. package/test/tmp/dist/types/client_post.d.ts +5 -0
  121. package/test/tmp/dist/types/client_post.js +2 -0
  122. package/test/tmp/dist/types/client_post.js.map +1 -0
  123. package/test/tmp/dist/types/client_put.d.ts +5 -0
  124. package/test/tmp/dist/types/client_put.js +2 -0
  125. package/test/tmp/dist/types/client_put.js.map +1 -0
  126. package/test/tmp/dist/types/client_query.d.ts +18 -0
  127. package/test/tmp/dist/types/client_query.js +2 -0
  128. package/test/tmp/dist/types/client_query.js.map +1 -0
  129. package/test/tmp/dist/types/institution.d.ts +4 -0
  130. package/test/tmp/dist/types/institution.js +2 -0
  131. package/test/tmp/dist/types/institution.js.map +1 -0
  132. package/test/tmp/dist/types/institution_post.d.ts +4 -0
  133. package/test/tmp/dist/types/institution_post.js +2 -0
  134. package/test/tmp/dist/types/institution_post.js.map +1 -0
  135. package/test/tmp/dist/types/institution_put.d.ts +4 -0
  136. package/test/tmp/dist/types/institution_put.js +2 -0
  137. package/test/tmp/dist/types/institution_put.js.map +1 -0
  138. package/test/tmp/dist/types/institution_query.d.ts +14 -0
  139. package/test/tmp/dist/types/institution_query.js +2 -0
  140. package/test/tmp/dist/types/institution_query.js.map +1 -0
  141. package/test/tmp/dist/types/project.d.ts +7 -0
  142. package/test/tmp/dist/types/project.js +2 -0
  143. package/test/tmp/dist/types/project.js.map +1 -0
  144. package/test/tmp/dist/types/project_post.d.ts +7 -0
  145. package/test/tmp/dist/types/project_post.js +2 -0
  146. package/test/tmp/dist/types/project_post.js.map +1 -0
  147. package/test/tmp/dist/types/project_put.d.ts +7 -0
  148. package/test/tmp/dist/types/project_put.js +2 -0
  149. package/test/tmp/dist/types/project_put.js.map +1 -0
  150. package/test/tmp/dist/types/project_query.d.ts +27 -0
  151. package/test/tmp/dist/types/project_query.js +2 -0
  152. package/test/tmp/dist/types/project_query.js.map +1 -0
  153. package/test/tmp/dist/utils/utils.d.ts +11 -0
  154. package/test/tmp/dist/utils/utils.js +13 -0
  155. package/test/tmp/dist/utils/utils.js.map +1 -0
  156. package/test/tmp/package-lock.json +573 -0
  157. package/test/tmp/package.json +18 -0
  158. package/test/tmp/src/Brief_News_Category.ts +94 -0
  159. package/test/tmp/src/Client.ts +106 -0
  160. package/test/tmp/src/Institution.ts +103 -0
  161. package/test/tmp/src/Project.ts +94 -0
  162. package/test/tmp/src/index.ts +20 -0
  163. package/test/tmp/src/types/brief_news_category.ts +7 -0
  164. package/test/tmp/src/types/brief_news_category_post.ts +7 -0
  165. package/test/tmp/src/types/brief_news_category_put.ts +7 -0
  166. package/test/tmp/src/types/brief_news_category_query.ts +26 -0
  167. package/test/tmp/src/types/client.ts +5 -0
  168. package/test/tmp/src/types/client_post.ts +5 -0
  169. package/test/tmp/src/types/client_put.ts +5 -0
  170. package/test/tmp/src/types/client_query.ts +18 -0
  171. package/test/tmp/src/types/institution.ts +4 -0
  172. package/test/tmp/src/types/institution_post.ts +4 -0
  173. package/test/tmp/src/types/institution_put.ts +4 -0
  174. package/test/tmp/src/types/institution_query.ts +14 -0
  175. package/test/tmp/src/types/project.ts +7 -0
  176. package/test/tmp/src/types/project_post.ts +7 -0
  177. package/test/tmp/src/types/project_put.ts +7 -0
  178. package/test/tmp/src/types/project_query.ts +27 -0
  179. package/test/tmp/src/utils/utils.ts +17 -0
  180. package/test/tmp/tsconfig.json +14 -0
  181. package/tsconfig.json +14 -0
@@ -0,0 +1,328 @@
1
+
2
+ import assert from "assert";
3
+
4
+ import { z_mongodb_id } from '../dist/utils/mongoose_from_zod.js';
5
+ import { F_Collection } from '../dist/f_collection.js';
6
+ import { F_Collection_Registry } from '../dist/F_Collection_Registry.js'
7
+ import { F_SM_Open_Access } from '../dist/F_Security_Models/F_SM_Open_Access.js'
8
+ import { F_SM_Ownership } from '../dist/F_Security_Models/F_SM_Ownership.js'
9
+ import { F_Security_Model } from '../dist/F_Security_Models/F_Security_Model.js'
10
+ import { z, ZodBoolean, ZodDate, ZodNumber, ZodString } from 'zod'
11
+
12
+ import got from 'got'
13
+ import express, { Express, Request, Response, NextFunction } from 'express'
14
+ import mongoose, { Mongoose } from "mongoose";
15
+ import { Server } from "http";
16
+
17
+
18
+
19
+ describe('Security Model Ownership', function () {
20
+ const port = 4601;
21
+ let express_app: Express;
22
+ let server: Server;
23
+ let db_connection: Mongoose;
24
+
25
+ let validate_user = z.object({
26
+ _id: z_mongodb_id,
27
+ auth_id: z.string(),
28
+ });
29
+ let validate_user_display = z.object({
30
+ _id: z_mongodb_id,
31
+ user_id: z_mongodb_id,
32
+ name: z.string(),
33
+ email: z.string()
34
+ })
35
+
36
+ // set up schema: user
37
+ let collection_user: F_Collection<'user', typeof validate_user>;
38
+
39
+ // set up schema: user_display
40
+ let collection_user_display: F_Collection<'user_display', typeof validate_user_display>;
41
+
42
+ // build registry
43
+ let registry: F_Collection_Registry;
44
+
45
+ // before any tests run, set up the server and the db connection
46
+ before(async function() {
47
+ express_app = express();
48
+ express_app.use(express.json());
49
+ db_connection = await mongoose.connect('mongodb://127.0.0.1:27017/');
50
+
51
+ collection_user = new F_Collection('user', validate_user);
52
+ collection_user.add_layers([], [new F_SM_Open_Access(collection_user)]);
53
+
54
+ collection_user_display = new F_Collection('user_display', validate_user_display);
55
+ collection_user_display.add_layers([], [new F_SM_Ownership(collection_user_display)]);
56
+
57
+ let proto_registry = new F_Collection_Registry();
58
+ registry = proto_registry.register(collection_user).register(collection_user_display);
59
+ F_Security_Model.set_auth_fetcher(async (req: Request) => {
60
+ if(!req.headers.authorization){ return undefined; }
61
+
62
+ let user_record = await collection_user.mongoose_model.findOne({auth_id: req.headers.authorization})
63
+ if(!user_record){ return undefined; }
64
+
65
+ return { user_id: user_record._id, layers: [] };
66
+ })
67
+ registry.compile(express_app, '/api');
68
+
69
+ server = express_app.listen(port);
70
+
71
+ // wait for a moment because otherwise stuff breaks for no reason
72
+ await new Promise(resolve => setTimeout(resolve, 200))
73
+ })
74
+
75
+ after(async function (){
76
+ await server.close();
77
+ mongoose.connection.modelNames().forEach(ele => mongoose.connection.deleteModel(ele));
78
+ db_connection.modelNames().forEach(ele => db_connection.deleteModel(ele));
79
+ await db_connection.disconnect()
80
+ });
81
+
82
+ beforeEach(async function(){
83
+ for(let collection of Object.values(registry.collections)){
84
+ //@ts-ignore
85
+ await collection.mongoose_model.collection.drop();
86
+ }
87
+ })
88
+
89
+ async function generate_user_and_display(){
90
+ let user = await collection_user.mongoose_model.create({
91
+ auth_id: 'steve'
92
+ });
93
+
94
+ let user_display = await collection_user_display.mongoose_model.create({
95
+ user_id: user._id,
96
+ name: 'steve',
97
+ email: 'steve@example.com'
98
+ })
99
+
100
+ return { user, user_display}
101
+ }
102
+
103
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
104
+ ///////////////////////////////////////////////////////////// GET one ////////////////////////////////////////////////////////////////////////////////
105
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106
+
107
+
108
+
109
+ it(`should authorize a basic GET operation authenticated properly`, async function () {
110
+ let { user, user_display } = await generate_user_and_display();
111
+
112
+ let results = await got.get(`http://localhost:${port}/api/user_display/${user_display.id}`, {
113
+ headers: {
114
+ authorization: 'steve'
115
+ }
116
+ }).json();
117
+
118
+ //@ts-ignore
119
+ assert.deepEqual(JSON.parse(JSON.stringify(user_display)), results.data);
120
+ });
121
+
122
+ it(`should reject a basic GET operation authenticated to the wrong user`, async function () {
123
+ let { user, user_display } = await generate_user_and_display();
124
+
125
+ let user_2 = await collection_user.mongoose_model.create({
126
+ auth_id: 'sharon'
127
+ });
128
+
129
+ assert.rejects(async () => {
130
+ let results = await got.get(`http://localhost:${port}/api/user_display/${user_display.id}`, {
131
+ headers: {
132
+ authorization: 'sharon'
133
+ }
134
+ }).json();
135
+ }, {
136
+ message: 'HTTPError: Response code 403 (Forbidden)'
137
+ })
138
+ });
139
+
140
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
141
+ ///////////////////////////////////////////////////////////// GET multiple ///////////////////////////////////////////////////////////////////////////
142
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
143
+
144
+
145
+ it(`should authorize a basic GET multiple operation authenticated properly`, async function () {
146
+ let user = await collection_user.mongoose_model.create({
147
+ auth_id: 'steve'
148
+ });
149
+
150
+ let user_displays = [] as any[];
151
+ for(let q = 0; q < 5; q++){
152
+ user_displays.push(await collection_user_display.mongoose_model.create({
153
+ user_id: user._id,
154
+ name: 'steve',
155
+ email: 'steve@example.com'
156
+ }))
157
+ }
158
+
159
+ let results = await got.get(`http://localhost:${port}/api/user_display?user_id=${user._id}`, {
160
+ headers: {
161
+ authorization: 'steve'
162
+ }
163
+ }).json();
164
+
165
+ //@ts-ignore
166
+ assert.deepEqual(JSON.parse(JSON.stringify(user_displays)), results.data);
167
+ });
168
+
169
+ it(`should reject a basic GET multiple operation when performed by the wrong user`, async function () {
170
+ let user = await collection_user.mongoose_model.create({
171
+ auth_id: 'steve'
172
+ });
173
+
174
+ let user_2 = await collection_user.mongoose_model.create({
175
+ auth_id: 'sharon'
176
+ });
177
+
178
+ let user_displays = [] as any[];
179
+ for(let q = 0; q < 5; q++){
180
+ user_displays.push(await collection_user_display.mongoose_model.create({
181
+ user_id: user._id,
182
+ name: 'steve',
183
+ email: 'steve@example.com'
184
+ }))
185
+ }
186
+
187
+ //@ts-ignore
188
+ assert.rejects(async () => {
189
+ let results = await got.get(`http://localhost:${port}/api/user_display?user_id=${user._id}`, {
190
+ headers: {
191
+ authorization: 'sharon'
192
+ }
193
+ }).json();
194
+ }, {
195
+ message: 'HTTPError: Response code 403 (Forbidden)'
196
+ })
197
+ });
198
+
199
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
200
+ ///////////////////////////////////////////////////////////// PUT ////////////////////////////////////////////////////////////////////////////////////
201
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
202
+
203
+
204
+
205
+ it(`should authorize a basic PUT operation authenticated properly`, async function () {
206
+ let { user, user_display } = await generate_user_and_display();
207
+
208
+ let results = await got.put(`http://localhost:${port}/api/user_display/${user_display.id}`, {
209
+ headers: {
210
+ authorization: 'steve'
211
+ },
212
+ json: {
213
+ email: 'steven@test.com'
214
+ }
215
+ }).json();
216
+
217
+ //@ts-ignore
218
+ assert.notDeepEqual(JSON.parse(JSON.stringify(user_display)), results.data);
219
+ //@ts-ignore
220
+ assert.deepEqual(JSON.parse(JSON.stringify(await collection_user_display.mongoose_model.findById(user_display._id))), results.data);
221
+ });
222
+
223
+ it(`should reject a basic PUT operation authenticated to the wrong user`, async function () {
224
+ let { user, user_display } = await generate_user_and_display();
225
+
226
+ let user_2 = await collection_user.mongoose_model.create({
227
+ auth_id: 'sharon'
228
+ });
229
+
230
+ assert.rejects(async () => {
231
+ let results = await got.put(`http://localhost:${port}/api/user_display/${user_display.id}`, {
232
+ headers: {
233
+ authorization: 'sharon'
234
+ },
235
+ json: {
236
+ email: 'steven@test.com'
237
+ }
238
+ }).json();
239
+ }, {
240
+ message: 'HTTPError: Response code 403 (Forbidden)'
241
+ })
242
+ });
243
+
244
+
245
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
246
+ ///////////////////////////////////////////////////////////// POST ///////////////////////////////////////////////////////////////////////////////////
247
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
248
+
249
+ it(`should authorize a basic POST operation authenticated properly`, async function () {
250
+ let { user, user_display } = await generate_user_and_display();
251
+
252
+ let results = await got.post(`http://localhost:${port}/api/user_display`, {
253
+ headers: {
254
+ authorization: 'steve'
255
+ },
256
+ json: {
257
+ user_id: user._id,
258
+ name: 'grogfurd',
259
+ email: 'grogfurd@example.com'
260
+ }
261
+ }).json();
262
+
263
+ //@ts-ignore
264
+ assert.deepEqual(JSON.parse(JSON.stringify(await collection_user_display.mongoose_model.findById(results.data._id))), results.data);
265
+ });
266
+
267
+ it(`should reject a basic POST operation authenticated to the wrong user`, async function () {
268
+ let { user, user_display } = await generate_user_and_display();
269
+
270
+ let user_2 = await collection_user.mongoose_model.create({
271
+ auth_id: 'sharon'
272
+ });
273
+
274
+ assert.rejects(async () => {
275
+ let results = await got.post(`http://localhost:${port}/api/user_display`, {
276
+ headers: {
277
+ authorization: 'sharon'
278
+ },
279
+ json: {
280
+ user_id: user._id,
281
+ name: 'grogfurd',
282
+ email: 'grogfurd@example.com'
283
+ }
284
+ }).json();
285
+ }, {
286
+ message: 'HTTPError: Response code 403 (Forbidden)'
287
+ })
288
+ });
289
+
290
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
291
+ ///////////////////////////////////////////////////////////// DELETE /////////////////////////////////////////////////////////////////////////////////
292
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
293
+
294
+
295
+
296
+ it(`should authorize a basic DELETE operation authenticated properly`, async function () {
297
+ let { user, user_display } = await generate_user_and_display();
298
+
299
+ let results = await got.delete(`http://localhost:${port}/api/user_display/${user_display.id}`, {
300
+ headers: {
301
+ authorization: 'steve'
302
+ }
303
+ }).json();
304
+
305
+ //@ts-ignore
306
+ assert.deepEqual(JSON.parse(JSON.stringify(user_display)), results.data);
307
+ //@ts-ignore
308
+ assert.deepEqual(JSON.parse(JSON.stringify(await collection_user_display.mongoose_model.findById(user_display._id))), undefined);
309
+ });
310
+
311
+ it(`should reject a basic DELETE operation authenticated to the wrong user`, async function () {
312
+ let { user, user_display } = await generate_user_and_display();
313
+
314
+ let user_2 = await collection_user.mongoose_model.create({
315
+ auth_id: 'sharon'
316
+ });
317
+
318
+ assert.rejects(async () => {
319
+ let results = await got.delete(`http://localhost:${port}/api/user_display/${user_display.id}`, {
320
+ headers: {
321
+ authorization: 'sharon'
322
+ }
323
+ }).json();
324
+ }, {
325
+ message: 'HTTPError: Response code 403 (Forbidden)'
326
+ })
327
+ });
328
+ });