Dmitrii Filippov | 701a252 | 2020-04-22 11:25:02 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @license |
Ben Rohlfs | 94fcbbc | 2022-05-27 10:45:03 +0200 | [diff] [blame] | 3 | * Copyright 2020 Google LLC |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
Dmitrii Filippov | 701a252 | 2020-04-22 11:25:02 +0200 | [diff] [blame] | 5 | */ |
Chris Poucet | f17f1b1b | 2021-11-24 14:02:46 +0100 | [diff] [blame] | 6 | import {create, Registry, Finalizable} from '../services/registry'; |
Chris Poucet | d3f52fd | 2021-11-29 23:16:39 +0100 | [diff] [blame] | 7 | import {AppContext} from '../services/app-context'; |
Chris Poucet | f17f1b1b | 2021-11-24 14:02:46 +0100 | [diff] [blame] | 8 | import {AuthService} from '../services/gr-auth/gr-auth'; |
Milutin Kristofic | 55f42bf | 2020-08-07 15:27:54 +0200 | [diff] [blame] | 9 | import {FlagsService} from '../services/flags/flags'; |
| 10 | import {grReportingMock} from '../services/gr-reporting/gr-reporting_mock'; |
Dmitrii Filippov | 701a252 | 2020-04-22 11:25:02 +0200 | [diff] [blame] | 11 | |
Milutin Kristofic | 55f42bf | 2020-08-07 15:27:54 +0200 | [diff] [blame] | 12 | class MockFlagsService implements FlagsService { |
| 13 | isEnabled() { |
Dmitrii Filippov | 701a252 | 2020-04-22 11:25:02 +0200 | [diff] [blame] | 14 | return false; |
| 15 | } |
| 16 | |
Chris Poucet | 55cbccb | 2021-11-16 03:17:06 +0100 | [diff] [blame] | 17 | finalize() {} |
| 18 | |
Dmitrii Filippov | 701a252 | 2020-04-22 11:25:02 +0200 | [diff] [blame] | 19 | /** |
Ben Rohlfs | f00a6cc | 2022-03-02 12:03:41 +0100 | [diff] [blame] | 20 | * @return array of all enabled experiments. |
Dmitrii Filippov | 701a252 | 2020-04-22 11:25:02 +0200 | [diff] [blame] | 21 | */ |
| 22 | get enabledExperiments() { |
| 23 | return []; |
| 24 | } |
| 25 | } |
| 26 | |
Milutin Kristofic | 55f42bf | 2020-08-07 15:27:54 +0200 | [diff] [blame] | 27 | class MockAuthService implements AuthService { |
| 28 | clearCache() {} |
Milutin Kristofic | 0f1e069 | 2020-07-21 12:21:58 +0200 | [diff] [blame] | 29 | |
| 30 | get isAuthed() { |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | authCheck() { |
| 35 | return Promise.resolve(false); |
| 36 | } |
Milutin Kristofic | 55f42bf | 2020-08-07 15:27:54 +0200 | [diff] [blame] | 37 | |
| 38 | baseUrl = ''; |
| 39 | |
| 40 | setup() {} |
| 41 | |
Chris Poucet | 55cbccb | 2021-11-16 03:17:06 +0100 | [diff] [blame] | 42 | finalize() {} |
| 43 | |
Milutin Kristofic | 55f42bf | 2020-08-07 15:27:54 +0200 | [diff] [blame] | 44 | fetch() { |
| 45 | const blob = new Blob(); |
| 46 | const init = {status: 200, statusText: 'Ack'}; |
| 47 | const response = new Response(blob, init); |
| 48 | return Promise.resolve(response); |
| 49 | } |
Milutin Kristofic | 0f1e069 | 2020-07-21 12:21:58 +0200 | [diff] [blame] | 50 | } |
| 51 | |
Dmitrii Filippov | 701a252 | 2020-04-22 11:25:02 +0200 | [diff] [blame] | 52 | // Setup mocks for appContext. |
| 53 | // This is a temporary solution |
| 54 | // TODO(dmfilippov): find a better solution for gr-diff |
Chris Poucet | d3f52fd | 2021-11-29 23:16:39 +0100 | [diff] [blame] | 55 | export function createDiffAppContext(): AppContext & Finalizable { |
Chris Poucet | f17f1b1b | 2021-11-24 14:02:46 +0100 | [diff] [blame] | 56 | const appRegistry: Registry<AppContext> = { |
| 57 | flagsService: (_ctx: Partial<AppContext>) => new MockFlagsService(), |
| 58 | authService: (_ctx: Partial<AppContext>) => new MockAuthService(), |
| 59 | reportingService: (_ctx: Partial<AppContext>) => grReportingMock, |
| 60 | eventEmitter: (_ctx: Partial<AppContext>) => { |
| 61 | throw new Error('eventEmitter is not implemented'); |
| 62 | }, |
| 63 | restApiService: (_ctx: Partial<AppContext>) => { |
| 64 | throw new Error('restApiService is not implemented'); |
| 65 | }, |
Chris Poucet | f17f1b1b | 2021-11-24 14:02:46 +0100 | [diff] [blame] | 66 | }; |
Chris Poucet | d3f52fd | 2021-11-29 23:16:39 +0100 | [diff] [blame] | 67 | return create<AppContext>(appRegistry); |
Dmitrii Filippov | 701a252 | 2020-04-22 11:25:02 +0200 | [diff] [blame] | 68 | } |