| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 12:12:46 -08:00
										 |  |  | import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; | 
					
						
							| 
									
										
										
										
											2017-12-17 15:10:54 -08:00
										 |  |  | import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options'; | 
					
						
							|  |  |  | import {RequestMethod} from '@angular/http/src/enums'; | 
					
						
							|  |  |  | import {Headers} from '@angular/http/src/headers'; | 
					
						
							| 
									
										
										
										
											2015-06-12 21:50:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 14:42:55 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-12 21:50:19 -07:00
										 |  |  |   describe('BaseRequestOptions', () => { | 
					
						
							|  |  |  |     it('should create a new object when calling merge', () => { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |       const options1 = new BaseRequestOptions(); | 
					
						
							|  |  |  |       const options2 = options1.merge(new RequestOptions({method: RequestMethod.Delete})); | 
					
						
							| 
									
										
										
										
											2015-06-12 21:50:19 -07:00
										 |  |  |       expect(options2).not.toBe(options1); | 
					
						
							| 
									
										
										
										
											2015-12-03 22:44:14 +01:00
										 |  |  |       expect(options2.method).toBe(RequestMethod.Delete); | 
					
						
							| 
									
										
										
										
											2015-06-12 21:50:19 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should retain previously merged values when merging again', () => { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |       const options1 = new BaseRequestOptions(); | 
					
						
							|  |  |  |       const options2 = options1.merge(new RequestOptions({method: RequestMethod.Delete})); | 
					
						
							| 
									
										
										
										
											2015-12-03 22:44:14 +01:00
										 |  |  |       expect(options2.method).toBe(RequestMethod.Delete); | 
					
						
							| 
									
										
										
										
											2015-06-12 21:50:19 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-12-10 02:38:29 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should accept search params as object', () => { | 
					
						
							|  |  |  |       const params = {a: 1, b: 'text', c: [1, 2, '3']}; | 
					
						
							|  |  |  |       const options = new RequestOptions({params}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(options.params.paramsMap.size).toBe(3); | 
					
						
							|  |  |  |       expect(options.params.paramsMap.get('a')).toEqual(['1']); | 
					
						
							|  |  |  |       expect(options.params.paramsMap.get('b')).toEqual(['text']); | 
					
						
							|  |  |  |       expect(options.params.paramsMap.get('c')).toEqual(['1', '2', '3']); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should merge search params as object', () => { | 
					
						
							|  |  |  |       const options1 = new BaseRequestOptions(); | 
					
						
							|  |  |  |       const params = {a: 1, b: 'text', c: [1, 2, '3']}; | 
					
						
							|  |  |  |       const options2 = options1.merge(new RequestOptions({params})); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(options2.params.paramsMap.size).toBe(3); | 
					
						
							|  |  |  |       expect(options2.params.paramsMap.get('a')).toEqual(['1']); | 
					
						
							|  |  |  |       expect(options2.params.paramsMap.get('b')).toEqual(['text']); | 
					
						
							|  |  |  |       expect(options2.params.paramsMap.get('c')).toEqual(['1', '2', '3']); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-12-12 22:16:34 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should create a new headers object when calling merge', () => { | 
					
						
							|  |  |  |       const options1 = new RequestOptions({headers: new Headers()}); | 
					
						
							|  |  |  |       const options2 = options1.merge(); | 
					
						
							|  |  |  |       expect(options2.headers).not.toBe(options1.headers); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-06-12 21:50:19 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |