@laboratoria/sdk-js 0.1.0 → 1.1.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 (40) hide show
  1. package/README.md +40 -3
  2. package/index.js +12 -20
  3. package/lib/core.js +67 -11
  4. package/lib/curriculum.js +59 -0
  5. package/lib/model.js +108 -36
  6. package/package.json +21 -11
  7. package/schemas/core.json +211 -11
  8. package/coverage/clover.xml +0 -140
  9. package/coverage/coverage-final.json +0 -9
  10. package/coverage/lcov-report/base.css +0 -224
  11. package/coverage/lcov-report/block-navigation.js +0 -79
  12. package/coverage/lcov-report/client.js.html +0 -152
  13. package/coverage/lcov-report/core.js.html +0 -281
  14. package/coverage/lcov-report/favicon.png +0 -0
  15. package/coverage/lcov-report/index.html +0 -126
  16. package/coverage/lcov-report/model.js.html +0 -557
  17. package/coverage/lcov-report/prettify.css +0 -1
  18. package/coverage/lcov-report/prettify.js +0 -2
  19. package/coverage/lcov-report/sdk-js/index.html +0 -111
  20. package/coverage/lcov-report/sdk-js/index.js.html +0 -293
  21. package/coverage/lcov-report/sdk-js/lib/campuses.js.html +0 -146
  22. package/coverage/lcov-report/sdk-js/lib/client.js.html +0 -152
  23. package/coverage/lcov-report/sdk-js/lib/core.js.html +0 -374
  24. package/coverage/lcov-report/sdk-js/lib/currencies.js.html +0 -89
  25. package/coverage/lcov-report/sdk-js/lib/index.html +0 -201
  26. package/coverage/lcov-report/sdk-js/lib/jobs.js.html +0 -143
  27. package/coverage/lcov-report/sdk-js/lib/model.js.html +0 -665
  28. package/coverage/lcov-report/sdk-js/lib/roles.js.html +0 -110
  29. package/coverage/lcov-report/sdk-js/lib/schemas.js.html +0 -434
  30. package/coverage/lcov-report/sdk-js/lib/team.js.html +0 -233
  31. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  32. package/coverage/lcov-report/sorter.js +0 -170
  33. package/coverage/lcov-report/team.js.html +0 -209
  34. package/coverage/lcov.info +0 -359
  35. package/index.spec.js +0 -112
  36. package/lib/client.spec.js +0 -77
  37. package/lib/currencies.js +0 -3
  38. package/lib/model.spec.js +0 -215
  39. package/lib/team.js +0 -52
  40. package/schemas/team.json +0 -146
@@ -1,359 +0,0 @@
1
- TN:
2
- SF:index.js
3
- FN:13,(anonymous_0)
4
- FN:30,(anonymous_1)
5
- FN:35,(anonymous_2)
6
- FN:35,(anonymous_3)
7
- FN:41,(anonymous_4)
8
- FN:51,(anonymous_5)
9
- FN:57,(anonymous_6)
10
- FN:62,(anonymous_7)
11
- FNF:8
12
- FNH:8
13
- FNDA:6,(anonymous_0)
14
- FNDA:3,(anonymous_1)
15
- FNDA:3,(anonymous_2)
16
- FNDA:3,(anonymous_3)
17
- FNDA:1,(anonymous_4)
18
- FNDA:1,(anonymous_5)
19
- FNDA:1,(anonymous_6)
20
- FNDA:1,(anonymous_7)
21
- DA:13,1
22
- DA:20,6
23
- DA:27,6
24
- DA:28,6
25
- DA:30,6
26
- DA:31,3
27
- DA:34,6
28
- DA:35,3
29
- DA:36,3
30
- DA:37,1
31
- DA:38,1
32
- DA:40,2
33
- DA:42,1
34
- DA:48,1
35
- DA:49,1
36
- DA:52,1
37
- DA:53,1
38
- DA:54,1
39
- DA:57,1
40
- DA:62,1
41
- DA:65,6
42
- LF:21
43
- LH:21
44
- BRDA:13,0,0,6
45
- BRDA:14,1,0,6
46
- BRDA:15,2,0,6
47
- BRDA:16,3,0,6
48
- BRDA:17,4,0,6
49
- BRDA:18,5,0,6
50
- BRDA:36,6,0,1
51
- BRDA:36,6,1,2
52
- BRF:8
53
- BRH:8
54
- end_of_record
55
- TN:
56
- SF:lib/client.js
57
- FN:1,(anonymous_0)
58
- FN:1,(anonymous_1)
59
- FNF:2
60
- FNH:2
61
- FNDA:4,(anonymous_0)
62
- FNDA:4,(anonymous_1)
63
- DA:1,4
64
- DA:2,4
65
- DA:3,4
66
- DA:14,4
67
- DA:16,4
68
- DA:17,1
69
- DA:23,3
70
- LF:7
71
- LH:7
72
- BRDA:1,0,0,3
73
- BRDA:2,1,0,1
74
- BRDA:2,1,1,3
75
- BRDA:7,2,0,4
76
- BRDA:7,2,1,1
77
- BRDA:8,3,0,4
78
- BRDA:8,3,1,1
79
- BRDA:11,4,0,4
80
- BRDA:11,4,1,1
81
- BRDA:16,5,0,1
82
- BRDA:16,5,1,3
83
- BRF:11
84
- BRH:11
85
- end_of_record
86
- TN:
87
- SF:lib/core.js
88
- FN:20,(anonymous_0)
89
- FN:32,(anonymous_1)
90
- FN:58,(anonymous_2)
91
- FN:90,(anonymous_3)
92
- FNF:4
93
- FNH:1
94
- FNDA:0,(anonymous_0)
95
- FNDA:0,(anonymous_1)
96
- FNDA:0,(anonymous_2)
97
- FNDA:6,(anonymous_3)
98
- DA:4,1
99
- DA:20,0
100
- DA:33,0
101
- DA:59,0
102
- DA:90,6
103
- LF:5
104
- LH:2
105
- BRDA:59,0,0,0
106
- BRDA:59,0,1,0
107
- BRF:2
108
- BRH:0
109
- end_of_record
110
- TN:
111
- SF:lib/currencies.js
112
- FNF:0
113
- FNH:0
114
- DA:1,1
115
- LF:1
116
- LH:1
117
- BRF:0
118
- BRH:0
119
- end_of_record
120
- TN:
121
- SF:lib/jobs.js
122
- FN:19,(anonymous_0)
123
- FNF:1
124
- FNH:1
125
- FNDA:6,(anonymous_0)
126
- DA:4,1
127
- DA:19,6
128
- LF:2
129
- LH:2
130
- BRF:0
131
- BRH:0
132
- end_of_record
133
- TN:
134
- SF:lib/model.js
135
- FN:3,(anonymous_0)
136
- FN:7,(anonymous_1)
137
- FN:43,(anonymous_2)
138
- FN:44,(anonymous_3)
139
- FN:58,(anonymous_4)
140
- FN:61,(anonymous_5)
141
- FN:61,(anonymous_6)
142
- FN:66,(anonymous_7)
143
- FN:66,(anonymous_8)
144
- FN:72,(anonymous_9)
145
- FN:73,(anonymous_10)
146
- FN:88,(anonymous_11)
147
- FN:93,(anonymous_12)
148
- FN:94,(anonymous_13)
149
- FN:99,(anonymous_14)
150
- FN:104,(anonymous_15)
151
- FN:106,(anonymous_16)
152
- FN:127,(anonymous_17)
153
- FN:130,(anonymous_18)
154
- FN:135,(anonymous_19)
155
- FN:136,(anonymous_20)
156
- FN:137,(anonymous_21)
157
- FN:138,(anonymous_22)
158
- FN:141,(anonymous_23)
159
- FN:146,(anonymous_24)
160
- FN:153,(anonymous_25)
161
- FN:155,(anonymous_26)
162
- FN:171,(anonymous_27)
163
- FN:173,(anonymous_28)
164
- FN:182,(anonymous_29)
165
- FNF:30
166
- FNH:29
167
- FNDA:108,(anonymous_0)
168
- FNDA:11,(anonymous_1)
169
- FNDA:2,(anonymous_2)
170
- FNDA:2,(anonymous_3)
171
- FNDA:7,(anonymous_4)
172
- FNDA:108,(anonymous_5)
173
- FNDA:7,(anonymous_6)
174
- FNDA:108,(anonymous_7)
175
- FNDA:6,(anonymous_8)
176
- FNDA:108,(anonymous_9)
177
- FNDA:941,(anonymous_10)
178
- FNDA:108,(anonymous_11)
179
- FNDA:7,(anonymous_12)
180
- FNDA:2,(anonymous_13)
181
- FNDA:2,(anonymous_14)
182
- FNDA:2,(anonymous_15)
183
- FNDA:2,(anonymous_16)
184
- FNDA:2,(anonymous_17)
185
- FNDA:0,(anonymous_18)
186
- FNDA:1,(anonymous_19)
187
- FNDA:1,(anonymous_20)
188
- FNDA:1,(anonymous_21)
189
- FNDA:1,(anonymous_22)
190
- FNDA:2,(anonymous_23)
191
- FNDA:1,(anonymous_24)
192
- FNDA:18,(anonymous_25)
193
- FNDA:90,(anonymous_26)
194
- FNDA:18,(anonymous_27)
195
- FNDA:90,(anonymous_28)
196
- FNDA:840,(anonymous_29)
197
- DA:3,2
198
- DA:4,108
199
- DA:5,108
200
- DA:7,108
201
- DA:8,11
202
- DA:9,11
203
- DA:10,11
204
- DA:12,11
205
- DA:13,5
206
- DA:14,3
207
- DA:16,2
208
- DA:17,2
209
- DA:21,6
210
- DA:23,2
211
- DA:24,2
212
- DA:26,0
213
- DA:28,3
214
- DA:29,3
215
- DA:30,2
216
- DA:32,1
217
- DA:34,0
218
- DA:36,0
219
- DA:42,108
220
- DA:43,2
221
- DA:45,2
222
- DA:46,2
223
- DA:47,1
224
- DA:49,1
225
- DA:58,7
226
- DA:61,108
227
- DA:62,7
228
- DA:66,108
229
- DA:72,108
230
- DA:74,941
231
- DA:88,2
232
- DA:89,108
233
- DA:90,108
234
- DA:91,108
235
- DA:92,108
236
- DA:93,108
237
- DA:94,108
238
- DA:99,108
239
- DA:104,108
240
- DA:105,2
241
- DA:107,2
242
- DA:108,2
243
- DA:119,2
244
- DA:126,108
245
- DA:128,2
246
- DA:131,0
247
- DA:135,1
248
- DA:136,1
249
- DA:137,1
250
- DA:138,1
251
- DA:142,2
252
- DA:146,1
253
- DA:153,2
254
- DA:154,18
255
- DA:156,90
256
- DA:157,90
257
- DA:171,2
258
- DA:172,18
259
- DA:173,90
260
- DA:182,840
261
- LF:64
262
- LH:60
263
- BRDA:4,0,0,108
264
- BRDA:4,0,1,9
265
- BRDA:5,1,0,108
266
- BRDA:5,1,1,72
267
- BRDA:8,2,0,11
268
- BRDA:8,2,1,1
269
- BRDA:9,3,0,3
270
- BRDA:9,3,1,8
271
- BRDA:10,4,0,11
272
- BRDA:10,4,1,3
273
- BRDA:12,5,0,5
274
- BRDA:12,5,1,6
275
- BRDA:13,6,0,3
276
- BRDA:13,6,1,2
277
- BRDA:13,7,0,5
278
- BRDA:13,7,1,3
279
- BRDA:16,8,0,2
280
- BRDA:16,8,1,0
281
- BRDA:21,9,0,2
282
- BRDA:21,9,1,3
283
- BRDA:21,9,2,0
284
- BRDA:21,9,3,0
285
- BRDA:21,9,4,1
286
- BRDA:23,10,0,2
287
- BRDA:23,10,1,0
288
- BRDA:23,11,0,2
289
- BRDA:23,11,1,2
290
- BRDA:29,12,0,2
291
- BRDA:29,12,1,1
292
- BRDA:29,13,0,3
293
- BRDA:29,13,1,3
294
- BRDA:46,14,0,1
295
- BRDA:46,14,1,1
296
- BRDA:58,15,0,5
297
- BRDA:58,16,0,0
298
- BRDA:58,16,1,7
299
- BRDA:62,17,0,4
300
- BRDA:62,17,1,3
301
- BRDA:66,18,0,2
302
- BRDA:67,19,0,6
303
- BRDA:67,19,1,6
304
- BRDA:67,19,2,0
305
- BRDA:72,20,0,108
306
- BRDA:72,20,1,9
307
- BRDA:74,21,0,96
308
- BRDA:74,21,1,845
309
- BRDA:75,22,0,941
310
- BRDA:75,22,1,863
311
- BRDA:75,22,2,18
312
- BRDA:88,23,0,9
313
- BRDA:107,24,0,2
314
- BRDA:107,24,1,0
315
- BRDA:111,25,0,1
316
- BRDA:111,25,1,1
317
- BRDA:111,26,0,2
318
- BRDA:111,26,1,1
319
- BRDA:120,27,0,0
320
- BRDA:120,27,1,2
321
- BRDA:138,28,0,1
322
- BRDA:138,28,1,0
323
- BRDA:142,29,0,1
324
- BRDA:142,29,1,1
325
- BRDA:162,30,0,90
326
- BRDA:162,30,1,72
327
- BRDA:176,31,0,12
328
- BRDA:176,31,1,78
329
- BRDA:186,32,0,840
330
- BRDA:186,32,1,510
331
- BRDA:189,33,0,78
332
- BRDA:189,33,1,54
333
- BRF:70
334
- BRH:61
335
- end_of_record
336
- TN:
337
- SF:lib/roles.js
338
- FNF:0
339
- FNH:0
340
- DA:1,1
341
- DA:3,1
342
- LF:2
343
- LH:2
344
- BRF:0
345
- BRH:0
346
- end_of_record
347
- TN:
348
- SF:lib/team.js
349
- FN:49,(anonymous_0)
350
- FNF:1
351
- FNH:1
352
- FNDA:6,(anonymous_0)
353
- DA:6,1
354
- DA:49,6
355
- LF:2
356
- LH:2
357
- BRF:0
358
- BRH:0
359
- end_of_record
package/index.spec.js DELETED
@@ -1,112 +0,0 @@
1
- import { initializeApp } from 'firebase/app';
2
- import {
3
- getAuth,
4
- onAuthStateChanged,
5
- signInWithEmailAndPassword,
6
- signOut,
7
- } from 'firebase/auth';
8
- import { createClient } from './lib/client.js';
9
- import { createApp } from './index.js';
10
-
11
- jest.mock('./lib/client.js');
12
-
13
- beforeEach(() => {
14
- initializeApp.mockClear();
15
- onAuthStateChanged.mockClear();
16
- signInWithEmailAndPassword.mockClear();
17
- });
18
-
19
- describe('createApp', () => {
20
- it('should invoke firebase\'s initializaApp', () => {
21
- createApp();
22
- expect(initializeApp).toHaveBeenCalledTimes(1);
23
- expect(initializeApp.mock.calls[0]).toMatchSnapshot();
24
- });
25
- });
26
-
27
- describe('app.auth.onChange', () => {
28
- it('should listen to firebase\'s onAuthStateChanged and notify subscribers when not authenticated', (done) => {
29
- const { auth } = createApp();
30
-
31
- onAuthStateChanged.mockImplementationOnce((_, cb) => {
32
- cb();
33
- return () => { };
34
- });
35
-
36
- auth.onChange(({ authUser, user }) => {
37
- expect(authUser).toBeNull();
38
- expect(user).toBeNull();
39
- done();
40
- });
41
- });
42
-
43
- it('should fetch user from db when authenticated and add isStaff, isManager, etc', (done) => {
44
- const { auth } = createApp();
45
- const mockAuthUser = { uid: 'xxx', getIdToken: () => 'token' };
46
- const userMock = { uid: 'xxx', email: 'foo@bar.baz' };
47
-
48
- onAuthStateChanged.mockImplementationOnce((_, cb) => {
49
- cb(mockAuthUser);
50
- return () => { };
51
- });
52
-
53
- createClient().mockResolvedValueOnce(userMock);
54
-
55
- auth.onChange(({ authUser, user }) => {
56
- expect(authUser).toEqual(mockAuthUser);
57
- expect(user).toEqual({
58
- ...userMock,
59
- isStaff: false,
60
- isManager: false,
61
- isFinance: false,
62
- isAdmin: false,
63
- });
64
- done();
65
- });
66
- });
67
-
68
- it('should log error and reset state (authUser = null, user = null) when fetch user from db fails', (done) => {
69
- const { auth } = createApp();
70
- const mockAuthUser = { uid: 'xxx', getIdToken: () => 'token' };
71
- const spy = jest.spyOn(console, 'error').mockImplementationOnce(() => { })
72
- const error = new Error('OMG');
73
-
74
- onAuthStateChanged.mockImplementationOnce((_, cb) => {
75
- cb(mockAuthUser);
76
- return () => { };
77
- });
78
-
79
- createClient().mockRejectedValueOnce(error);
80
-
81
- auth.onChange(({ authUser, user }) => {
82
- expect(authUser).toBeNull();
83
- expect(user).toBeNull();
84
- expect(spy).toHaveBeenCalledWith(error);
85
- spy.mockRestore();
86
- done();
87
- });
88
- });
89
- });
90
-
91
- describe('app.auth.signIn', () => {
92
- it('should delegate to firebase\'s signInWithEmailAndPassword', async () => {
93
- const { auth } = createApp();
94
- const email = 'foo@bar.baz';
95
- const pass = 'secret';
96
-
97
- await auth.signIn(email, pass);
98
-
99
- expect(signInWithEmailAndPassword).toHaveBeenCalledTimes(1);
100
- expect(signInWithEmailAndPassword).toHaveBeenCalledWith({}, email, pass);
101
- });
102
- });
103
-
104
- describe('app.auth.signOut', () => {
105
- it('should delegate to firebase\'s signOut', async () => {
106
- const { auth } = createApp();
107
-
108
- await auth.signOut();
109
-
110
- expect(signOut).toHaveBeenCalledTimes(1);
111
- });
112
- });
@@ -1,77 +0,0 @@
1
- import { createClient } from './client.js';
2
-
3
- describe('client', () => {
4
-
5
- beforeAll(() => window.fetch = jest.fn());
6
-
7
- afterEach(() => {
8
- window.fetch.mockClear();
9
- jest.restoreAllMocks();
10
- });
11
-
12
- it('should delegate to global fetch and add mode:cors and parse JSON resp when OK', async () => {
13
- window.fetch.mockResolvedValue({
14
- json: jest.fn().mockResolvedValue({ ok: true }),
15
- });
16
- const baseUrl = 'http://foo.bar';
17
- const client = createClient(baseUrl);
18
- expect(await client('/')).toEqual({ ok: true });
19
- expect(window.fetch).toHaveBeenCalledTimes(1);
20
- expect(window.fetch).toHaveBeenCalledWith(`${baseUrl}/`, {
21
- mode: 'cors',
22
- headers: {},
23
- });
24
- });
25
-
26
- it('should reject when response.status > 202', async () => {
27
- window.fetch.mockResolvedValue({
28
- status: 400,
29
- json: jest.fn().mockResolvedValue({ ok: false }),
30
- });
31
- const baseUrl = 'http://foo.bar';
32
- const client = createClient(baseUrl);
33
- await expect(client('/')).rejects.toThrow('HTTP Error 400');
34
- expect(window.fetch).toHaveBeenCalledTimes(1);
35
- expect(window.fetch).toHaveBeenCalledWith(`${baseUrl}/`, {
36
- mode: 'cors',
37
- headers: {},
38
- });
39
- });
40
-
41
- it('should add token when authUser present', async () => {
42
- window.fetch.mockResolvedValue({
43
- json: jest.fn().mockResolvedValue({ ok: true }),
44
- });
45
- const baseUrl = 'http://foo.bar';
46
- const user = { getIdToken: jest.fn().mockReturnValueOnce('xxx') };
47
- const client = createClient(baseUrl, user);
48
- expect(await client('/')).toEqual({ ok: true });
49
- expect(window.fetch).toHaveBeenCalledTimes(1);
50
- expect(window.fetch).toHaveBeenCalledWith(`${baseUrl}/`, {
51
- mode: 'cors',
52
- headers: {
53
- authorization: 'Bearer xxx',
54
- },
55
- });
56
- expect(user.getIdToken).toHaveBeenCalledTimes(1);
57
- });
58
-
59
- it('should add content-type header and stringify body when necessary', async () => {
60
- window.fetch.mockResolvedValue({
61
- json: jest.fn().mockResolvedValue({ ok: true }),
62
- });
63
- const baseUrl = 'http://foo.bar';
64
- const client = createClient(baseUrl);
65
- const body = { foo: 'bar' };
66
- expect(await client('/', { method: 'POST', body })).toEqual({ ok: true });
67
- expect(window.fetch).toHaveBeenCalledTimes(1);
68
- expect(window.fetch).toHaveBeenCalledWith(`${baseUrl}/`, {
69
- mode: 'cors',
70
- headers: {
71
- 'content-type': 'application/json',
72
- },
73
- method: 'POST',
74
- body: JSON.stringify(body),
75
- });
76
- });
77
- });
package/lib/currencies.js DELETED
@@ -1,3 +0,0 @@
1
- const currencies = ['BRL', 'CLP', 'COP', 'MXN', 'PEN', 'USD'];
2
-
3
- export default currencies;