@@ -12,7 +12,7 @@ let lib;
12
12
chai . expect ( ) ;
13
13
chai . use ( chaiAsPromised ) ;
14
14
15
- describe ( 'After contructing a new instance of OpenMRS' , ( ) => {
15
+ describe ( 'After contructing a new instance of OpenMRS with no constructor parameters ' , ( ) => {
16
16
before ( ( ) => {
17
17
lib = new OpenMRS ( ) ;
18
18
} ) ;
@@ -96,3 +96,149 @@ describe('After contructing a new instance of OpenMRS', () => {
96
96
} ) ;
97
97
} ) ;
98
98
} ) ;
99
+
100
+ describe ( 'Contructing a new instance of OpenMRS with the full URL constructor parameter' , ( ) => {
101
+ before ( ( ) => {
102
+ lib = new OpenMRS ( 'http://localhost:8080/openmrs/module/webservices/rest/swagger.json' ) ;
103
+ } ) ;
104
+
105
+ describe ( 'and logging in' , ( ) => {
106
+ beforeEach ( ( ) => {
107
+ fauxJax . install ( ) ;
108
+ } ) ;
109
+
110
+ afterEach ( ( ) => {
111
+ fauxJax . restore ( ) ;
112
+ } ) ;
113
+
114
+ it ( 'should succeed with just the user and password' , ( ) => {
115
+ fauxJax . on ( 'request' , ( req ) => {
116
+ req . respond ( 200 , {
117
+ 'Content-Type' : 'application/json' ,
118
+ } , JSON . stringify ( swaggerSpec ) ) ;
119
+ } ) ;
120
+
121
+ const deferred = lib . login ( 'admin' , 'Admin123' ) ;
122
+
123
+ return expect ( deferred ) . to . eventually . be . fulfilled ;
124
+ } ) ;
125
+ } ) ;
126
+ } ) ;
127
+
128
+ describe ( 'Contructing a new instance of OpenMRS with the base URL and protocol' , ( ) => {
129
+ before ( ( ) => {
130
+ lib = new OpenMRS ( 'http://localhost:8080/openmrs/module/webservices/rest/swagger.json' ) ;
131
+ } ) ;
132
+
133
+ describe ( 'and logging in' , ( ) => {
134
+ beforeEach ( ( ) => {
135
+ fauxJax . install ( ) ;
136
+ } ) ;
137
+
138
+ afterEach ( ( ) => {
139
+ fauxJax . restore ( ) ;
140
+ } ) ;
141
+
142
+ it ( 'should succeed with just the user and password' , ( ) => {
143
+ fauxJax . on ( 'request' , ( req ) => {
144
+ req . respond ( 200 , {
145
+ 'Content-Type' : 'application/json' ,
146
+ } , JSON . stringify ( swaggerSpec ) ) ;
147
+ } ) ;
148
+
149
+ const deferred = lib . login ( 'admin' , 'Admin123' ) ;
150
+
151
+ return expect ( deferred ) . to . eventually . be . fulfilled ;
152
+ } ) ;
153
+ } ) ;
154
+ } ) ;
155
+
156
+ describe ( 'Contructing a new instance of OpenMRS with the full URL without protocol' , ( ) => {
157
+ before ( ( ) => {
158
+ lib = new OpenMRS ( 'localhost:8080/openmrs/module/webservices/rest/swagger.json' ) ;
159
+ } ) ;
160
+
161
+ describe ( 'and logging in' , ( ) => {
162
+ beforeEach ( ( ) => {
163
+ fauxJax . install ( ) ;
164
+ } ) ;
165
+
166
+ afterEach ( ( ) => {
167
+ fauxJax . restore ( ) ;
168
+ } ) ;
169
+
170
+ it ( 'should succeed with just the user and password' , ( ) => {
171
+ fauxJax . on ( 'request' , ( req ) => {
172
+ req . respond ( 200 , {
173
+ 'Content-Type' : 'application/json' ,
174
+ } , JSON . stringify ( swaggerSpec ) ) ;
175
+ } ) ;
176
+
177
+ const deferred = lib . login ( 'admin' , 'Admin123' ) ;
178
+
179
+ return expect ( deferred ) . to . eventually . be . fulfilled ;
180
+ } ) ;
181
+ } ) ;
182
+ } ) ;
183
+
184
+ describe ( 'Contructing a new instance of OpenMRS with the base URL without protocol' , ( ) => {
185
+ before ( ( ) => {
186
+ lib = new OpenMRS ( 'localhost:8080/openmrs' ) ;
187
+ } ) ;
188
+
189
+ describe ( 'and logging in' , ( ) => {
190
+ beforeEach ( ( ) => {
191
+ fauxJax . install ( ) ;
192
+ } ) ;
193
+
194
+ afterEach ( ( ) => {
195
+ fauxJax . restore ( ) ;
196
+ } ) ;
197
+
198
+ it ( 'should succeed with just the user and password' , ( ) => {
199
+ fauxJax . on ( 'request' , ( req ) => {
200
+ req . respond ( 200 , {
201
+ 'Content-Type' : 'application/json' ,
202
+ } , JSON . stringify ( swaggerSpec ) ) ;
203
+ } ) ;
204
+
205
+ const deferred = lib . login ( 'admin' , 'Admin123' ) ;
206
+
207
+ return expect ( deferred ) . to . eventually . be . fulfilled ;
208
+ } ) ;
209
+ } ) ;
210
+ } ) ;
211
+
212
+ describe ( 'Contructing a new instance of OpenMRS with the config object' , ( ) => {
213
+ before ( ( ) => {
214
+ const config = {
215
+ user : 'admin' ,
216
+ pass : 'Admin123' ,
217
+ url : 'localhost:8080/openmrs' ,
218
+ } ;
219
+
220
+ lib = new OpenMRS ( config ) ;
221
+ } ) ;
222
+
223
+ describe ( 'and logging in' , ( ) => {
224
+ beforeEach ( ( ) => {
225
+ fauxJax . install ( ) ;
226
+ } ) ;
227
+
228
+ afterEach ( ( ) => {
229
+ fauxJax . restore ( ) ;
230
+ } ) ;
231
+
232
+ it ( 'should succeed with no parameters' , ( ) => {
233
+ fauxJax . on ( 'request' , ( req ) => {
234
+ req . respond ( 200 , {
235
+ 'Content-Type' : 'application/json' ,
236
+ } , JSON . stringify ( swaggerSpec ) ) ;
237
+ } ) ;
238
+
239
+ const deferred = lib . login ( ) ;
240
+
241
+ return expect ( deferred ) . to . eventually . be . fulfilled ;
242
+ } ) ;
243
+ } ) ;
244
+ } ) ;
0 commit comments