-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
189 lines (158 loc) · 6.02 KB
/
test.js
File metadata and controls
189 lines (158 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// (function() {
// 'use strict';
// describe('GroupService', function() {
// var service, $httpBackend, handler, groupData, errorMessage;
// // Configure module that contains the controller being tested
// beforeEach(module('eggercise'));
// beforeEach(inject(function (_$httpBackend_, _GroupService_) {
// $httpBackend = _$httpBackend_;
// service = _GroupService_;
// groupData = [];
// // Define an object with functions to handle success and error for our API calls
// // These functions simulate the functions written in controllers when a service is called
// handler = {
// success: function(group) {
// groupData.push(group);
// },
// error: function(err) {
// errorMessage = err;
// }
// };
// // Use the Jasmine spyOn method to setup a callback using our handler mock object
// spyOn(handler, 'success').and.callThrough();
// spyOn(handler, 'error').and.callThrough();
// }));
// //Test for showAllGroups()
// it('should show the list of groups', function () {
// var id = '56662b84c6e3a5280b1209aa';
// var existingGroup = {
// _id : id,
// name : 'New Group',
// email : 'new3@email.com',
// bet : 25,
// start: '2015-12-01T08:00:00Z',
// end: '2015-12-31T08:00:00Z',
// _creator : '565f912726c74d251d0a7b03'
// };
// // expect(200);
// var response = service.showAllGroups()
// .then(function () {
// console.log('successful');
// })
// .catch(function (err) {
// console.log('Error!!!', err);
// });
// expect(response).toBeTruthy();
// // $httpBackend.flush();
// })
// //Test to showGroup()
// it('should show one group', function () {
// var id = '56662b84c6e3a5280b1209aa';
// var existingGroup = {
// _id : id,
// name : 'Tiger Group',
// email : 'tiger@mail.com',
// bet : 500,
// start : '2015-12-31T09:00:00Z',
// end : '2016-1-31T09:00:00Z',
// _creator : '565f912726c74d251d0a7b03'
// };
// var response = service.showGroup()
// .then(function () {
// console.log('successful');
// })
// .catch(function (err) {
// console.log('Error: ', err);
// });
// expect(response).toBeTruthy();
// })
// //Test for createGroup()
// it('should create a new group', function () {
// // expect(200);
// var createG = service.createGroup()
// .then(function () {
// console.log('successful');
// })
// .catch(function (err) {
// console.log('Error!!!', err);
// });
// expect(createG).toBeTruthy();
// // $httpBackend.flush();
// })
// it('should delete a group', function() {
// var id = '56662b84c6e3a5280b1209aa';
// var existingGroup = {
// _id : id,
// name : 'New Group',
// email : 'new3@email.com',
// bet : 25,
// start: '2015-12-01T08:00:00Z',
// end: '2015-12-31T08:00:00Z',
// _creator : '565f912726c74d251d0a7b03'
// };
// // Use the httpBackend mock service to capture the call to our API and return the data we specify in the response variable
// $httpBackend.whenPOST(/delete\/(\S+)$/)
// .respond(function(method, url, params) {
// // Retrieve the asked id as integer ...
// var re = /.*\/delete\/(\S+)$/;
// var groupId = url.replace(re, '$1');
// if (groupId === existingGroup._id) {
// return [200, existingGroup];
// } else {
// return [404, { message: 'Not Found' }];
// }
// });
// // setup the service to use the success and error handler functions we defined in the beforeEach block.
// service.deleteGroup(id).then(handler.success, handler.error);
// // execute the HTTP API call
// $httpBackend.flush();
// // tests the results
// // expect(handler.success).toHaveBeenCalled();
// expect(groupData[0]._id).toEqual(existingGroup._id);
// expect(handler.error).not.toHaveBeenCalled();
// expect(errorMessage).toBeUndefined();
// });
// it('should update a group', function() {
// var id = '56662b84c6e3a5280b1209aa';
// var existingGroup = {
// _id : id,
// name : 'New Group',
// email : 'new3@email.com',
// bet : 25,
// start: '2015-12-01T08:00:00Z',
// end: '2015-12-31T08:00:00Z',
// _creator : '565f912726c74d251d0a7b03'
// };
// var updatedGroup = {
// _id : id,
// name : 'New Updated Group',
// email : 'new5@email.com',
// bet : 30,
// start: '2015-12-15T08:00:00Z',
// end: '2015-12-25T08:00:00Z',
// _creator : '565f912726c74d251d0a7b03'
// }
// // Use the httpBackend mock service to capture the call to our API and return the data we specify in the response variable
// $httpBackend.whenPOST(/update\/(\S+)$/)
// .respond(function(method, url, params) {
// // Retrieve the asked id as integer ...
// var re = /.*\/update\/(\S+)$/;
// var groupId = url.replace(re, '$1');
// if (groupId === existingGroup._id) {
// return [200, updatedGroup];
// } else {
// return [404, { message: 'Not Found' }];
// }
// });
// // setup the service to use the success and error handler functions we defined in the beforeEach block.
// service.updateGroup(id).then(handler.success, handler.error);
// // execute the HTTP API call
// $httpBackend.flush();
// // tests the results
// // expect(handler.success).toHaveBeenCalled();
// expect(groupData[0]._id).toEqual(updatedGroup._id);
// expect(handler.error).not.toHaveBeenCalled();
// expect(errorMessage).toBeUndefined();
// });
// });
// })();