@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.
- package/README.md +40 -3
- package/index.js +12 -20
- package/lib/core.js +67 -11
- package/lib/curriculum.js +59 -0
- package/lib/model.js +108 -36
- package/package.json +21 -11
- package/schemas/core.json +211 -11
- package/coverage/clover.xml +0 -140
- package/coverage/coverage-final.json +0 -9
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/client.js.html +0 -152
- package/coverage/lcov-report/core.js.html +0 -281
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -126
- package/coverage/lcov-report/model.js.html +0 -557
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sdk-js/index.html +0 -111
- package/coverage/lcov-report/sdk-js/index.js.html +0 -293
- package/coverage/lcov-report/sdk-js/lib/campuses.js.html +0 -146
- package/coverage/lcov-report/sdk-js/lib/client.js.html +0 -152
- package/coverage/lcov-report/sdk-js/lib/core.js.html +0 -374
- package/coverage/lcov-report/sdk-js/lib/currencies.js.html +0 -89
- package/coverage/lcov-report/sdk-js/lib/index.html +0 -201
- package/coverage/lcov-report/sdk-js/lib/jobs.js.html +0 -143
- package/coverage/lcov-report/sdk-js/lib/model.js.html +0 -665
- package/coverage/lcov-report/sdk-js/lib/roles.js.html +0 -110
- package/coverage/lcov-report/sdk-js/lib/schemas.js.html +0 -434
- package/coverage/lcov-report/sdk-js/lib/team.js.html +0 -233
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov-report/team.js.html +0 -209
- package/coverage/lcov.info +0 -359
- package/index.spec.js +0 -112
- package/lib/client.spec.js +0 -77
- package/lib/currencies.js +0 -3
- package/lib/model.spec.js +0 -215
- package/lib/team.js +0 -52
- package/schemas/team.json +0 -146
package/lib/model.spec.js
DELETED
@@ -1,215 +0,0 @@
|
|
1
|
-
import createModel from './model.js';
|
2
|
-
import { createClient } from './client.js';
|
3
|
-
|
4
|
-
jest.mock('./client.js');
|
5
|
-
|
6
|
-
beforeEach(() => createClient().mockClear());
|
7
|
-
|
8
|
-
describe('model.schema', () => {
|
9
|
-
it('should be empty object by default', () => {
|
10
|
-
const model = createModel('http://1.2.3.4', {}, 'foo');
|
11
|
-
expect(model.schema).toEqual({});
|
12
|
-
});
|
13
|
-
|
14
|
-
it('should get the model\'s schema', () => {
|
15
|
-
const schema = {
|
16
|
-
properties: {
|
17
|
-
a: { type: 'string' },
|
18
|
-
},
|
19
|
-
};
|
20
|
-
const model = createModel('http://1.2.3.4', {}, 'foo', schema);
|
21
|
-
expect(model.schema).toEqual(schema);
|
22
|
-
});
|
23
|
-
});
|
24
|
-
|
25
|
-
describe('model.findMany(options)', () => {
|
26
|
-
it('should send GET request', async () => {
|
27
|
-
const schema = {
|
28
|
-
properties: {
|
29
|
-
id: { type: 'integer' },
|
30
|
-
createdAt: { type: 'string', format: 'date-time' },
|
31
|
-
},
|
32
|
-
};
|
33
|
-
const now = new Date();
|
34
|
-
const client = createClient().mockResolvedValue([{
|
35
|
-
id: 1,
|
36
|
-
createdAt: now.toISOString(),
|
37
|
-
}]);
|
38
|
-
const model = createModel('http://1.2.3.4', {}, 'foo', schema);
|
39
|
-
const results = await model.findMany();
|
40
|
-
expect(results).toEqual([{ id: 1, createdAt: now }]);
|
41
|
-
expect(results[0].createdAt instanceof Date).toBe(true);
|
42
|
-
expect(client).toHaveBeenCalledTimes(1);
|
43
|
-
expect(client).toHaveBeenCalledWith('/foo');
|
44
|
-
});
|
45
|
-
});
|
46
|
-
|
47
|
-
describe('model.findById(id, options)', () => {
|
48
|
-
it('should send GET request', async () => {
|
49
|
-
const client = createClient().mockResolvedValue({});
|
50
|
-
const model = createModel('http://1.2.3.4', {}, 'foo');
|
51
|
-
expect(await model.findById(1)).toEqual({});
|
52
|
-
expect(client).toHaveBeenCalledTimes(1);
|
53
|
-
expect(client).toHaveBeenCalledWith('/foo/1');
|
54
|
-
});
|
55
|
-
});
|
56
|
-
|
57
|
-
describe('model.create(options)', () => {
|
58
|
-
it('should send POST request', async () => {
|
59
|
-
const client = createClient().mockResolvedValue({});
|
60
|
-
const model = createModel('http://1.2.3.4', {}, 'foo');
|
61
|
-
expect(await model.create({ data: { ok: true } })).toEqual({});
|
62
|
-
expect(client).toHaveBeenCalledTimes(1);
|
63
|
-
expect(client).toHaveBeenCalledWith('/foo', {
|
64
|
-
body: { data: { ok: true } },
|
65
|
-
method: 'POST',
|
66
|
-
});
|
67
|
-
});
|
68
|
-
});
|
69
|
-
|
70
|
-
describe('model.update(options)', () => {
|
71
|
-
it('should send POST request', async () => {
|
72
|
-
const client = createClient().mockResolvedValue({});
|
73
|
-
const model = createModel('http://1.2.3.4', {}, 'foo');
|
74
|
-
expect(await model.update({ where: { id: 1 }, data: { ok: true } })).toEqual({});
|
75
|
-
expect(client).toHaveBeenCalledTimes(1);
|
76
|
-
expect(client).toHaveBeenCalledWith('/foo/1', {
|
77
|
-
body: { where: { id: 1 }, data: { ok: true } },
|
78
|
-
method: 'PUT',
|
79
|
-
});
|
80
|
-
});
|
81
|
-
});
|
82
|
-
|
83
|
-
describe('model.upsert(options)', () => {
|
84
|
-
it('should send POST request when new row', async () => {
|
85
|
-
const client = createClient().mockResolvedValue({});
|
86
|
-
const model = createModel('http://1.2.3.4', {}, 'foo');
|
87
|
-
const result = await model.upsert({
|
88
|
-
where: {},
|
89
|
-
create: { ok: true },
|
90
|
-
});
|
91
|
-
expect(result).toEqual({});
|
92
|
-
expect(client).toHaveBeenCalledTimes(1);
|
93
|
-
expect(client).toHaveBeenCalledWith('/foo', {
|
94
|
-
body: { data: { ok: true } },
|
95
|
-
method: 'POST',
|
96
|
-
});
|
97
|
-
});
|
98
|
-
|
99
|
-
it('should send PUT request when existing row', async () => {
|
100
|
-
const client = createClient().mockResolvedValue({});
|
101
|
-
const model = createModel('http://1.2.3.4', {}, 'foo');
|
102
|
-
const result = await model.upsert({
|
103
|
-
where: { id: 1 },
|
104
|
-
update: { ok: true },
|
105
|
-
});
|
106
|
-
expect(result).toEqual({});
|
107
|
-
expect(client).toHaveBeenCalledTimes(1);
|
108
|
-
expect(client).toHaveBeenCalledWith('/foo/1', {
|
109
|
-
body: {
|
110
|
-
where: { id: 1 },
|
111
|
-
data: { ok: true },
|
112
|
-
},
|
113
|
-
method: 'PUT',
|
114
|
-
});
|
115
|
-
});
|
116
|
-
});
|
117
|
-
|
118
|
-
describe('model.delete(id)', () => {
|
119
|
-
it('should send POST request', async () => {
|
120
|
-
const client = createClient().mockResolvedValue({});
|
121
|
-
const model = createModel('http://1.2.3.4', {}, 'foo');
|
122
|
-
expect(await model.delete(1)).toEqual({});
|
123
|
-
expect(client).toHaveBeenCalledTimes(1);
|
124
|
-
expect(client).toHaveBeenCalledWith('/foo/1', {
|
125
|
-
method: 'DELETE',
|
126
|
-
});
|
127
|
-
});
|
128
|
-
});
|
129
|
-
|
130
|
-
describe('model.validateAttr(key, value)', () => {
|
131
|
-
it('should not validate when no schema', () => {
|
132
|
-
const model = createModel('http://1.2.3.4', {}, 'foo');
|
133
|
-
expect(model.validateAttr('a', 1)).toBeUndefined();
|
134
|
-
});
|
135
|
-
|
136
|
-
it('should validate text when required', () => {
|
137
|
-
const schema = {
|
138
|
-
properties: {
|
139
|
-
a: { type: 'string' },
|
140
|
-
},
|
141
|
-
};
|
142
|
-
const model = createModel('http://1.2.3.4', {}, 'foo', schema);
|
143
|
-
expect(model.validateAttr('a', '')).toBe('Field is required');
|
144
|
-
});
|
145
|
-
|
146
|
-
it('should validate number when required', () => {
|
147
|
-
const schema = {
|
148
|
-
properties: {
|
149
|
-
a: { type: 'integer', required: true },
|
150
|
-
},
|
151
|
-
};
|
152
|
-
const model = createModel('http://1.2.3.4', {}, 'foo', schema);
|
153
|
-
expect(model.validateAttr('a', 'foo')).toBe('Invalid number format');
|
154
|
-
});
|
155
|
-
|
156
|
-
it('should validate enum', () => {
|
157
|
-
const schema = {
|
158
|
-
properties: {
|
159
|
-
a: { type: 'integer', enum: [1, 2, 3] },
|
160
|
-
},
|
161
|
-
};
|
162
|
-
const model = createModel('http://1.2.3.4', {}, 'foo', schema);
|
163
|
-
expect(model.validateAttr('a', 'foo')).toBe('foo is not one of: 1,2,3');
|
164
|
-
});
|
165
|
-
|
166
|
-
it('should allow empty enum when not required', () => {
|
167
|
-
const schema = {
|
168
|
-
properties: {
|
169
|
-
a: { type: ['integer', 'null'], enum: [1, 2, 3] },
|
170
|
-
},
|
171
|
-
};
|
172
|
-
const model = createModel('http://1.2.3.4', {}, 'foo', schema);
|
173
|
-
expect(model.validateAttr('a', null)).toBeUndefined();
|
174
|
-
expect(model.validateAttr('a', undefined)).toBeUndefined();
|
175
|
-
expect(model.validateAttr('a', '')).toBeUndefined();
|
176
|
-
});
|
177
|
-
});
|
178
|
-
|
179
|
-
describe('model.validate(attributes)', () => {
|
180
|
-
it('should not validate when no schema', () => {
|
181
|
-
const model = createModel('http://1.2.3.4', {}, 'foo');
|
182
|
-
expect(model.validate({ a: 1 })).toEqual({});
|
183
|
-
});
|
184
|
-
|
185
|
-
it('should validate when schema present', () => {
|
186
|
-
const schema = {
|
187
|
-
properties: {
|
188
|
-
a: { type: 'string' },
|
189
|
-
b: { type: 'integer' },
|
190
|
-
},
|
191
|
-
};
|
192
|
-
const model = createModel('http://1.2.3.4', {}, 'foo', schema);
|
193
|
-
expect(model.validate({ a: '', b: 1 })).toEqual({ a: 'Field is required' });
|
194
|
-
});
|
195
|
-
|
196
|
-
it('should validate number when required', () => {
|
197
|
-
const schema = {
|
198
|
-
properties: {
|
199
|
-
a: { type: 'integer' },
|
200
|
-
},
|
201
|
-
};
|
202
|
-
const model = createModel('http://1.2.3.4', {}, 'foo', schema);
|
203
|
-
expect(model.validateAttr('a', 'foo')).toBe('Invalid number format');
|
204
|
-
});
|
205
|
-
|
206
|
-
it('should validate enum', () => {
|
207
|
-
const schema = {
|
208
|
-
properties: {
|
209
|
-
a: { type: 'integer', enum: [1, 2, 3] },
|
210
|
-
},
|
211
|
-
};
|
212
|
-
const model = createModel('http://1.2.3.4', {}, 'foo', schema);
|
213
|
-
expect(model.validateAttr('a', 'foo')).toBe('foo is not one of: 1,2,3');
|
214
|
-
});
|
215
|
-
});
|
package/lib/team.js
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
import { createModels, extendSchemaDefinitions } from './model';
|
2
|
-
import currencies from './currencies';
|
3
|
-
import roles from './roles';
|
4
|
-
import schema from '../schemas/team.json';
|
5
|
-
|
6
|
-
const extended = {
|
7
|
-
Country: {
|
8
|
-
plural: 'countries',
|
9
|
-
},
|
10
|
-
Contract: {
|
11
|
-
inputProps: [
|
12
|
-
'uid',
|
13
|
-
'countryCode',
|
14
|
-
'currency',
|
15
|
-
'isEmployment',
|
16
|
-
'feeBasis',
|
17
|
-
'feeAmount',
|
18
|
-
'hoursPerWeek',
|
19
|
-
'start',
|
20
|
-
'end',
|
21
|
-
],
|
22
|
-
properties: {
|
23
|
-
countryCode: {
|
24
|
-
enum: ['BR', 'CL', 'CO', 'MX', 'PE'],
|
25
|
-
},
|
26
|
-
currency: {
|
27
|
-
enum: currencies,
|
28
|
-
},
|
29
|
-
},
|
30
|
-
},
|
31
|
-
Gig: {
|
32
|
-
inputProps: [
|
33
|
-
// 'contract',
|
34
|
-
'cohortId',
|
35
|
-
'uid',
|
36
|
-
'role',
|
37
|
-
'hoursPerWeek',
|
38
|
-
'start',
|
39
|
-
'end',
|
40
|
-
],
|
41
|
-
properties: {
|
42
|
-
role: {
|
43
|
-
enum: roles,
|
44
|
-
},
|
45
|
-
},
|
46
|
-
},
|
47
|
-
};
|
48
|
-
|
49
|
-
export const createAPI = (url, state) => createModels(url, state, {
|
50
|
-
...schema,
|
51
|
-
definitions: extendSchemaDefinitions(schema, extended),
|
52
|
-
});
|
package/schemas/team.json
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
3
|
-
"definitions": {
|
4
|
-
"Country": {
|
5
|
-
"type": "object",
|
6
|
-
"properties": {
|
7
|
-
"code": {
|
8
|
-
"type": "string"
|
9
|
-
},
|
10
|
-
"name": {
|
11
|
-
"type": "string"
|
12
|
-
},
|
13
|
-
"contracts": {
|
14
|
-
"type": "array",
|
15
|
-
"items": {
|
16
|
-
"$ref": "#/definitions/Contract"
|
17
|
-
}
|
18
|
-
}
|
19
|
-
}
|
20
|
-
},
|
21
|
-
"Contract": {
|
22
|
-
"type": "object",
|
23
|
-
"properties": {
|
24
|
-
"id": {
|
25
|
-
"type": "integer"
|
26
|
-
},
|
27
|
-
"createdAt": {
|
28
|
-
"type": "string",
|
29
|
-
"format": "date-time"
|
30
|
-
},
|
31
|
-
"updatedAt": {
|
32
|
-
"type": "string",
|
33
|
-
"format": "date-time"
|
34
|
-
},
|
35
|
-
"createdBy": {
|
36
|
-
"type": "string"
|
37
|
-
},
|
38
|
-
"uid": {
|
39
|
-
"type": "string"
|
40
|
-
},
|
41
|
-
"isEmployment": {
|
42
|
-
"type": "boolean"
|
43
|
-
},
|
44
|
-
"currency": {
|
45
|
-
"type": "string"
|
46
|
-
},
|
47
|
-
"feeBasis": {
|
48
|
-
"type": "string",
|
49
|
-
"enum": [
|
50
|
-
"HOURLY",
|
51
|
-
"MONTHLY"
|
52
|
-
]
|
53
|
-
},
|
54
|
-
"feeAmount": {
|
55
|
-
"type": "integer"
|
56
|
-
},
|
57
|
-
"hoursPerWeek": {
|
58
|
-
"type": "integer"
|
59
|
-
},
|
60
|
-
"start": {
|
61
|
-
"type": "string",
|
62
|
-
"format": "date-time"
|
63
|
-
},
|
64
|
-
"end": {
|
65
|
-
"type": [
|
66
|
-
"string",
|
67
|
-
"null"
|
68
|
-
],
|
69
|
-
"format": "date-time"
|
70
|
-
},
|
71
|
-
"country": {
|
72
|
-
"$ref": "#/definitions/Country"
|
73
|
-
},
|
74
|
-
"gigs": {
|
75
|
-
"type": "array",
|
76
|
-
"items": {
|
77
|
-
"$ref": "#/definitions/Gig"
|
78
|
-
}
|
79
|
-
}
|
80
|
-
}
|
81
|
-
},
|
82
|
-
"Gig": {
|
83
|
-
"type": "object",
|
84
|
-
"properties": {
|
85
|
-
"id": {
|
86
|
-
"type": "integer"
|
87
|
-
},
|
88
|
-
"createdAt": {
|
89
|
-
"type": "string",
|
90
|
-
"format": "date-time"
|
91
|
-
},
|
92
|
-
"updatedAt": {
|
93
|
-
"type": "string",
|
94
|
-
"format": "date-time"
|
95
|
-
},
|
96
|
-
"createdBy": {
|
97
|
-
"type": "string"
|
98
|
-
},
|
99
|
-
"role": {
|
100
|
-
"type": "string",
|
101
|
-
"enum": [
|
102
|
-
"bm",
|
103
|
-
"pdc",
|
104
|
-
"js",
|
105
|
-
"ux"
|
106
|
-
]
|
107
|
-
},
|
108
|
-
"hoursPerWeek": {
|
109
|
-
"type": "integer"
|
110
|
-
},
|
111
|
-
"start": {
|
112
|
-
"type": "string",
|
113
|
-
"format": "date-time"
|
114
|
-
},
|
115
|
-
"end": {
|
116
|
-
"type": [
|
117
|
-
"string",
|
118
|
-
"null"
|
119
|
-
],
|
120
|
-
"format": "date-time"
|
121
|
-
},
|
122
|
-
"uid": {
|
123
|
-
"type": "string"
|
124
|
-
},
|
125
|
-
"cohortId": {
|
126
|
-
"type": "integer"
|
127
|
-
},
|
128
|
-
"contract": {
|
129
|
-
"$ref": "#/definitions/Contract"
|
130
|
-
}
|
131
|
-
}
|
132
|
-
}
|
133
|
-
},
|
134
|
-
"type": "object",
|
135
|
-
"properties": {
|
136
|
-
"country": {
|
137
|
-
"$ref": "#/definitions/Country"
|
138
|
-
},
|
139
|
-
"contract": {
|
140
|
-
"$ref": "#/definitions/Contract"
|
141
|
-
},
|
142
|
-
"gig": {
|
143
|
-
"$ref": "#/definitions/Gig"
|
144
|
-
}
|
145
|
-
}
|
146
|
-
}
|