Skip to content

Commit

Permalink
[CP-2749] Extended MockUpdaterStateService to handle downloaded state
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarski committed Jun 27, 2024
1 parent be20b35 commit 2def696
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
18 changes: 17 additions & 1 deletion libs/e2e-mock/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ E2EMockClient.mockHttpResponse({
The `setMockUpdateState` function is a method provided by the `E2EMockClient` to simulate different update states of the application, use the following command:

```javascript
E2EMockClient.setMockUpdateState({ available: boolean, version?: string })
E2EMockClient.setMockUpdateState({ available: boolean, downloaded?: boolean, version?: string })
```

### Parameters
- `available` (boolean): This parameter indicates whether an update is available (`true`) or not (`false`).

- `version` (string, optional): This parameter specifies the version of the update that is available. It is only required if `available` is set to `true`.

- `downloaded` (boolean, optional): This parameter indicates whether the download process was successful (`true`) or not (`false`). When downloaded is `true`, the modal shows in-progress indefinitely, and in the production environment, the application closes to complete the installation process. When downloaded is `false`, the application displays an error message.

## Usage Examples

### No Update Available
Expand All @@ -71,6 +73,20 @@ To set the response indicating that an update is available with a specified vers
E2EMockClient.setMockUpdateState({ available: true, version: "4.0.0" })
```

### Update Available with Download Failure

To set the response indicating that an update is available with a specified version, but the download process fails, use the following command:
```javascript
E2EMockClient.setMockUpdateState({ available: true, version: "4.0.0", downloaded: false })
```

### Update Available with Successful Download

To set the response indicating that an update is available with a specified version and the download process is successful, use the following command:
```javascript
E2EMockClient.setMockUpdateState({ available: true, version: "4.0.0", downloaded: true })
```

### Required Mudita Center Update

To set the response indicating that an update is available and a Mudita Center update is required for versions lower than 3.0.0, use the following commands:
Expand Down
12 changes: 8 additions & 4 deletions libs/e2e-mock/server/src/lib/mock-updater-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@

export interface UpdateState {
available: boolean
downloaded?: boolean
version?: string
}

const defaultUpdateState: UpdateState = {
available: false,
downloaded: true,
}

export class MockUpdaterStateService {
private _updateState: UpdateState = {
available: false,
}
private _updateState = { ...defaultUpdateState }

get updateState(): UpdateState {
return this._updateState
}

set updateState(value: UpdateState) {
this._updateState = value
this._updateState = { ...defaultUpdateState, ...value }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export class MockApplicationUpdaterService extends BaseApplicationUpdaterService
) {
super()
}
public quitAndInstall(): void {
this.onError()
}
public quitAndInstall(): void {}

public async downloadUpdate(): Promise<void> {
this.onError()
if (this.isUpdateDownloaded()) {
this.onUpdateDownloaded()
} else {
this.onError()
}
}

public async checkForUpdatesAndNotify(): Promise<void> {
Expand All @@ -33,6 +35,11 @@ export class MockApplicationUpdaterService extends BaseApplicationUpdaterService
this.onUpdateNotAvailable()
}
}

private isUpdateDownloaded(): boolean {
return this.mockUpdaterStateService.updateState.downloaded ?? true
}

private isUpdateAvailable(): boolean {
return this.mockUpdaterStateService.updateState.available
}
Expand Down

0 comments on commit 2def696

Please sign in to comment.