|
@@ -0,0 +1,229 @@
|
|
1
|
+/**
|
|
2
|
+ * Created by robin on 12/11/16.
|
|
3
|
+ */
|
|
4
|
+
|
|
5
|
+describe('lu-webapi-crud-business factory', function() {
|
|
6
|
+ var luWebApiCrudBusiness;
|
|
7
|
+ var fakeDataAccess;
|
|
8
|
+ var $q;
|
|
9
|
+ var $rootScope;
|
|
10
|
+
|
|
11
|
+ // Before each test load our api.users module
|
|
12
|
+ beforeEach(angular.mock.module('luticate2Utils'));
|
|
13
|
+
|
|
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
|
+ }));
|
|
20
|
+
|
|
21
|
+ beforeEach(function () {
|
|
22
|
+ fakeDataAccess = {
|
|
23
|
+ getSingleById: function(id, luBusyGroups) {
|
|
24
|
+ var deferred = $q.defer();
|
|
25
|
+ if (id == 1) {
|
|
26
|
+ deferred.resolve({
|
|
27
|
+ id: id,
|
|
28
|
+ name: "Test."
|
|
29
|
+ });
|
|
30
|
+ }
|
|
31
|
+ else if (id == 2) {
|
|
32
|
+ deferred.resolve({
|
|
33
|
+ id: id,
|
|
34
|
+ name: "Test.2",
|
|
35
|
+ obj: {
|
|
36
|
+ value: 4242
|
|
37
|
+ }
|
|
38
|
+ });
|
|
39
|
+ }
|
|
40
|
+ return deferred.promise;
|
|
41
|
+ },
|
|
42
|
+ getMultiple: function (orderBy, filter, page, perPage, luBusyGroups) {
|
|
43
|
+ var deferred = $q.defer();
|
|
44
|
+ deferred.resolve({
|
|
45
|
+ count: 42,
|
|
46
|
+ data: [{
|
|
47
|
+ id: 1,
|
|
48
|
+ name: "Test.",
|
|
49
|
+ obj: {
|
|
50
|
+ value: 4242
|
|
51
|
+ }
|
|
52
|
+ }, {
|
|
53
|
+ id: 2,
|
|
54
|
+ name: "Test.2",
|
|
55
|
+ obj: {
|
|
56
|
+ anotherValue: 2424
|
|
57
|
+ }
|
|
58
|
+ }]
|
|
59
|
+ });
|
|
60
|
+ return deferred.promise;
|
|
61
|
+ },
|
|
62
|
+ addDbo: function(data, luBusyGroups) {
|
|
63
|
+ return this.getSingleById(1, luBusyGroups);
|
|
64
|
+ },
|
|
65
|
+ editSingleByIdDbo: function(id, data, luBusyGroups) {
|
|
66
|
+ return this.getSingleById(id, luBusyGroups);
|
|
67
|
+ },
|
|
68
|
+ deleteDbo: function(id, luBusyGroups) {
|
|
69
|
+ return this.getSingleById(id, luBusyGroups);
|
|
70
|
+ }
|
|
71
|
+ };
|
|
72
|
+ });
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+ it('should add a dummy function to getSingleById dbo', function()
|
|
76
|
+ {
|
|
77
|
+ var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
|
78
|
+ business.defaultDbo = {
|
|
79
|
+ id: null,
|
|
80
|
+ name: "",
|
|
81
|
+ dummyFunction: function () {
|
|
82
|
+ return '_' + this.name + '_';
|
|
83
|
+ }
|
|
84
|
+ };
|
|
85
|
+
|
|
86
|
+ var id = 1;
|
|
87
|
+ business.getSingleById(id).then(function (data) {
|
|
88
|
+ expect(data.id).toEqual(id);
|
|
89
|
+ expect(data.name).toEqual("Test.");
|
|
90
|
+ expect(data.dummyFunction).not.toBeNull();
|
|
91
|
+ expect(data.dummyFunction()).toEqual("_Test._");
|
|
92
|
+ }, function (error) {
|
|
93
|
+ expect(error).toBeNull();
|
|
94
|
+ });
|
|
95
|
+ $rootScope.$digest();
|
|
96
|
+ });
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+ it('should test complex extend', function()
|
|
100
|
+ {
|
|
101
|
+ var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
|
102
|
+ business.defaultDbo = {
|
|
103
|
+ id: null,
|
|
104
|
+ name: "",
|
|
105
|
+ obj: {
|
|
106
|
+ value: 42,
|
|
107
|
+ anotherValue: 24
|
|
108
|
+ }
|
|
109
|
+ };
|
|
110
|
+
|
|
111
|
+ var id = 2;
|
|
112
|
+ business.getSingleById(id).then(function (data) {
|
|
113
|
+ expect(data.id).toEqual(id);
|
|
114
|
+ expect(data.name).toEqual("Test.2");
|
|
115
|
+ expect(data.obj).not.toBeNull();
|
|
116
|
+ expect(data.obj.value).toEqual(4242);
|
|
117
|
+ expect(data.obj.anotherValue).toEqual(24);
|
|
118
|
+ }, function (error) {
|
|
119
|
+ expect(error).toBeNull();
|
|
120
|
+ });
|
|
121
|
+ $rootScope.$digest();
|
|
122
|
+ });
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+ it('should add a dummy function to getSingleById dbo', function()
|
|
126
|
+ {
|
|
127
|
+ var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
|
128
|
+ business.defaultDbo = {
|
|
129
|
+ id: null,
|
|
130
|
+ name: "",
|
|
131
|
+ dummyFunction: function () {
|
|
132
|
+ return '_' + this.name + '_';
|
|
133
|
+ }
|
|
134
|
+ };
|
|
135
|
+
|
|
136
|
+ business.getMultiple(null, null, 0, 2).then(function (data) {
|
|
137
|
+ expect(data.count).toEqual(42);
|
|
138
|
+ expect(data.data.length).toEqual(2);
|
|
139
|
+
|
|
140
|
+ var i = 0;
|
|
141
|
+ expect(data.data[i].id).toEqual(1);
|
|
142
|
+ expect(data.data[i].name).toEqual("Test.");
|
|
143
|
+ expect(data.data[i].dummyFunction).not.toBeNull();
|
|
144
|
+ expect(data.data[i].dummyFunction()).toEqual("_Test._");
|
|
145
|
+
|
|
146
|
+ i = 1;
|
|
147
|
+ expect(data.data[i].id).toEqual(2);
|
|
148
|
+ expect(data.data[i].name).toEqual("Test.2");
|
|
149
|
+ expect(data.data[i].dummyFunction).not.toBeNull();
|
|
150
|
+ expect(data.data[i].dummyFunction()).toEqual("_Test.2_");
|
|
151
|
+
|
|
152
|
+ }, function (error) {
|
|
153
|
+ expect(error).toBeNull();
|
|
154
|
+ });
|
|
155
|
+ $rootScope.$digest();
|
|
156
|
+ });
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+ it('should add a dummy function to addDbo dbo', function()
|
|
160
|
+ {
|
|
161
|
+ var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
|
162
|
+ business.defaultDbo = {
|
|
163
|
+ id: null,
|
|
164
|
+ name: "",
|
|
165
|
+ dummyFunction: function () {
|
|
166
|
+ return '_' + this.name + '_';
|
|
167
|
+ }
|
|
168
|
+ };
|
|
169
|
+
|
|
170
|
+ var id = 1;
|
|
171
|
+ business.addDbo(null).then(function (data) {
|
|
172
|
+ expect(data.id).toEqual(id);
|
|
173
|
+ expect(data.name).toEqual("Test.");
|
|
174
|
+ expect(data.dummyFunction).not.toBeNull();
|
|
175
|
+ expect(data.dummyFunction()).toEqual("_Test._");
|
|
176
|
+ }, function (error) {
|
|
177
|
+ expect(error).toBeNull();
|
|
178
|
+ });
|
|
179
|
+ $rootScope.$digest();
|
|
180
|
+ });
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+ it('should add a dummy function to editSingleByIdDbo dbo', function()
|
|
184
|
+ {
|
|
185
|
+ var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
|
186
|
+ business.defaultDbo = {
|
|
187
|
+ id: null,
|
|
188
|
+ name: "",
|
|
189
|
+ dummyFunction: function () {
|
|
190
|
+ return '_' + this.name + '_';
|
|
191
|
+ }
|
|
192
|
+ };
|
|
193
|
+
|
|
194
|
+ var id = 1;
|
|
195
|
+ business.editSingleByIdDbo(id, null).then(function (data) {
|
|
196
|
+ expect(data.id).toEqual(id);
|
|
197
|
+ expect(data.name).toEqual("Test.");
|
|
198
|
+ expect(data.dummyFunction).not.toBeNull();
|
|
199
|
+ expect(data.dummyFunction()).toEqual("_Test._");
|
|
200
|
+ }, function (error) {
|
|
201
|
+ expect(error).toBeNull();
|
|
202
|
+ });
|
|
203
|
+ $rootScope.$digest();
|
|
204
|
+ });
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+ it('should add a dummy function to deleteDbo dbo', function()
|
|
208
|
+ {
|
|
209
|
+ var business = luWebApiCrudBusiness.create(fakeDataAccess);
|
|
210
|
+ business.defaultDbo = {
|
|
211
|
+ id: null,
|
|
212
|
+ name: "",
|
|
213
|
+ dummyFunction: function () {
|
|
214
|
+ return '_' + this.name + '_';
|
|
215
|
+ }
|
|
216
|
+ };
|
|
217
|
+
|
|
218
|
+ var id = 1;
|
|
219
|
+ business.deleteDbo(id, null).then(function (data) {
|
|
220
|
+ expect(data.id).toEqual(id);
|
|
221
|
+ expect(data.name).toEqual("Test.");
|
|
222
|
+ expect(data.dummyFunction).not.toBeNull();
|
|
223
|
+ expect(data.dummyFunction()).toEqual("_Test._");
|
|
224
|
+ }, function (error) {
|
|
225
|
+ expect(error).toBeNull();
|
|
226
|
+ });
|
|
227
|
+ $rootScope.$digest();
|
|
228
|
+ });
|
|
229
|
+});
|