-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathapp.service.spec.ts
198 lines (184 loc) · 8.58 KB
/
app.service.spec.ts
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
190
191
192
193
194
195
196
197
198
import {of} from 'rxjs';
import {AppService} from './app.service';
import {App, ApplicationType} from '../model/app.model';
import {GET_APP_VERSIONS} from '../../tests/data/app';
describe('shared/api/app.service.ts', () => {
let mockHttp;
let appService;
let jsonData = {};
beforeEach(() => {
mockHttp = {
delete: jasmine.createSpy('delete'),
get: jasmine.createSpy('get'),
post: jasmine.createSpy('post'),
put: jasmine.createSpy('put')
};
jsonData = {};
appService = new AppService(mockHttp);
});
it('unregisterApps', () => {
mockHttp.delete.and.returnValue(of(jsonData));
appService.unregisterApps([App.parse({name: 'foo', type: 'source'}), App.parse({name: 'bar', type: 'processor'})]);
let httpUri = mockHttp.delete.calls.argsFor(0)[0];
expect(httpUri).toEqual('/apps/source/foo');
httpUri = mockHttp.delete.calls.argsFor(1)[0];
expect(httpUri).toEqual('/apps/processor/bar');
});
it('getApp', () => {
mockHttp.get.and.returnValue(of(jsonData));
appService.getApp('foo', 'processor' as any as ApplicationType);
const httpUri = mockHttp.get.calls.mostRecent().args[0];
const headerArgs = mockHttp.get.calls.mostRecent().args[1].headers;
expect(httpUri).toEqual('/apps/processor/foo');
expect(headerArgs.get('Content-Type')).toEqual('application/json');
expect(headerArgs.get('Accept')).toEqual('application/json');
});
it('getApp with spring boot version in parameter', () => {
mockHttp.get.and.returnValue(of(jsonData));
appService.getApp('foo', 'processor' as any as ApplicationType, '');
const httpUri = mockHttp.get.calls.mostRecent().args[0];
const headerArgs = mockHttp.get.calls.mostRecent().args[1].headers;
expect(httpUri).toEqual('/apps/processor/foo');
expect(headerArgs.get('Content-Type')).toEqual('application/json');
expect(headerArgs.get('Accept')).toEqual('application/json');
});
it('getApp with version', () => {
mockHttp.get.and.returnValue(of(jsonData));
appService.getApp('foo', 'processor' as any as ApplicationType, '1.0.0');
const httpUri = mockHttp.get.calls.mostRecent().args[0];
const headerArgs = mockHttp.get.calls.mostRecent().args[1].headers;
expect(httpUri).toEqual('/apps/processor/foo/1.0.0');
expect(headerArgs.get('Content-Type')).toEqual('application/json');
expect(headerArgs.get('Accept')).toEqual('application/json');
});
it('importUri', () => {
mockHttp.post.and.returnValue(of(true));
appService.importUri('https://uri.foo.bar', true);
const httpUri = mockHttp.post.calls.mostRecent().args[0];
const headerArgs = mockHttp.post.calls.mostRecent().args[2].headers;
const httpParams = mockHttp.post.calls.mostRecent().args[2].params;
expect(httpUri).toEqual('/apps');
expect(headerArgs.get('Content-Type')).toEqual('application/json');
expect(headerArgs.get('Accept')).toEqual('application/json');
expect(httpParams.get('uri')).toEqual('https://uri.foo.bar');
expect(httpParams.get('force')).toEqual('true');
});
it('unregisterApp', () => {
mockHttp.delete.and.returnValue(of(jsonData));
appService.unregisterApp(App.parse({name: 'foo', type: 'source'}));
const httpUri = mockHttp.delete.calls.mostRecent().args[0];
const headerArgs = mockHttp.delete.calls.mostRecent().args[1].headers;
expect(httpUri).toEqual('/apps/source/foo');
expect(headerArgs.get('Content-Type')).toEqual('application/json');
expect(headerArgs.get('Accept')).toEqual('application/json');
});
it('unregisterApp with version', () => {
mockHttp.delete.and.returnValue(of(jsonData));
appService.unregisterApp(App.parse({name: 'foo', type: 'source', version: '1.0.0'}));
const httpUri = mockHttp.delete.calls.mostRecent().args[0];
const headerArgs = mockHttp.delete.calls.mostRecent().args[1].headers;
expect(httpUri).toEqual('/apps/source/foo/1.0.0');
expect(headerArgs.get('Content-Type')).toEqual('application/json');
expect(headerArgs.get('Accept')).toEqual('application/json');
});
it('importProps', () => {
mockHttp.post.and.returnValue(of(true));
appService.importProps('foo', true);
const httpUri = mockHttp.post.calls.mostRecent().args[0];
const headerArgs = mockHttp.post.calls.mostRecent().args[2].headers;
const httpParams = mockHttp.post.calls.mostRecent().args[2].params;
expect(httpUri).toEqual('/apps');
expect(headerArgs.get('Content-Type')).toEqual('application/json');
expect(headerArgs.get('Accept')).toEqual('application/json');
expect(httpParams.get('apps')).toEqual('foo');
expect(httpParams.get('force')).toEqual('true');
});
it('registerApp', () => {
mockHttp.post.and.returnValue(of(true));
appService.registerProp({
name: 'foo',
uri: 'https://uri.foo.bar',
metaDataUri: 'https://metaDataUri.foo.bar',
type: ApplicationType.processor,
force: true
});
const httpUri = mockHttp.post.calls.mostRecent().args[0];
const headerArgs = mockHttp.post.calls.mostRecent().args[2].headers;
const httpParams = mockHttp.post.calls.mostRecent().args[2].params;
expect(httpUri).toEqual('/apps/processor/foo');
expect(headerArgs.get('Content-Type')).toEqual('application/json');
expect(headerArgs.get('Accept')).toEqual('application/json');
expect(httpParams.get('uri')).toEqual('https://uri.foo.bar');
expect(httpParams.get('metadata-uri')).toEqual('https://metaDataUri.foo.bar');
expect(httpParams.get('force')).toEqual('true');
});
it('registerProps', () => {
mockHttp.post.and.returnValue(of(true));
const props = [
{
name: 'foo',
uri: 'https://uri.foo',
metaDataUri: 'https://metaDataUri.foo',
type: ApplicationType.processor,
force: true
},
{
name: 'bar',
uri: 'https://uri.bar',
metaDataUri: 'https://metaDataUri.bar',
type: ApplicationType.sink,
force: false
}
];
appService.registerProps(props);
const httpUri1 = mockHttp.post.calls.argsFor(0)[0];
const headerArgs1 = mockHttp.post.calls.argsFor(0)[2].headers;
const httpParams1 = mockHttp.post.calls.argsFor(0)[2].params;
const httpUri2 = mockHttp.post.calls.argsFor(1)[0];
const headerArgs2 = mockHttp.post.calls.argsFor(1)[2].headers;
const httpParams2 = mockHttp.post.calls.argsFor(1)[2].params;
expect(httpUri1).toEqual('/apps/processor/foo');
expect(headerArgs1.get('Content-Type')).toEqual('application/json');
expect(headerArgs1.get('Accept')).toEqual('application/json');
expect(httpParams1.get('uri')).toEqual('https://uri.foo');
expect(httpParams1.get('metadata-uri')).toEqual('https://metaDataUri.foo');
expect(httpParams1.get('force')).toEqual('true');
expect(httpUri2).toEqual('/apps/sink/bar');
expect(headerArgs2.get('Content-Type')).toEqual('application/json');
expect(headerArgs2.get('Accept')).toEqual('application/json');
expect(httpParams2.get('uri')).toEqual('https://uri.bar');
expect(httpParams2.get('metadata-uri')).toEqual('https://metaDataUri.bar');
expect(httpParams2.get('force')).toEqual('false');
expect(mockHttp.post).toHaveBeenCalledTimes(2);
});
it('defaultVersion', () => {
mockHttp.put.and.returnValue(of(jsonData));
appService.defaultVersion(App.parse({name: 'foo', type: 'source', version: '1.0.0'}));
const httpUri1 = mockHttp.put.calls.mostRecent().args[0];
expect(httpUri1).toEqual('/apps/source/foo/1.0.0');
});
it('getApps', () => {
mockHttp.get.and.returnValue(of(jsonData));
appService.getApps(0, 20, 'bar', 'processor' as any as ApplicationType, 'name', 'DESC');
const httpUri = mockHttp.get.calls.mostRecent().args[0];
const httpParams = mockHttp.get.calls.mostRecent().args[1].params;
expect(httpParams.get('sort')).toEqual('name,DESC');
expect(httpParams.get('search')).toEqual('bar');
expect(httpParams.get('type')).toEqual('processor');
expect(httpParams.get('page')).toEqual('0');
expect(httpParams.get('size')).toEqual('20');
expect(httpUri).toEqual('/apps');
});
it('getAppVersions', async done => {
mockHttp.get.and.returnValue(of(GET_APP_VERSIONS));
await appService.getAppVersions('aggregator', 'processor' as any as ApplicationType).subscribe();
const httpUri = mockHttp.get.calls.mostRecent().args[0];
const httpParams = mockHttp.get.calls.mostRecent().args[1].params;
expect(httpParams.get('search')).toEqual('aggregator');
expect(httpParams.get('type')).toEqual('processor');
expect(httpParams.get('page')).toEqual('0');
expect(httpParams.get('size')).toEqual('10000');
expect(httpUri).toEqual('/apps');
done();
});
});