|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0 and the Server Side Public License, v 1; you may not use this file except |
| 5 | + * in compliance with, at your election, the Elastic License 2.0 or the Server |
| 6 | + * Side Public License, v 1. |
| 7 | + */ |
| 8 | + |
| 9 | +import { TestScheduler } from 'rxjs/testing'; |
| 10 | +import { ServiceStatus, ServiceStatusLevels } from './types'; |
| 11 | +import { getOverallStatusChanges } from './log_overall_status'; |
| 12 | + |
| 13 | +const getTestScheduler = () => |
| 14 | + new TestScheduler((actual, expected) => { |
| 15 | + expect(actual).toEqual(expected); |
| 16 | + }); |
| 17 | + |
| 18 | +const createStatus = (parts: Partial<ServiceStatus> = {}): ServiceStatus => ({ |
| 19 | + level: ServiceStatusLevels.available, |
| 20 | + summary: 'summary', |
| 21 | + ...parts, |
| 22 | +}); |
| 23 | + |
| 24 | +describe('getOverallStatusChanges', () => { |
| 25 | + it('emits an initial message after first overall$ emission', () => { |
| 26 | + getTestScheduler().run(({ expectObservable, hot }) => { |
| 27 | + const overall$ = hot<ServiceStatus>('--a', { |
| 28 | + a: createStatus(), |
| 29 | + }); |
| 30 | + const stop$ = hot<void>(''); |
| 31 | + const expected = '--a'; |
| 32 | + |
| 33 | + expectObservable(getOverallStatusChanges(overall$, stop$)).toBe(expected, { |
| 34 | + a: 'Kibana is now available', |
| 35 | + }); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + it('emits a new message every time the status level changes', () => { |
| 40 | + getTestScheduler().run(({ expectObservable, hot }) => { |
| 41 | + const overall$ = hot<ServiceStatus>('--a--b', { |
| 42 | + a: createStatus({ |
| 43 | + level: ServiceStatusLevels.degraded, |
| 44 | + }), |
| 45 | + b: createStatus({ |
| 46 | + level: ServiceStatusLevels.available, |
| 47 | + }), |
| 48 | + }); |
| 49 | + const stop$ = hot<void>(''); |
| 50 | + const expected = '--a--b'; |
| 51 | + |
| 52 | + expectObservable(getOverallStatusChanges(overall$, stop$)).toBe(expected, { |
| 53 | + a: 'Kibana is now degraded', |
| 54 | + b: 'Kibana is now available (was degraded)', |
| 55 | + }); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + it('does not emit when the status stays the same', () => { |
| 60 | + getTestScheduler().run(({ expectObservable, hot }) => { |
| 61 | + const overall$ = hot<ServiceStatus>('--a--b--c', { |
| 62 | + a: createStatus({ |
| 63 | + level: ServiceStatusLevels.degraded, |
| 64 | + summary: 'summary 1', |
| 65 | + }), |
| 66 | + b: createStatus({ |
| 67 | + level: ServiceStatusLevels.degraded, |
| 68 | + summary: 'summary 2', |
| 69 | + }), |
| 70 | + c: createStatus({ |
| 71 | + level: ServiceStatusLevels.available, |
| 72 | + summary: 'summary 2', |
| 73 | + }), |
| 74 | + }); |
| 75 | + const stop$ = hot<void>(''); |
| 76 | + const expected = '--a-----b'; |
| 77 | + |
| 78 | + expectObservable(getOverallStatusChanges(overall$, stop$)).toBe(expected, { |
| 79 | + a: 'Kibana is now degraded', |
| 80 | + b: 'Kibana is now available (was degraded)', |
| 81 | + }); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + it('stops emitting once `stop$` emits', () => { |
| 86 | + getTestScheduler().run(({ expectObservable, hot }) => { |
| 87 | + const overall$ = hot<ServiceStatus>('--a--b', { |
| 88 | + a: createStatus({ |
| 89 | + level: ServiceStatusLevels.degraded, |
| 90 | + }), |
| 91 | + b: createStatus({ |
| 92 | + level: ServiceStatusLevels.available, |
| 93 | + }), |
| 94 | + }); |
| 95 | + const stop$ = hot<void>('----(s|)'); |
| 96 | + const expected = '--a-|'; |
| 97 | + |
| 98 | + expectObservable(getOverallStatusChanges(overall$, stop$)).toBe(expected, { |
| 99 | + a: 'Kibana is now degraded', |
| 100 | + }); |
| 101 | + }); |
| 102 | + }); |
| 103 | +}); |
0 commit comments