Skip to content

Commit c8e9940

Browse files
committed
Remove unneccesary polling calls
1 parent b87f457 commit c8e9940

File tree

4 files changed

+27
-112
lines changed

4 files changed

+27
-112
lines changed

src/app/shared/models/hoverfly.model.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,3 @@ export interface Hoverfly {
1010
middleware: Middleware;
1111
usage: Usage;
1212
}
13-
14-
export class NullHoverfly implements Hoverfly {
15-
version = '';
16-
mode = '';
17-
destination = '';
18-
middleware = {} as Middleware;
19-
usage = {} as Usage;
20-
21-
}

src/app/shared/services/hoverfly.service.spec.ts

Lines changed: 24 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,48 @@ describe('Service: Hoverfly', () => {
4545

4646
});
4747

48-
it('getVersion should dispatch an update action', () => {
48+
it('getHoverflyInfo should dispatch an update action', () => {
4949

50-
service.getVersion();
50+
const hoverflyInfo = {
51+
destination: 'hoverfly.io',
52+
mode: 'simulate',
53+
usage: {
54+
counters: {
55+
capture: 0,
56+
modify: 0,
57+
simulate: 0,
58+
spy: 0,
59+
synthesize: 0
60+
}
61+
},
62+
version: 'v0.15.0',
63+
};
64+
65+
service.getHoverflyInfo();
5166
lastConnection.mockRespond(new Response(new ResponseOptions({
52-
body: { version: 'v0.11.4' },
67+
body: hoverflyInfo,
5368
status: 200
5469
})));
5570

5671
expect(lastConnection).toBeDefined();
57-
expect(lastConnection.request.url).toBe('/api/v2/hoverfly/version');
72+
expect(lastConnection.request.url).toBe('/api/v2/hoverfly');
5873
expect(lastConnection.request.method).toBe(RequestMethod.Get);
5974

6075
expect(ngRedux.dispatch).toHaveBeenCalledWith({
6176
type: HOVERFLY_ACTIONS.UPDATE,
62-
payload: { version: 'v0.11.4' }
77+
payload: hoverflyInfo
6378
});
6479

6580
});
6681

67-
it('getMode should dispatch an update action', () => {
82+
it('getHoverflyInfo failed should dispatch an error notification action', () => {
6883

69-
service.getMode();
70-
lastConnection.mockRespond(new Response(new ResponseOptions({
71-
body: { mode: 'capture' },
72-
status: 200
73-
})));
84+
service.getHoverflyInfo();
85+
lastConnection.mockError(mockErrorResponse(0));
7486

7587
expect(lastConnection).toBeDefined();
76-
expect(lastConnection.request.url).toBe('/api/v2/hoverfly/mode');
77-
expect(lastConnection.request.method).toBe(RequestMethod.Get);
78-
79-
expect(ngRedux.dispatch).toHaveBeenCalledWith({
80-
type: HOVERFLY_ACTIONS.UPDATE,
81-
payload: { mode: 'capture' }
82-
});
8388

89+
expect(notifyService.sendError).toHaveBeenCalledWith(API_ERRORS.SERVICE_UNAVAILABLE);
8490
});
8591

8692
it('setMode should send hoverfly mode', () => {
@@ -103,34 +109,6 @@ describe('Service: Hoverfly', () => {
103109

104110
});
105111

106-
it('getDestination should dispatch an update action', () => {
107-
108-
service.getDestination();
109-
lastConnection.mockRespond(new Response(new ResponseOptions({
110-
body: { destination: 'destination.com' },
111-
status: 200
112-
})));
113-
114-
expect(lastConnection).toBeDefined();
115-
expect(lastConnection.request.url).toBe('/api/v2/hoverfly/destination');
116-
expect(lastConnection.request.method).toBe(RequestMethod.Get);
117-
118-
expect(ngRedux.dispatch).toHaveBeenCalledWith({
119-
type: HOVERFLY_ACTIONS.UPDATE,
120-
payload: { destination: 'destination.com' }
121-
});
122-
123-
});
124-
125-
it('getDestination failed should dispatch an error notification action', () => {
126-
127-
service.getDestination();
128-
lastConnection.mockError(mockErrorResponse(0));
129-
130-
expect(lastConnection).toBeDefined();
131-
132-
expect(notifyService.sendError).toHaveBeenCalledWith(API_ERRORS.SERVICE_UNAVAILABLE);
133-
});
134112

135113
it('getMiddleware should dispatch an update action', () => {
136114

@@ -174,33 +152,4 @@ describe('Service: Hoverfly', () => {
174152

175153
});
176154

177-
it('getUsage should dispatch an update action', () => {
178-
179-
const usageData = {
180-
usage: {
181-
counters: {
182-
capture: 1,
183-
modify: 2,
184-
simulate: 3,
185-
synthesize: 4
186-
}
187-
}
188-
};
189-
190-
service.getUsage();
191-
192-
lastConnection.mockRespond(new Response(new ResponseOptions({
193-
body: usageData,
194-
status: 200
195-
})));
196-
expect(lastConnection).toBeDefined();
197-
expect(lastConnection.request.url).toBe('/api/v2/hoverfly/usage');
198-
expect(lastConnection.request.method).toBe(RequestMethod.Get);
199-
200-
expect(ngRedux.dispatch).toHaveBeenCalledWith({
201-
type: HOVERFLY_ACTIONS.UPDATE,
202-
payload: usageData
203-
});
204-
});
205-
206155
});

src/app/shared/services/hoverfly.service.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,6 @@ export class HoverflyService {
1818
constructor(private http: Http, private ngRedux: NgRedux<AppState>, private notifyService: NotificationService) {
1919
}
2020

21-
getVersion(): void {
22-
this.http.get('/api/v2/hoverfly/version')
23-
.map(res => res.json())
24-
.subscribe(
25-
this.updateHoverfly(),
26-
httpErrorHandler(this.notifyService));
27-
}
28-
29-
getMode(): void {
30-
this.http.get('/api/v2/hoverfly/mode')
31-
.map(res => res.json())
32-
.subscribe(
33-
this.updateHoverfly(),
34-
httpErrorHandler(this.notifyService));
35-
}
3621

3722
setMode(modeSelection): void {
3823
this.http.put('/api/v2/hoverfly/mode', JSON.stringify({ mode: modeSelection }))
@@ -42,8 +27,8 @@ export class HoverflyService {
4227
httpErrorHandler(this.notifyService));
4328
}
4429

45-
getDestination(): void {
46-
this.http.get('/api/v2/hoverfly/destination')
30+
getHoverflyInfo(): void {
31+
this.http.get('/api/v2/hoverfly')
4732
.map(res => res.json())
4833
.subscribe(
4934
this.updateHoverfly(),
@@ -60,22 +45,13 @@ export class HoverflyService {
6045
httpErrorHandler(this.notifyService));
6146
}
6247

63-
getUsage(): void {
64-
this.http.get('/api/v2/hoverfly/usage')
65-
.map(res => res.json())
66-
.subscribe(
67-
this.updateHoverfly(),
68-
httpErrorHandler(this.notifyService));
69-
}
7048

7149
pollHoverfly(): Subscription {
7250

7351
return Observable.timer(0, 5000)
7452
.subscribe(() => {
75-
this.getMode();
76-
this.getDestination();
53+
this.getHoverflyInfo();
7754
this.getMiddleware();
78-
this.getUsage();
7955
});
8056

8157
}

src/app/views/dashboard/dashboard.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class DashboardComponent implements OnInit, OnDestroy {
3030
this.hoverfly = hoverfly.toJS();
3131
});
3232

33-
this.service.getVersion();
3433
this.pollingSubscription = this.service.pollHoverfly();
3534

3635
this.notiffyService.errors

0 commit comments

Comments
 (0)