@@ -3,7 +3,7 @@ import {StreamsService} from './streams.service';
3
3
import { Observable } from 'rxjs/Observable' ;
4
4
import { HttpUtils } from '../shared/support/http.utils' ;
5
5
import { StreamDefinition } from './model/stream-definition' ;
6
- import { Headers , RequestOptions } from '@angular/http' ;
6
+ import { Headers , RequestOptions , URLSearchParams } from '@angular/http' ;
7
7
import { MockResponse } from '../tests/mocks/response' ;
8
8
import { STREAM_DEFINITIONS } from '../tests/mocks/mock-data' ;
9
9
@@ -28,56 +28,62 @@ describe('StreamsService', () => {
28
28
expect ( this . streamsService . streamDefinitions ) . toBeDefined ( ) ;
29
29
30
30
const params : URLSearchParams = HttpUtils . getPaginationParams ( 0 , 10 ) ;
31
-
32
- this . streamsService . getDefinitions ( ) ;
31
+ const requestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
32
+ requestOptionsArgs . search = params ;
33
+ this . streamsService . getDefinitions ( ) ;
33
34
34
35
const defaultPageNumber : number = this . streamsService . streamDefinitions . pageNumber ;
35
36
const defaultPageSize : number = this . streamsService . streamDefinitions . pageSize ;
36
37
37
38
expect ( defaultPageNumber ) . toBe ( 0 ) ;
38
39
expect ( defaultPageSize ) . toBe ( 10 ) ;
39
- expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , { search : params } ) ;
40
+ expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , requestOptionsArgs ) ;
40
41
41
42
this . streamsService . streamDefinitions . filter = 'testFilter' ;
42
43
this . streamsService . getDefinitions ( ) ;
43
44
expect ( this . streamsService . streamDefinitions . filter ) . toBe ( 'testFilter' ) ;
44
- expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , { search : params } ) ;
45
+ expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , requestOptionsArgs ) ;
45
46
} ) ;
46
47
47
48
it ( 'should call the definitions service with the right url [no sort params]' , ( ) => {
48
49
this . mockHttp . get . and . returnValue ( Observable . of ( this . jsonData ) ) ;
49
50
50
51
const params : URLSearchParams = HttpUtils . getPaginationParams ( 0 , 10 ) ;
51
-
52
+ const requestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
53
+ requestOptionsArgs . search = params ;
52
54
this . streamsService . getDefinitions ( ) ;
53
- expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , { search : params } ) ;
55
+ expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , requestOptionsArgs ) ;
54
56
} ) ;
55
57
56
58
it ( 'should call the definitions service with the right url [null sort params]' , ( ) => {
57
59
this . mockHttp . get . and . returnValue ( Observable . of ( this . jsonData ) ) ;
58
60
const params : URLSearchParams = HttpUtils . getPaginationParams ( 0 , 10 ) ;
61
+ const requestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
62
+ requestOptionsArgs . search = params ;
59
63
this . streamsService . getDefinitions ( undefined , undefined ) ;
60
- expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , { search : params } ) ;
64
+ expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , requestOptionsArgs ) ;
61
65
} ) ;
62
66
63
67
it ( 'should call the definitions service with the right url [desc asc sort]' , ( ) => {
64
68
this . mockHttp . get . and . returnValue ( Observable . of ( this . jsonData ) ) ;
65
69
const params : URLSearchParams = HttpUtils . getPaginationParams ( 0 , 10 ) ;
66
- const tocheck = params ;
67
- tocheck . append ( 'sort' , 'DEFINITION,ASC' ) ;
68
- tocheck . append ( 'sort' , 'DEFINITION_NAME,DESC' ) ;
70
+ params . append ( 'sort' , 'DEFINITION,ASC' ) ;
71
+ params . append ( 'sort' , 'DEFINITION_NAME,DESC' ) ;
69
72
this . streamsService . getDefinitions ( true , false ) ;
70
- expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , { search : tocheck } ) ;
73
+ const requestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
74
+ requestOptionsArgs . search = params ;
75
+ expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , requestOptionsArgs ) ;
71
76
} ) ;
72
77
73
78
it ( 'should call the definitions service with the right url [asc desc sort]' , ( ) => {
74
79
this . mockHttp . get . and . returnValue ( Observable . of ( this . jsonData ) ) ;
75
80
const params : URLSearchParams = HttpUtils . getPaginationParams ( 0 , 10 ) ;
76
- const tocheck = params ;
77
- tocheck . append ( 'sort' , 'DEFINITION,DESC' ) ;
78
- tocheck . append ( 'sort' , 'DEFINITION_NAME,ASC' ) ;
81
+ params . append ( 'sort' , 'DEFINITION,DESC' ) ;
82
+ params . append ( 'sort' , 'DEFINITION_NAME,ASC' ) ;
79
83
this . streamsService . getDefinitions ( false , true ) ;
80
- expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , { search : tocheck } ) ;
84
+ const requestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
85
+ requestOptionsArgs . search = params ;
86
+ expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/streams/definitions' , requestOptionsArgs ) ;
81
87
} ) ;
82
88
} ) ;
83
89
@@ -89,9 +95,8 @@ describe('StreamsService', () => {
89
95
90
96
const streamDefinition = new StreamDefinition ( 'test' , 'time|log' , 'undeployed' ) ;
91
97
this . streamsService . destroyDefinition ( streamDefinition ) ;
92
- const headers = new Headers ( { 'Content-Type' : 'application/json' } ) ;
93
- const options = new RequestOptions ( { headers : headers } ) ;
94
- expect ( this . mockHttp . delete ) . toHaveBeenCalledWith ( '/streams/definitions/test' , options ) ;
98
+ const requestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
99
+ expect ( this . mockHttp . delete ) . toHaveBeenCalledWith ( '/streams/definitions/test' , requestOptionsArgs ) ;
95
100
} ) ;
96
101
97
102
describe ( 'undeployDefinition' , ( ) => {
@@ -102,9 +107,8 @@ describe('StreamsService', () => {
102
107
103
108
const streamDefinition = new StreamDefinition ( 'test' , 'time|log' , 'deployed' ) ;
104
109
this . streamsService . undeployDefinition ( streamDefinition ) ;
105
- const headers = new Headers ( { 'Content-Type' : 'application/json' } ) ;
106
- const options = new RequestOptions ( { headers : headers } ) ;
107
- expect ( this . mockHttp . delete ) . toHaveBeenCalledWith ( '/streams/deployments/test' , options ) ;
110
+ const requestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
111
+ expect ( this . mockHttp . delete ) . toHaveBeenCalledWith ( '/streams/deployments/test' , requestOptionsArgs ) ;
108
112
} ) ;
109
113
} ) ;
110
114
@@ -115,9 +119,8 @@ describe('StreamsService', () => {
115
119
expect ( this . streamsService . streamDefinitions ) . toBeDefined ( ) ;
116
120
117
121
this . streamsService . deployDefinition ( 'test' , { } ) ;
118
- const headers = new Headers ( { 'Content-Type' : 'application/json' } ) ;
119
- const options = new RequestOptions ( { headers : headers } ) ;
120
- expect ( this . mockHttp . post ) . toHaveBeenCalledWith ( '/streams/deployments/test' , { } , options ) ;
122
+ const requestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
123
+ expect ( this . mockHttp . post ) . toHaveBeenCalledWith ( '/streams/deployments/test' , { } , requestOptionsArgs ) ;
121
124
} ) ;
122
125
} ) ;
123
126
0 commit comments