|
@@ -2,26 +2,76 @@
|
2
|
2
|
* Created by robin on 12/11/16.
|
3
|
3
|
*/
|
4
|
4
|
|
5
|
|
-describe('lu-webapi-crud-business factory', function() {
|
6
|
|
- var luWebApiCrudBusiness;
|
|
5
|
+describe('lu-webapi-crud-dataaccess model factory', function() {
|
|
6
|
+ var luWebApiCrudDataAccess;
|
7
|
7
|
var fakeDataAccess;
|
8
|
8
|
var $q;
|
9
|
9
|
var $rootScope;
|
10
|
10
|
|
11
|
|
- // Before each test load our api.users module
|
12
|
11
|
beforeEach(angular.mock.module('luticate2Utils'));
|
13
|
12
|
|
14
|
|
- // Before each test set our injected Users factory (_Users_) to our local Users variable
|
15
|
|
- beforeEach(inject(function(_luWebApiCrudBusiness_, _$q_, _$rootScope_) {
|
16
|
|
- luWebApiCrudBusiness = _luWebApiCrudBusiness_;
|
17
|
|
- $q = _$q_;
|
18
|
|
- $rootScope = _$rootScope_;
|
19
|
|
- }));
|
|
13
|
+ beforeEach(function () {
|
|
14
|
+ module(function ($provide) {
|
|
15
|
+ $provide.value('luWebApiDataAccess', {
|
|
16
|
+ create: function (entry_point) {
|
|
17
|
+ return {
|
|
18
|
+
|
|
19
|
+ get: function (url, dataGet, luBusyGroups) {
|
|
20
|
+ var deferred = $q.defer();
|
|
21
|
+ if (url == '') {
|
|
22
|
+ fakeDataAccess.getMultiple(dataGet.orderBy, dataGet.filter, dataGet.page, dataGet.perPage, deferred);
|
|
23
|
+ }
|
|
24
|
+ else {
|
|
25
|
+ fakeDataAccess.getSingleById(url, deferred);
|
|
26
|
+ }
|
|
27
|
+ // deferred.resolve({
|
|
28
|
+ // get: dataGet,
|
|
29
|
+ // post: null,
|
|
30
|
+ // url: entry_point + url
|
|
31
|
+ // });
|
|
32
|
+ return deferred.promise;
|
|
33
|
+ },
|
|
34
|
+
|
|
35
|
+ post: function (url, dataGet, dataPost, luBusyGroups) {
|
|
36
|
+ var deferred = $q.defer();
|
|
37
|
+ if (url == '') {
|
|
38
|
+ fakeDataAccess.addDbo(dataPost, deferred);
|
|
39
|
+ }
|
|
40
|
+ else {
|
|
41
|
+ fakeDataAccess.editSingleByIdDbo(url, dataPost, deferred);
|
|
42
|
+ }
|
|
43
|
+ deferred.resolve({
|
|
44
|
+ get: dataGet,
|
|
45
|
+ post: dataPost,
|
|
46
|
+ url: entry_point + url
|
|
47
|
+ });
|
|
48
|
+ return deferred.promise;
|
|
49
|
+ },
|
|
50
|
+
|
|
51
|
+ put: function (url, dataGet, dataPost, luBusyGroups) {
|
|
52
|
+ var deferred = $q.defer();
|
|
53
|
+ deferred.resolve({
|
|
54
|
+ get: dataGet,
|
|
55
|
+ post: dataPost,
|
|
56
|
+ url: entry_point + url
|
|
57
|
+ });
|
|
58
|
+ return deferred.promise;
|
|
59
|
+ },
|
|
60
|
+
|
|
61
|
+ delete: function (url, dataGet, dataPost, luBusyGroups) {
|
|
62
|
+ var deferred = $q.defer();
|
|
63
|
+ fakeDataAccess.deleteDbo(url, deferred);
|
|
64
|
+ return deferred.promise;
|
|
65
|
+ }
|
|
66
|
+ }
|
|
67
|
+ }
|
|
68
|
+ });
|
|
69
|
+ });
|
|
70
|
+ });
|
20
|
71
|
|
21
|
72
|
beforeEach(function () {
|
22
|
73
|
fakeDataAccess = {
|
23
|
|
- getSingleById: function(id, luBusyGroups) {
|
24
|
|
- var deferred = $q.defer();
|
|
74
|
+ getSingleById: function(id, deferred) {
|
25
|
75
|
if (id == 1) {
|
26
|
76
|
deferred.resolve({
|
27
|
77
|
id: id,
|
|
@@ -61,43 +111,48 @@ describe('lu-webapi-crud-business factory', function() {
|
61
|
111
|
}
|
62
|
112
|
return deferred.promise;
|
63
|
113
|
},
|
64
|
|
- getMultiple: function (orderBy, filter, page, perPage, luBusyGroups) {
|
65
|
|
- var deferred = $q.defer();
|
|
114
|
+ getMultiple: function (orderBy, filter, page, perPage, deferred) {
|
66
|
115
|
deferred.resolve({
|
67
|
116
|
count: 42,
|
68
|
117
|
data: [{
|
69
|
|
- id: 1,
|
70
|
|
- name: "Test.",
|
71
|
|
- obj: {
|
72
|
|
- value: 4242
|
73
|
|
- }
|
74
|
|
- }, {
|
75
|
|
- id: 2,
|
76
|
|
- name: "Test.2",
|
77
|
|
- obj: {
|
78
|
|
- anotherValue: 2424
|
79
|
|
- }
|
80
|
|
- }]
|
|
118
|
+ id: 1,
|
|
119
|
+ name: "Test.",
|
|
120
|
+ obj: {
|
|
121
|
+ value: 4242
|
|
122
|
+ }
|
|
123
|
+ }, {
|
|
124
|
+ id: 2,
|
|
125
|
+ name: "Test.2",
|
|
126
|
+ obj: {
|
|
127
|
+ anotherValue: 2424
|
|
128
|
+ }
|
|
129
|
+ }]
|
81
|
130
|
});
|
82
|
131
|
return deferred.promise;
|
83
|
132
|
},
|
84
|
|
- addDbo: function(data, luBusyGroups) {
|
85
|
|
- return this.getSingleById(1, luBusyGroups);
|
|
133
|
+ addDbo: function(data, deferred) {
|
|
134
|
+ return this.getSingleById(1, deferred);
|
86
|
135
|
},
|
87
|
|
- editSingleByIdDbo: function(id, data, luBusyGroups) {
|
88
|
|
- return this.getSingleById(id, luBusyGroups);
|
|
136
|
+ editSingleByIdDbo: function(id, data, deferred) {
|
|
137
|
+ return this.getSingleById(id, deferred);
|
89
|
138
|
},
|
90
|
|
- deleteDbo: function(id, luBusyGroups) {
|
91
|
|
- return this.getSingleById(id, luBusyGroups);
|
|
139
|
+ deleteDbo: function(id, deferred) {
|
|
140
|
+ return this.getSingleById(id, deferred);
|
92
|
141
|
}
|
93
|
142
|
};
|
94
|
143
|
});
|
|
144
|
+
|
|
145
|
+ beforeEach(inject(function(_luWebApiCrudDataAccess_, _$q_, _$rootScope_) {
|
|
146
|
+ luWebApiCrudDataAccess = _luWebApiCrudDataAccess_;
|
|
147
|
+ $q = _$q_;
|
|
148
|
+ $rootScope = _$rootScope_;
|
|
149
|
+ }));
|
95
|
150
|
|
96
|
151
|
|
97
|
152
|
it('should add a dummy function to getSingleById dbo', function()
|
98
|
153
|
{
|
99
|
|
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
100
|
|
- business.defaultDbo = {
|
|
154
|
+ var dataAccess = luWebApiCrudDataAccess.create('');
|
|
155
|
+ dataAccess.defaultDbo = {
|
101
|
156
|
id: null,
|
102
|
157
|
name: "",
|
103
|
158
|
dummyFunction: function () {
|
|
@@ -106,7 +161,7 @@ describe('lu-webapi-crud-business factory', function() {
|
106
|
161
|
};
|
107
|
162
|
|
108
|
163
|
var id = 1;
|
109
|
|
- business.getSingleById(id).then(function (data) {
|
|
164
|
+ dataAccess.getSingleById(id).then(function (data) {
|
110
|
165
|
expect(data.id).toEqual(id);
|
111
|
166
|
expect(data.name).toEqual("Test.");
|
112
|
167
|
expect(data.dummyFunction).not.toBeNull();
|
|
@@ -120,8 +175,8 @@ describe('lu-webapi-crud-business factory', function() {
|
120
|
175
|
|
121
|
176
|
it('should test complex extend', function()
|
122
|
177
|
{
|
123
|
|
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
124
|
|
- business.defaultDbo = {
|
|
178
|
+ var dataAccess = luWebApiCrudDataAccess.create('');
|
|
179
|
+ dataAccess.defaultDbo = {
|
125
|
180
|
id: null,
|
126
|
181
|
name: "",
|
127
|
182
|
obj: {
|
|
@@ -131,7 +186,7 @@ describe('lu-webapi-crud-business factory', function() {
|
131
|
186
|
};
|
132
|
187
|
|
133
|
188
|
var id = 2;
|
134
|
|
- business.getSingleById(id).then(function (data) {
|
|
189
|
+ dataAccess.getSingleById(id).then(function (data) {
|
135
|
190
|
expect(data.id).toEqual(id);
|
136
|
191
|
expect(data.name).toEqual("Test.2");
|
137
|
192
|
expect(data.obj).not.toBeNull();
|
|
@@ -146,8 +201,8 @@ describe('lu-webapi-crud-business factory', function() {
|
146
|
201
|
|
147
|
202
|
it('should add a dummy function to getSingleById dbo', function()
|
148
|
203
|
{
|
149
|
|
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
150
|
|
- business.defaultDbo = {
|
|
204
|
+ var dataAccess = luWebApiCrudDataAccess.create('');
|
|
205
|
+ dataAccess.defaultDbo = {
|
151
|
206
|
id: null,
|
152
|
207
|
name: "",
|
153
|
208
|
dummyFunction: function () {
|
|
@@ -155,7 +210,7 @@ describe('lu-webapi-crud-business factory', function() {
|
155
|
210
|
}
|
156
|
211
|
};
|
157
|
212
|
|
158
|
|
- business.getMultiple(null, null, 0, 2).then(function (data) {
|
|
213
|
+ dataAccess.getMultiple(null, null, 0, 2).then(function (data) {
|
159
|
214
|
expect(data.count).toEqual(42);
|
160
|
215
|
expect(data.data.length).toEqual(2);
|
161
|
216
|
|
|
@@ -180,8 +235,8 @@ describe('lu-webapi-crud-business factory', function() {
|
180
|
235
|
|
181
|
236
|
it('should add a dummy function to addDbo dbo', function()
|
182
|
237
|
{
|
183
|
|
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
184
|
|
- business.defaultDbo = {
|
|
238
|
+ var dataAccess = luWebApiCrudDataAccess.create('');
|
|
239
|
+ dataAccess.defaultDbo = {
|
185
|
240
|
id: null,
|
186
|
241
|
name: "",
|
187
|
242
|
dummyFunction: function () {
|
|
@@ -190,7 +245,7 @@ describe('lu-webapi-crud-business factory', function() {
|
190
|
245
|
};
|
191
|
246
|
|
192
|
247
|
var id = 1;
|
193
|
|
- business.addDbo(null).then(function (data) {
|
|
248
|
+ dataAccess.addDbo({}).then(function (data) {
|
194
|
249
|
expect(data.id).toEqual(id);
|
195
|
250
|
expect(data.name).toEqual("Test.");
|
196
|
251
|
expect(data.dummyFunction).not.toBeNull();
|
|
@@ -204,8 +259,8 @@ describe('lu-webapi-crud-business factory', function() {
|
204
|
259
|
|
205
|
260
|
it('should add a dummy function to editSingleByIdDbo dbo', function()
|
206
|
261
|
{
|
207
|
|
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
208
|
|
- business.defaultDbo = {
|
|
262
|
+ var dataAccess = luWebApiCrudDataAccess.create('');
|
|
263
|
+ dataAccess.defaultDbo = {
|
209
|
264
|
id: null,
|
210
|
265
|
name: "",
|
211
|
266
|
dummyFunction: function () {
|
|
@@ -214,7 +269,7 @@ describe('lu-webapi-crud-business factory', function() {
|
214
|
269
|
};
|
215
|
270
|
|
216
|
271
|
var id = 1;
|
217
|
|
- business.editSingleByIdDbo(id, null).then(function (data) {
|
|
272
|
+ dataAccess.editSingleByIdDbo(id, {}).then(function (data) {
|
218
|
273
|
expect(data.id).toEqual(id);
|
219
|
274
|
expect(data.name).toEqual("Test.");
|
220
|
275
|
expect(data.dummyFunction).not.toBeNull();
|
|
@@ -228,8 +283,8 @@ describe('lu-webapi-crud-business factory', function() {
|
228
|
283
|
|
229
|
284
|
it('should add a dummy function to deleteDbo dbo', function()
|
230
|
285
|
{
|
231
|
|
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
232
|
|
- business.defaultDbo = {
|
|
286
|
+ var dataAccess = luWebApiCrudDataAccess.create('');
|
|
287
|
+ dataAccess.defaultDbo = {
|
233
|
288
|
id: null,
|
234
|
289
|
name: "",
|
235
|
290
|
dummyFunction: function () {
|
|
@@ -238,7 +293,7 @@ describe('lu-webapi-crud-business factory', function() {
|
238
|
293
|
};
|
239
|
294
|
|
240
|
295
|
var id = 1;
|
241
|
|
- business.deleteDbo(id, null).then(function (data) {
|
|
296
|
+ dataAccess.deleteDbo(id, null).then(function (data) {
|
242
|
297
|
expect(data.id).toEqual(id);
|
243
|
298
|
expect(data.name).toEqual("Test.");
|
244
|
299
|
expect(data.dummyFunction).not.toBeNull();
|
|
@@ -252,8 +307,8 @@ describe('lu-webapi-crud-business factory', function() {
|
252
|
307
|
|
253
|
308
|
it('should convert createdAt into Date', function()
|
254
|
309
|
{
|
255
|
|
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
256
|
|
- business.defaultDbo = {
|
|
310
|
+ var dataAccess = luWebApiCrudDataAccess.create('');
|
|
311
|
+ dataAccess.defaultDbo = {
|
257
|
312
|
id: null,
|
258
|
313
|
name: "",
|
259
|
314
|
createdAt: null,
|
|
@@ -264,7 +319,7 @@ describe('lu-webapi-crud-business factory', function() {
|
264
|
319
|
};
|
265
|
320
|
|
266
|
321
|
var id = 3;
|
267
|
|
- business.getSingleById(id, null).then(function (data) {
|
|
322
|
+ dataAccess.getSingleById(id, null).then(function (data) {
|
268
|
323
|
expect(data.id).toEqual(id);
|
269
|
324
|
expect(data.name).toEqual("Test.2");
|
270
|
325
|
expect(data.dummyFunction).not.toBeNull();
|
|
@@ -280,8 +335,8 @@ describe('lu-webapi-crud-business factory', function() {
|
280
|
335
|
|
281
|
336
|
it('should convert createdAt and updatedAt into Date', function()
|
282
|
337
|
{
|
283
|
|
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
284
|
|
- business.defaultDbo = {
|
|
338
|
+ var dataAccess = luWebApiCrudDataAccess.create('');
|
|
339
|
+ dataAccess.defaultDbo = {
|
285
|
340
|
id: null,
|
286
|
341
|
name: "",
|
287
|
342
|
createdAt: null,
|
|
@@ -292,7 +347,7 @@ describe('lu-webapi-crud-business factory', function() {
|
292
|
347
|
};
|
293
|
348
|
|
294
|
349
|
var id = 4;
|
295
|
|
- business.getSingleById(id, null).then(function (data) {
|
|
350
|
+ dataAccess.getSingleById(id, null).then(function (data) {
|
296
|
351
|
expect(data.id).toEqual(id);
|
297
|
352
|
expect(data.name).toEqual("Test.2");
|
298
|
353
|
expect(data.dummyFunction).not.toBeNull();
|