* IdentityProvider that simulates various error scenarios with configurable behavior
| 85 | * IdentityProvider that simulates various error scenarios with configurable behavior |
| 86 | */ |
| 87 | class ErrorSimulatingProvider implements IdentityProvider<string> { |
| 88 | private requestCount = 0; |
| 89 | |
| 90 | constructor( |
| 91 | private readonly errorSequence: Array<Error | string>, |
| 92 | private readonly delayMs: number = 0, |
| 93 | private readonly ttlMs: number = 100 |
| 94 | ) {} |
| 95 | |
| 96 | async requestToken(): Promise<TokenResponse<string>> { |
| 97 | |
| 98 | if (this.delayMs > 0) { |
| 99 | await delay(this.delayMs); |
| 100 | } |
| 101 | |
| 102 | const result = this.errorSequence[this.requestCount]; |
| 103 | this.requestCount++; |
| 104 | |
| 105 | if (result instanceof Error) { |
| 106 | throw result; |
| 107 | } else if (typeof result === 'string') { |
| 108 | return { token: result, ttlMs: this.ttlMs }; |
| 109 | } else { |
| 110 | throw new Error('No more responses configured'); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | getRequestCount(): number { |
| 115 | return this.requestCount; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | describe('constructor validation', () => { |
| 120 | it('should throw error if ratio is greater than 1', () => { |
nothing calls this directly
no outgoing calls
no test coverage detected