@sera4/essentia 1.1.66-rc.1 → 1.1.66

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 (242) hide show
  1. package/package.json +1 -1
  2. package/package.tar.gz +0 -0
  3. package/coverage/base.css +0 -224
  4. package/coverage/block-navigation.js +0 -87
  5. package/coverage/configurations/index.html +0 -116
  6. package/coverage/configurations/server-config.ts.html +0 -94
  7. package/coverage/dns/DnsCache.ts.html +0 -598
  8. package/coverage/dns/index.html +0 -131
  9. package/coverage/dns/index.ts.html +0 -94
  10. package/coverage/favicon.png +0 -0
  11. package/coverage/health/index.html +0 -116
  12. package/coverage/health/index.ts.html +0 -778
  13. package/coverage/index.html +0 -161
  14. package/coverage/lcov-report/base.css +0 -224
  15. package/coverage/lcov-report/block-navigation.js +0 -87
  16. package/coverage/lcov-report/configurations/index.html +0 -116
  17. package/coverage/lcov-report/configurations/server-config.ts.html +0 -94
  18. package/coverage/lcov-report/dns/DnsCache.ts.html +0 -598
  19. package/coverage/lcov-report/dns/index.html +0 -131
  20. package/coverage/lcov-report/dns/index.ts.html +0 -94
  21. package/coverage/lcov-report/favicon.png +0 -0
  22. package/coverage/lcov-report/health/index.html +0 -116
  23. package/coverage/lcov-report/health/index.ts.html +0 -778
  24. package/coverage/lcov-report/index.html +0 -161
  25. package/coverage/lcov-report/logger/index.html +0 -131
  26. package/coverage/lcov-report/logger/index.ts.html +0 -94
  27. package/coverage/lcov-report/logger/s4-logger.ts.html +0 -514
  28. package/coverage/lcov-report/prettify.css +0 -1
  29. package/coverage/lcov-report/prettify.js +0 -2
  30. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  31. package/coverage/lcov-report/sorter.js +0 -196
  32. package/coverage/lcov.info +0 -747
  33. package/coverage/logger/index.html +0 -131
  34. package/coverage/logger/index.ts.html +0 -94
  35. package/coverage/logger/s4-logger.ts.html +0 -514
  36. package/coverage/prettify.css +0 -1
  37. package/coverage/prettify.js +0 -2
  38. package/coverage/sort-arrow-sprite.png +0 -0
  39. package/coverage/sorter.js +0 -196
  40. package/coverage/tmp/coverage-24302-1746472691313-0.json +0 -1
  41. package/coverage/tmp/coverage-24302-1746472691366-1.json +0 -1
  42. package/dist/cache/index.d.ts +0 -22
  43. package/dist/cache/index.js +0 -166
  44. package/dist/cache/index.js.map +0 -1
  45. package/dist/constants/index.d.ts +0 -6
  46. package/dist/constants/index.js +0 -9
  47. package/dist/constants/index.js.map +0 -1
  48. package/dist/coverage/block-navigation.d.ts +0 -1
  49. package/dist/coverage/block-navigation.js +0 -70
  50. package/dist/coverage/block-navigation.js.map +0 -1
  51. package/dist/coverage/lcov-report/block-navigation.d.ts +0 -1
  52. package/dist/coverage/lcov-report/block-navigation.js +0 -70
  53. package/dist/coverage/lcov-report/block-navigation.js.map +0 -1
  54. package/dist/coverage/lcov-report/prettify.d.ts +0 -0
  55. package/dist/coverage/lcov-report/prettify.js +0 -477
  56. package/dist/coverage/lcov-report/prettify.js.map +0 -1
  57. package/dist/coverage/lcov-report/sorter.d.ts +0 -1
  58. package/dist/coverage/lcov-report/sorter.js +0 -163
  59. package/dist/coverage/lcov-report/sorter.js.map +0 -1
  60. package/dist/coverage/prettify.d.ts +0 -0
  61. package/dist/coverage/prettify.js +0 -477
  62. package/dist/coverage/prettify.js.map +0 -1
  63. package/dist/coverage/sorter.d.ts +0 -1
  64. package/dist/coverage/sorter.js +0 -163
  65. package/dist/coverage/sorter.js.map +0 -1
  66. package/dist/formatter/index.d.ts +0 -37
  67. package/dist/formatter/index.js +0 -75
  68. package/dist/formatter/index.js.map +0 -1
  69. package/dist/hal/index.d.ts +0 -5
  70. package/dist/hal/index.js +0 -69
  71. package/dist/hal/index.js.map +0 -1
  72. package/dist/health/health-logger.d.ts +0 -9
  73. package/dist/health/health-logger.js +0 -34
  74. package/dist/health/health-logger.js.map +0 -1
  75. package/dist/health/index.d.ts +0 -19
  76. package/dist/health/index.js +0 -175
  77. package/dist/health/index.js.map +0 -1
  78. package/dist/helpers/index.d.ts +0 -1
  79. package/dist/helpers/index.js +0 -2
  80. package/dist/helpers/index.js.map +0 -1
  81. package/dist/helpers/test-server-wrapper.d.ts +0 -120
  82. package/dist/helpers/test-server-wrapper.js +0 -165
  83. package/dist/helpers/test-server-wrapper.js.map +0 -1
  84. package/dist/index.d.ts +0 -1
  85. package/dist/index.js +0 -17
  86. package/dist/index.js.map +0 -1
  87. package/dist/last-commit.d.ts +0 -1
  88. package/dist/last-commit.js +0 -12
  89. package/dist/last-commit.js.map +0 -1
  90. package/dist/last_commit/index.d.ts +0 -7
  91. package/dist/last_commit/index.js +0 -83
  92. package/dist/last_commit/index.js.map +0 -1
  93. package/dist/paginator/s4-pagination.d.ts +0 -9
  94. package/dist/paginator/s4-pagination.js +0 -49
  95. package/dist/paginator/s4-pagination.js.map +0 -1
  96. package/dist/paginator/sql-pagination.d.ts +0 -27
  97. package/dist/paginator/sql-pagination.js +0 -166
  98. package/dist/paginator/sql-pagination.js.map +0 -1
  99. package/dist/paper-trail/helpers.d.ts +0 -11
  100. package/dist/paper-trail/helpers.js +0 -74
  101. package/dist/paper-trail/helpers.js.map +0 -1
  102. package/dist/paper-trail/index.d.ts +0 -13
  103. package/dist/paper-trail/index.js +0 -662
  104. package/dist/paper-trail/index.js.map +0 -1
  105. package/dist/prompts/index.d.ts +0 -14
  106. package/dist/prompts/index.js +0 -63
  107. package/dist/prompts/index.js.map +0 -1
  108. package/dist/queue/index.d.ts +0 -166
  109. package/dist/queue/index.js +0 -371
  110. package/dist/queue/index.js.map +0 -1
  111. package/dist/queue/publisher.d.ts +0 -31
  112. package/dist/queue/publisher.js +0 -84
  113. package/dist/queue/publisher.js.map +0 -1
  114. package/dist/queue/queue-logger.d.ts +0 -9
  115. package/dist/queue/queue-logger.js +0 -35
  116. package/dist/queue/queue-logger.js.map +0 -1
  117. package/dist/queue/subscriber.d.ts +0 -39
  118. package/dist/queue/subscriber.js +0 -97
  119. package/dist/queue/subscriber.js.map +0 -1
  120. package/dist/safe_proxy/index.d.ts +0 -13
  121. package/dist/safe_proxy/index.js +0 -54
  122. package/dist/safe_proxy/index.js.map +0 -1
  123. package/dist/serializer/index.d.ts +0 -5
  124. package/dist/serializer/index.js +0 -83
  125. package/dist/serializer/index.js.map +0 -1
  126. package/dist/test/debug-array.d.ts +0 -0
  127. package/dist/test/debug-array.js +0 -1
  128. package/dist/test/debug-array.js.map +0 -1
  129. package/dist/test/debug-setJSONB.d.ts +0 -0
  130. package/dist/test/debug-setJSONB.js +0 -1
  131. package/dist/test/debug-setJSONB.js.map +0 -1
  132. package/dist/test/prompt.test.d.ts +0 -1
  133. package/dist/test/prompt.test.js +0 -74
  134. package/dist/test/prompt.test.js.map +0 -1
  135. package/dist/test/s4-formatter.spec.d.ts +0 -1
  136. package/dist/test/s4-formatter.spec.js +0 -67
  137. package/dist/test/s4-formatter.spec.js.map +0 -1
  138. package/dist/test/s4-pagination.spec.d.ts +0 -1
  139. package/dist/test/s4-pagination.spec.js +0 -170
  140. package/dist/test/s4-pagination.spec.js.map +0 -1
  141. package/dist/test/safe-proxy.spec.d.ts +0 -1
  142. package/dist/test/safe-proxy.spec.js +0 -252
  143. package/dist/test/safe-proxy.spec.js.map +0 -1
  144. package/dist/test/serializer.spec.d.ts +0 -1
  145. package/dist/test/serializer.spec.js +0 -27
  146. package/dist/test/serializer.spec.js.map +0 -1
  147. package/dist/test/utils.spec.d.ts +0 -1
  148. package/dist/test/utils.spec.js +0 -446
  149. package/dist/test/utils.spec.js.map +0 -1
  150. package/dist/ts/cache/index.d.ts +0 -33
  151. package/dist/ts/cache/index.js +0 -171
  152. package/dist/ts/cache/index.js.map +0 -1
  153. package/dist/ts/configurations/server-config.d.ts +0 -4
  154. package/dist/ts/configurations/server-config.js +0 -2
  155. package/dist/ts/configurations/server-config.js.map +0 -1
  156. package/dist/ts/constants/index.d.ts +0 -7
  157. package/dist/ts/constants/index.js +0 -8
  158. package/dist/ts/constants/index.js.map +0 -1
  159. package/dist/ts/cycle/index.d.ts +0 -53
  160. package/dist/ts/cycle/index.js +0 -169
  161. package/dist/ts/cycle/index.js.map +0 -1
  162. package/dist/ts/dns/DnsCache.d.ts +0 -50
  163. package/dist/ts/dns/DnsCache.js +0 -137
  164. package/dist/ts/dns/DnsCache.js.map +0 -1
  165. package/dist/ts/dns/index.d.ts +0 -4
  166. package/dist/ts/dns/index.js +0 -4
  167. package/dist/ts/dns/index.js.map +0 -1
  168. package/dist/ts/formatter/index.d.ts +0 -44
  169. package/dist/ts/formatter/index.js +0 -76
  170. package/dist/ts/formatter/index.js.map +0 -1
  171. package/dist/ts/hal/index.d.ts +0 -26
  172. package/dist/ts/hal/index.js +0 -70
  173. package/dist/ts/hal/index.js.map +0 -1
  174. package/dist/ts/health/index.d.ts +0 -53
  175. package/dist/ts/health/index.js +0 -165
  176. package/dist/ts/health/index.js.map +0 -1
  177. package/dist/ts/helpers/index.d.ts +0 -1
  178. package/dist/ts/helpers/index.js +0 -2
  179. package/dist/ts/helpers/index.js.map +0 -1
  180. package/dist/ts/helpers/test-server-wrapper.d.ts +0 -56
  181. package/dist/ts/helpers/test-server-wrapper.js +0 -144
  182. package/dist/ts/helpers/test-server-wrapper.js.map +0 -1
  183. package/dist/ts/index.d.ts +0 -22
  184. package/dist/ts/index.js +0 -27
  185. package/dist/ts/index.js.map +0 -1
  186. package/dist/ts/last-commit/index.d.ts +0 -12
  187. package/dist/ts/last-commit/index.js +0 -82
  188. package/dist/ts/last-commit/index.js.map +0 -1
  189. package/dist/ts/logger/index.d.ts +0 -3
  190. package/dist/ts/logger/index.js +0 -4
  191. package/dist/ts/logger/index.js.map +0 -1
  192. package/dist/ts/logger/s4-logger.d.ts +0 -23
  193. package/dist/ts/logger/s4-logger.js +0 -105
  194. package/dist/ts/logger/s4-logger.js.map +0 -1
  195. package/dist/ts/paginator/index.d.ts +0 -2
  196. package/dist/ts/paginator/index.js +0 -3
  197. package/dist/ts/paginator/index.js.map +0 -1
  198. package/dist/ts/paginator/s4-pagination.d.ts +0 -26
  199. package/dist/ts/paginator/s4-pagination.js +0 -49
  200. package/dist/ts/paginator/s4-pagination.js.map +0 -1
  201. package/dist/ts/paginator/sql-pagination.d.ts +0 -52
  202. package/dist/ts/paginator/sql-pagination.js +0 -157
  203. package/dist/ts/paginator/sql-pagination.js.map +0 -1
  204. package/dist/ts/paper-trail/helpers.d.ts +0 -14
  205. package/dist/ts/paper-trail/helpers.js +0 -74
  206. package/dist/ts/paper-trail/helpers.js.map +0 -1
  207. package/dist/ts/paper-trail/index.d.ts +0 -54
  208. package/dist/ts/paper-trail/index.js +0 -236
  209. package/dist/ts/paper-trail/index.js.map +0 -1
  210. package/dist/ts/prompts/index.d.ts +0 -21
  211. package/dist/ts/prompts/index.js +0 -68
  212. package/dist/ts/prompts/index.js.map +0 -1
  213. package/dist/ts/queue/index.d.ts +0 -232
  214. package/dist/ts/queue/index.js +0 -440
  215. package/dist/ts/queue/index.js.map +0 -1
  216. package/dist/ts/queue/publisher.d.ts +0 -41
  217. package/dist/ts/queue/publisher.js +0 -84
  218. package/dist/ts/queue/publisher.js.map +0 -1
  219. package/dist/ts/queue/queue-logger.d.ts +0 -10
  220. package/dist/ts/queue/queue-logger.js +0 -35
  221. package/dist/ts/queue/queue-logger.js.map +0 -1
  222. package/dist/ts/queue/subscriber.d.ts +0 -55
  223. package/dist/ts/queue/subscriber.js +0 -98
  224. package/dist/ts/queue/subscriber.js.map +0 -1
  225. package/dist/ts/safe-proxy/index.d.ts +0 -35
  226. package/dist/ts/safe-proxy/index.js +0 -54
  227. package/dist/ts/safe-proxy/index.js.map +0 -1
  228. package/dist/ts/serializer/index.d.ts +0 -52
  229. package/dist/ts/serializer/index.js +0 -83
  230. package/dist/ts/serializer/index.js.map +0 -1
  231. package/dist/ts/task-scheduler/index.d.ts +0 -130
  232. package/dist/ts/task-scheduler/index.js +0 -259
  233. package/dist/ts/task-scheduler/index.js.map +0 -1
  234. package/dist/ts/utils/index.d.ts +0 -49
  235. package/dist/ts/utils/index.js +0 -157
  236. package/dist/ts/utils/index.js.map +0 -1
  237. package/test/health.spec.js +0 -213
  238. package/test/prompt.test.js +0 -91
  239. package/test/s4-formatter.spec.js +0 -80
  240. package/test/s4-pagination.spec.js +0 -196
  241. package/test/serializer.spec.js +0 -34
  242. package/test/utils.spec.js +0 -145
@@ -1,213 +0,0 @@
1
- import { expect, should as chaiShould } from "chai";
2
- import sinon from "sinon";
3
- import express from "express";
4
- import { healthCheck as hc } from "../index.js";
5
-
6
- const should = chaiShould();
7
-
8
- const mockResponse = () => {
9
- const res = {};
10
- res.status = sinon.stub().returns(res);
11
- res.setHeader = sinon.stub();
12
- res.json = sinon.stub().returns(res);
13
- res.send = sinon.spy();
14
- return res;
15
- };
16
-
17
- /* algorithm for shuffling an array */
18
- const shuffle = (a) => {
19
- for (let i = a.length - 1; i > 0; i--) {
20
- const j = Math.floor(Math.random() * (i + 1));
21
- [a[i], a[j]] = [a[j], a[i]];
22
- }
23
- return a;
24
- }
25
-
26
- describe("HealthCheck Testing", () => {
27
- let healthCheck = new hc();
28
-
29
- describe("Health Check Sanity", () => {
30
- it ("Should have NO predefined health checks", () => {
31
- return expect(healthCheck.healthChecks).to.be.an('array').that.is.empty;
32
- });
33
-
34
- it ("Should have have a sane default path route", () => {
35
- return expect(healthCheck.defaultPath()).to.match(/health_check/);
36
- });
37
-
38
- it ("Should have have sane response defaults", () => {
39
- expect(healthCheck.defaultResponse).to.have.property("status", 200);
40
- expect(healthCheck.defaultResponse).to.have.property("errors").to.be.an('object').to.be.empty;
41
- })
42
- });
43
-
44
- describe("Health Check Router", () => {
45
- it ("Should throw without a proper router object", () => {
46
- expect(healthCheck.routes.bind(healthCheck)).to.throw('missing_express_router');
47
- })
48
-
49
- it ("Should return a proper router object with an improved route", () => {
50
- let router = express.Router();
51
- let improved_router = healthCheck.routes(router);
52
- expect(improved_router).to.equal(router);
53
- })
54
- });
55
-
56
- describe("Check Health Checks", () => {
57
- let req, res;
58
-
59
- beforeEach("Setup hc object", () => {
60
- res = mockResponse();
61
- req = { baseUrl: "server.example.com/api/health_check.json" };
62
- healthCheck = new hc();
63
- })
64
-
65
- it ("Returns ok with no additional health check routes defined", (done) => {
66
- req = { baseUrl: "server.example.com/api/health_check.json" };
67
-
68
- const expectedResult = { check: 1, healthy: "true", message: "success" }
69
-
70
- healthCheck.checkHealth(req, res)
71
- .then((r) => {
72
- sinon.assert.alwaysCalledWith(res.status, 200);
73
- sinon.assert.calledOnce(res.status);
74
- sinon.assert.alwaysCalledWith(res.json, expectedResult)
75
- done()
76
- });
77
- })
78
-
79
- it("Returns success with a simple successful (v1) health check defined", (done) => {
80
- const sampleCheck = async () => {
81
- return { name: "db", "result": "success", critical: false };
82
- }
83
-
84
- healthCheck.addCheck(sampleCheck);
85
- expect(healthCheck.healthChecks).to.be.an('array').with.lengthOf(1);
86
-
87
- const expectedResult = { check: 1, healthy: "true", message: "success" }
88
- healthCheck.checkHealth(req, res)
89
- .then((r) => {
90
- sinon.assert.alwaysCalledWith(res.status, 200);
91
- sinon.assert.alwaysCalledWith(res.json, expectedResult);
92
- done()
93
- });
94
- })
95
-
96
- it("Returns fail with a failed health check", (done) => {
97
- const sampleCheck = async () => {
98
- return { name: "db", "result": "fail" };
99
- }
100
-
101
- healthCheck.addCheck(sampleCheck);
102
- expect(healthCheck.healthChecks).to.be.an('array').with.lengthOf(1);
103
-
104
- const expectedResult = { check: 1, healthy: "false", message: "fail" }
105
- healthCheck.checkHealth(req, res)
106
- .then(e => { done() })
107
- .catch(err => {
108
- sinon.assert.alwaysCalledWith(res.status, 500);
109
- sinon.assert.alwaysCalledWith(res.json, expectedResult);
110
- done()
111
- })
112
- })
113
-
114
- it("Returns unhealthy with an OK and failed health check", (done) => {
115
- const sampleFail = async () => {
116
- return { name: "db", "result": "fail" };
117
- }
118
-
119
- const sampleSuccess= async () => {
120
- return { name: "redis", "result": "success" };
121
- }
122
-
123
- shuffle([sampleFail, sampleSuccess]).forEach(el => {
124
- healthCheck.addCheck(el);
125
- })
126
-
127
- expect(healthCheck.healthChecks).to.be.an('array').with.lengthOf(2);
128
-
129
- healthCheck.checkHealth(req, res)
130
- .then(e => { done() })
131
- .catch(err => {
132
- sinon.assert.alwaysCalledWith(res.status, 500);
133
- sinon.assert.alwaysCalledWith(res.json, 'fail');
134
- done()
135
- })
136
- })
137
-
138
- it("Returns healthy/200 when non-critical element fails (v2)", async () => {
139
- const sampleCheck= async () => { throw new Error({status: 500}) }
140
-
141
- healthCheck.setupCheck({ name: "sample", critical: false, healthFunction: sampleCheck });
142
- expect(healthCheck.healthChecks).to.be.an('array').with.lengthOf(1);
143
-
144
- await healthCheck.checkHealth(req, res)
145
-
146
- sinon.assert.alwaysCalledWith(res.status, 200);
147
-
148
- const expectedResult = {
149
- check: 1,
150
- healthy: "true",
151
- message: "fail",
152
- services: [{ critical: false, name: "sample", result: "fail", status: undefined }]
153
- }
154
- sinon.assert.alwaysCalledWith(res.json, expectedResult);
155
- })
156
-
157
- it("Returns unhealthy/500 when a critical component returns failure (v2)", async () => {
158
- const sampleCheck= async () => { throw new Error({status: 500}) }
159
-
160
- healthCheck.setupCheck({ name: "sample", critical: true, healthFunction: sampleCheck });
161
- expect(healthCheck.healthChecks).to.be.an('array').with.lengthOf(1);
162
-
163
- await healthCheck.checkHealth(req, res)
164
-
165
- const expectedResult = {
166
- check: 1, healthy: false,
167
- message: "fail",
168
- services: [{ critical: true, name: "sample", result: "fail", status: undefined }]
169
- }
170
- sinon.assert.alwaysCalledWith(res.status, 500);
171
- sinon.assert.alwaysCalledWith(res.json, expectedResult);
172
- })
173
-
174
- it("Returns unhealthy/500 when a critical component returns failure (v2)", async () => {
175
- const sampleCheck= async () => { throw new Error({status: 500}) }
176
- const sampleCheck2= async () => { return true }
177
-
178
- healthCheck.setupCheck({ name: "sample", critical: true, healthFunction: sampleCheck });
179
- healthCheck.setupCheck({ name: "sample2", critical: true, healthFunction: sampleCheck2 });
180
- expect(healthCheck.healthChecks).to.be.an('array').with.lengthOf(2);
181
-
182
- await healthCheck.checkHealth(req, res)
183
-
184
- const expectedResult = {
185
- check: 1, healthy: false,
186
- message: "fail",
187
- services: [
188
- { critical: true, name: "sample", result: "fail", status: undefined },
189
- { critical: true, name: "sample2", result: "success" }]
190
- }
191
- sinon.assert.alwaysCalledWith(res.status, 500);
192
- sinon.assert.alwaysCalledWith(res.json, expectedResult);
193
- })
194
-
195
- it("Returns a different ID each time it runscheck", (done) => {
196
- let req2, res2;
197
- res2 = mockResponse();
198
-
199
- req = { baseUrl: "server.example.com/api/health_check.json" };
200
- req2 = req
201
-
202
- healthCheck.checkHealth(req, res)
203
- .then(() => {
204
- expect(healthCheck.lastCallId).to.equal(1)
205
- healthCheck.checkHealth(req2, res2)
206
- .then(() => {
207
- expect(healthCheck.lastCallId).to.equal(2)
208
- done()
209
- })
210
- })
211
- })
212
- })
213
- });
@@ -1,91 +0,0 @@
1
- import { expect } from "chai";
2
- import sinon from "sinon";
3
- import prompt from "prompt";
4
- import { ArgumentParser } from 'argparse';
5
- import logger from "../logger/s4-logger.js";
6
-
7
- import { setupCLIParser, cliSleep, promptCLIAsync, commonCLIInit, waitCLIPrompt, continueCLIPrompt } from "../prompts/index.js";
8
-
9
- describe("Prompt Functions", () => {
10
- describe("Setup Parser", () => {
11
- let loggerStub;
12
-
13
- beforeEach(() => {
14
- loggerStub = sinon.stub(logger, "info");
15
- });
16
-
17
- afterEach(() => {
18
- loggerStub.restore();
19
- });
20
-
21
- it("should create an ArgumentParser with the given description", () => {
22
- const description = "Test Description";
23
- const parser = setupCLIParser(description);
24
-
25
- expect(parser).to.be.instanceOf(ArgumentParser);
26
- expect(loggerStub.calledWith(description)).to.be.true;
27
- });
28
- });
29
-
30
- describe("cliSleep", () => {
31
- it("should return a promise that resolves after the specified time", async () => {
32
- const clock = sinon.useFakeTimers();
33
- const ms = 1000;
34
-
35
- const promise = cliSleep(ms);
36
- clock.tick(ms);
37
-
38
- await promise;
39
- clock.restore();
40
- });
41
- });
42
-
43
- describe("Prompt Async", () => {
44
- let promptStub;
45
-
46
- beforeEach(() => {
47
- promptStub = sinon.stub(prompt, "get");
48
- });
49
-
50
- afterEach(() => {
51
- promptStub.restore();
52
- });
53
-
54
- it("should resolve with response when prompt succeeds", async () => {
55
- const options = { name: "test" };
56
- const mockResponse = { name: "response" };
57
-
58
- promptStub.yields(null, mockResponse);
59
-
60
- const result = await promptCLIAsync(options);
61
- expect(result).to.equal(mockResponse);
62
- expect(promptStub.calledWith(options)).to.be.true;
63
- });
64
-
65
- it("should reject with error when prompt fails", async () => {
66
- const options = { name: "test" };
67
- const mockError = new Error("Prompt error");
68
-
69
- promptStub.yields(mockError, null);
70
-
71
- try {
72
- await promptCLIAsync(options);
73
- expect.fail("Should have thrown an error");
74
- } catch (error) {
75
- expect(error).to.equal(mockError);
76
- }
77
- });
78
- });
79
-
80
- describe("Prompt Objects", () => {
81
- it("should define waitPrompt with correct structure", () => {
82
- expect(waitCLIPrompt).to.have.property("Push <enter> when done");
83
- expect(waitCLIPrompt["Push <enter> when done"]).to.have.property("type", "boolean");
84
- });
85
-
86
- it("should define continuePrompt with correct structure", () => {
87
- expect(continueCLIPrompt).to.have.property("Push <enter> to continue");
88
- expect(continueCLIPrompt["Push <enter> to continue"]).to.have.property("type", "boolean");
89
- });
90
- });
91
- });
@@ -1,80 +0,0 @@
1
- import should from "should";
2
- import { expect as expect } from "chai";
3
-
4
- import S4Formatter from "../formatter/index.js";
5
-
6
- describe("Formatter", function () {
7
- let response;
8
-
9
- describe("Sending legacy format []", function () {
10
- before("Setup", function () {
11
- const error = { status: 200, error: ["error1"] }
12
- response = S4Formatter.formatError(error);
13
- })
14
-
15
- describe("Default values", function () {
16
- it("should have a generic error", function () {
17
- response.should.have.property("errors");
18
- });
19
-
20
- it("should have error code set correctly", function () {
21
- response.should.have.property("status", 200);
22
- });
23
- });
24
- });
25
-
26
- describe("Support null error payloads", function () {
27
- before("Setup", function () {
28
- response = S4Formatter.formatError(null);
29
- })
30
-
31
- describe("Default values", function () {
32
- it("Should have a default error level and blank errors", function () {
33
- expect(response).to.have.property("status",422);
34
- expect(response).to.have.property("errors").to.be.empty;
35
- });
36
-
37
- });
38
- });
39
-
40
- describe("Should not fold in funky keys/values", function () {
41
- before("Setup", function () {
42
- response = S4Formatter.formatError({randomKey: 123});
43
- })
44
-
45
- describe("Default values", function () {
46
- it("Should not funky key name folded in", function () {
47
- response.should.not.have.property("randomKey", {});
48
- });
49
- });
50
- });
51
-
52
- describe("Support validator formats", function () {
53
- before("Setup", function () {
54
- let error = {
55
- "status": 422,
56
- "errors": {
57
- "password": {
58
- "location": "body",
59
- "param": "password",
60
- "value": "badPassw0rd",
61
- "msg": "weak"
62
- }
63
- }
64
- }
65
-
66
- response = S4Formatter.formatError(error);
67
- })
68
-
69
- describe("Default values", function () {
70
- it("Should have a default error level and blank errors", function () {
71
- response.should.have.property("status", 422);
72
- expect(response).to.be.an("object");
73
- expect(response).to.have.property('errors');
74
- expect(Object.keys(response['errors'])).to.have.lengthOf('1')
75
- response.should.have.property("errors");
76
- });
77
-
78
- });
79
- });
80
- })
@@ -1,196 +0,0 @@
1
- import should from "should";
2
- import S4Pagination from "../paginator/s4-pagination.js";
3
- import http_mocks from "node-mocks-http";
4
- import events from "events";
5
-
6
- describe("Pagination", function () {
7
- var paginator = null;
8
- var request = null;
9
- var response = null;
10
- var next = null;
11
-
12
- before("Setup", function () {
13
- next = function () { };
14
- response = http_mocks.createResponse({ eventEmitter: events.EventEmitter });
15
- request = http_mocks.createRequest({
16
- method: "GET",
17
- url: "/"
18
- })
19
- paginator = S4Pagination.createPaginator(request, response, next);
20
- });
21
-
22
- describe("Parsing query parameters", function () {
23
- describe("Default values", function () {
24
- it("should have default page set to 1", function () {
25
- paginator.should.have.property("page", 1);
26
- });
27
-
28
- it("should have default page size set to 5", function () {
29
- paginator.should.have.property("page_size", 5);
30
- });
31
- });
32
-
33
- describe("Page value set to 0", function () {
34
- before("Setup", function () {
35
- request = http_mocks.createRequest({
36
- method: "GET",
37
- url: "/?page=0"
38
- })
39
- paginator = S4Pagination.createPaginator(request, response, next);
40
- });
41
-
42
- it("should set page to 1", function () {
43
- paginator.should.have.property("page", 1);
44
- });
45
- });
46
-
47
- describe("Page value set to negative", function () {
48
- before("Setup", function () {
49
- request = http_mocks.createRequest({
50
- method: "GET",
51
- url: "/?page=-1"
52
- })
53
- paginator = S4Pagination.createPaginator(request, response, next);
54
- });
55
-
56
- it("should set page to 1", function () {
57
- paginator.should.have.property("page", 1);
58
- });
59
- });
60
-
61
- describe("Page value set to 2", function () {
62
- before("Setup", function () {
63
- request = http_mocks.createRequest({
64
- method: "GET",
65
- url: "/?page=2"
66
- })
67
- paginator = S4Pagination.createPaginator(request, response, next);
68
- });
69
-
70
- it("should set page to 2", function () {
71
- paginator.should.have.property("page", 2);
72
- });
73
- });
74
-
75
- describe("Page value set to 10", function () {
76
- before("Setup", function () {
77
- request = http_mocks.createRequest({
78
- method: "GET",
79
- url: "/?page=10"
80
- })
81
- paginator = S4Pagination.createPaginator(request, response, next);
82
- });
83
-
84
- it("should set page to 10", function () {
85
- paginator.should.have.property("page", 10);
86
- });
87
- });
88
-
89
- describe("Page value set to 100", function () {
90
- before("Setup", function () {
91
- request = http_mocks.createRequest({
92
- method: "GET",
93
- url: "/?page=100"
94
- })
95
- paginator = S4Pagination.createPaginator(request, response, next);
96
- });
97
-
98
- it("should set page to 100", function () {
99
- paginator.should.have.property("page", 100);
100
- });
101
- });
102
-
103
- describe("Page Size value set to 0", function () {
104
- before("Setup", function () {
105
- request = http_mocks.createRequest({
106
- method: "GET",
107
- url: "/?page_size=0"
108
- })
109
- paginator = S4Pagination.createPaginator(request, response, next);
110
- });
111
-
112
- it("should set page size to 5", function () {
113
- paginator.should.have.property("page_size", 5);
114
- });
115
- });
116
-
117
- describe("Page Size value set to negative", function () {
118
- before("Setup", function () {
119
- request = http_mocks.createRequest({
120
- method: "GET",
121
- url: "/?page_size=-1"
122
- })
123
- paginator = S4Pagination.createPaginator(request, response, next);
124
- });
125
-
126
- it("should set page size to 5", function () {
127
- paginator.should.have.property("page_size", 5);
128
- });
129
- });
130
-
131
- describe("Page Size value set to 2", function () {
132
- before("Setup", function () {
133
- request = http_mocks.createRequest({
134
- method: "GET",
135
- url: "/?page_size=2"
136
- })
137
- paginator = S4Pagination.createPaginator(request, response, next);
138
- });
139
-
140
- it("should set page size to 5", function () {
141
- paginator.should.have.property("page_size", 5);
142
- });
143
- });
144
-
145
- describe("Page Size value set to 10", function () {
146
- before("Setup", function () {
147
- request = http_mocks.createRequest({
148
- method: "GET",
149
- url: "/?page_size=10"
150
- })
151
- paginator = S4Pagination.createPaginator(request, response, next);
152
- });
153
-
154
- it("should set page size to 10", function () {
155
- paginator.should.have.property("page_size", 10);
156
- });
157
- });
158
-
159
- describe("Page Size value set to 100", function () {
160
- before("Setup", function () {
161
- request = http_mocks.createRequest({
162
- method: "GET",
163
- url: "/?page_size=100"
164
- })
165
- paginator = S4Pagination.createPaginator(request, response, next);
166
- });
167
-
168
- it("should set page size to 100", function () {
169
- paginator.should.have.property("page_size", 100);
170
- });
171
- });
172
- });
173
-
174
- describe("Replying", function() {
175
- beforeEach("Clear request", function() {
176
- response = http_mocks.createResponse({ eventEmitter: events.EventEmitter });
177
- paginator = S4Pagination.createPaginator(request, response, next);
178
- });
179
-
180
- it ("should return 500 if data is null", function(){
181
- paginator.reply(null);
182
- response.statusCode.should.equal(500);
183
- });
184
-
185
- it ("should return pagination data", function(){
186
- const items = [1,2,3,4,5,6,7,8,9,10];
187
- const data = {
188
- docs : items,
189
- total : items.length,
190
- };
191
- paginator.reply(data);
192
- response.statusCode.should.equal(200);
193
- response._getHeaders().should.have.property("s4-pagination");
194
- });
195
- });
196
- });
@@ -1,34 +0,0 @@
1
- import { expect } from "chai";
2
- import serializer from "../serializer/index.js";
3
-
4
- describe("Serializer", () => {
5
-
6
- describe("Serialize", () => {
7
-
8
- it ("should not show Hidden/Removed fields", () => {
9
- const model = { prototype: {} }
10
- model.prototype.get = function() {
11
- return {
12
- name: "John",
13
- hidden_prefs: "should be hidden",
14
- password: "password",
15
- password_salt: "password_salt",
16
- mfa_totp_secret: "mfa_totp_secret",
17
- }
18
- }
19
- const options = { hide: ["hidden_prefs"], remove: ["password", "password_salt", "mfa_totp_secret"] }
20
-
21
- serializer.serialize(model, options);
22
-
23
- const serialized = model.prototype.toJSON();
24
-
25
- expect(serialized.name).to.eq("John");
26
-
27
- expect(serialized.hidden_prefs).to.be.undefined;
28
- expect(serialized.password).to.be.undefined;
29
- expect(serialized.password_salt).to.be.undefined;
30
- expect(serialized.mfa_totp_secret).to.be.undefined;
31
- });
32
-
33
- });
34
- });