|
| 1 | +import { type ClassTransformOptions } from 'class-transformer'; |
| 2 | +import type CircuitBreaker from 'opossum'; |
| 3 | +import { describe, expect, test } from 'vitest'; |
| 4 | +import { Configuration } from './configuration'; |
| 5 | +import { StubHttpClient } from '../fixtures/stub-http-client'; |
| 6 | + |
| 7 | +describe('Configuration', () => { |
| 8 | + describe('default values', () => { |
| 9 | + const configuration = new Configuration(); |
| 10 | + |
| 11 | + test('timeout', () => { |
| 12 | + // when |
| 13 | + const timeout = configuration.timeout; |
| 14 | + |
| 15 | + // then |
| 16 | + expect(timeout).toBe(Configuration.DEFAULT_TIMEOUT); |
| 17 | + }); |
| 18 | + |
| 19 | + test('http client', () => { |
| 20 | + // given |
| 21 | + const configuration = new Configuration(); |
| 22 | + |
| 23 | + // when |
| 24 | + const httpClient = configuration.httpClient; |
| 25 | + |
| 26 | + // then |
| 27 | + expect(httpClient).toBeInstanceOf(Configuration.DEFAULT_HTTP_CLIENT); |
| 28 | + }); |
| 29 | + |
| 30 | + test('transform option', () => { |
| 31 | + // when |
| 32 | + const transformOption = configuration.transformOption; |
| 33 | + |
| 34 | + // then |
| 35 | + expect(transformOption).toBeUndefined(); |
| 36 | + }); |
| 37 | + |
| 38 | + test('circuit breaker option', () => { |
| 39 | + // when |
| 40 | + const circuitBreakerOption = configuration.circuitBreakerOption; |
| 41 | + |
| 42 | + // then |
| 43 | + expect(circuitBreakerOption).toBeUndefined(); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe('custom values', () => { |
| 48 | + test('timeout', () => { |
| 49 | + // given |
| 50 | + const timeout = 1000; |
| 51 | + |
| 52 | + // when |
| 53 | + const configuration = new Configuration({ timeout }); |
| 54 | + |
| 55 | + // then |
| 56 | + expect(configuration.timeout).toBe(timeout); |
| 57 | + }); |
| 58 | + |
| 59 | + test('http client', () => { |
| 60 | + // given |
| 61 | + const httpClient = new StubHttpClient(); |
| 62 | + |
| 63 | + // when |
| 64 | + const configuration = new Configuration({ httpClient }); |
| 65 | + |
| 66 | + // then |
| 67 | + expect(configuration.httpClient).toBe(httpClient); |
| 68 | + }); |
| 69 | + |
| 70 | + test('transform option', () => { |
| 71 | + // given |
| 72 | + const transformOption: ClassTransformOptions = { |
| 73 | + enableImplicitConversion: true, |
| 74 | + }; |
| 75 | + |
| 76 | + // when |
| 77 | + const configuration = new Configuration({ transformOption }); |
| 78 | + |
| 79 | + // then |
| 80 | + expect(configuration.transformOption).toBe(transformOption); |
| 81 | + }); |
| 82 | + |
| 83 | + test('circuit breaker option', () => { |
| 84 | + // given |
| 85 | + const circuitBreakerOption: CircuitBreaker.Options = { |
| 86 | + errorThresholdPercentage: 50, |
| 87 | + resetTimeout: 1000, |
| 88 | + }; |
| 89 | + const timeout = 10000; |
| 90 | + |
| 91 | + // when |
| 92 | + const configuration = new Configuration({ |
| 93 | + circuitBreakerOption, |
| 94 | + timeout, |
| 95 | + }); |
| 96 | + |
| 97 | + // then |
| 98 | + expect(configuration.circuitBreakerOption).toMatchInlineSnapshot(` |
| 99 | + { |
| 100 | + "errorThresholdPercentage": 50, |
| 101 | + "resetTimeout": 1000, |
| 102 | + "timeout": 10000, |
| 103 | + } |
| 104 | + `); |
| 105 | + }); |
| 106 | + }); |
| 107 | +}); |
0 commit comments