2016-06-23 12:47:54 -04: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
|
|
|
|
*/
|
|
|
|
|
2016-09-27 20:12:25 -04:00
|
|
|
import {describe, expect, it} from '@angular/core/testing/testing_internal';
|
2016-04-28 20:50:03 -04:00
|
|
|
import {BaseRequestOptions, RequestOptions} from '../src/base_request_options';
|
|
|
|
import {RequestMethod} from '../src/enums';
|
2016-12-12 14:16:34 -05:00
|
|
|
import {Headers} from '../src/headers';
|
2015-06-13 00:50:19 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('BaseRequestOptions', () => {
|
|
|
|
it('should create a new object when calling merge', () => {
|
2016-11-12 08:08:58 -05:00
|
|
|
const options1 = new BaseRequestOptions();
|
|
|
|
const options2 = options1.merge(new RequestOptions({method: RequestMethod.Delete}));
|
2015-06-13 00:50:19 -04:00
|
|
|
expect(options2).not.toBe(options1);
|
2015-12-03 16:44:14 -05:00
|
|
|
expect(options2.method).toBe(RequestMethod.Delete);
|
2015-06-13 00:50:19 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should retain previously merged values when merging again', () => {
|
2016-11-12 08:08:58 -05:00
|
|
|
const options1 = new BaseRequestOptions();
|
|
|
|
const options2 = options1.merge(new RequestOptions({method: RequestMethod.Delete}));
|
2015-12-03 16:44:14 -05:00
|
|
|
expect(options2.method).toBe(RequestMethod.Delete);
|
2015-06-13 00:50:19 -04:00
|
|
|
});
|
2016-12-09 18:38:29 -05: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 14:16:34 -05: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-13 00:50:19 -04:00
|
|
|
});
|
|
|
|
}
|