Skip to content

Commit

Permalink
Disable version for next prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
BuZZ-T committed Oct 20, 2021
1 parent 5d6d5b0 commit 15a6be6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
16 changes: 16 additions & 0 deletions commons/MappedVersion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,20 @@ describe('MappedVersion', () => {
it('should throw an error on unknwon input', () => {
expect(() => new MappedVersion(0 as unknown as IVersionWithDisabled)).toThrow('This should not happen, MappedVersion called with wrong types!')
})

it('should disable the version', () => {
const version = new MappedVersion({
major: 10,
minor: 0,
branch: 0,
patch: 0,
disabled: false
})

expect(version.disabled).toBe(false)

version.disable()

expect(version.disabled).toBe(true)
})
})
4 changes: 4 additions & 0 deletions commons/MappedVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class MappedVersion {
return this._disabled
}

public disable(): void {
this._disabled = true
}

public constructor(input: string, disabled: boolean)
public constructor(major: number, minor: number, branch: number, patch: number, disabled: boolean)
public constructor(versionObject: IVersionWithDisabled)
Expand Down
16 changes: 10 additions & 6 deletions versions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mocked } from 'ts-jest/utils'

import { fetchBranchPosition, fetchChromeUrl, fetchChromiumTags } from './api'
import { ComparableVersion } from './commons/ComparableVersion'
import { MappedVersion } from './commons/MappedVersion'
import { MappedVersion } from './commons/MappedVersion';
import { IDownloadSettings } from './interfaces/interfaces'
import { OSSetting } from './interfaces/os.interfaces'
import { Spinner, logger } from './log/spinner'
Expand Down Expand Up @@ -300,20 +300,24 @@ describe('versions', () => {
filenameOS: FILENAME_OS,
}

userSelectedVersionMock.mockResolvedValueOnce(version2)
const version = new MappedVersion(20, 0, 0, 0, false)
const disableSpy = jest.spyOn(version, 'disable')

userSelectedVersionMock.mockResolvedValueOnce(version)
fetchBranchPositionMock.mockResolvedValueOnce('branch-position2')
fetchChromeUrlMock.mockResolvedValueOnce(undefined)

expect(await getChromeDownloadUrl(config, [version1, version2])).toEqual(expectedSettings)
expect(await getChromeDownloadUrl(config, [version1, version])).toEqual(expectedSettings)

expect(disableSpy).toHaveBeenCalledTimes(1)
expect(storeNegativeHitMock).toHaveBeenCalledTimes(1)
expect(storeNegativeHitMock).toHaveBeenCalledWith(version2.comparable, 'linux', 'x64')
expect(storeNegativeHitMock).toHaveBeenCalledWith(version.comparable, 'linux', 'x64')
expect(detectOperatingSystemMock).toHaveBeenCalledTimes(1)
expect(detectOperatingSystemMock).toHaveBeenCalledWith(config)
expect(userSelectedVersionMock).toHaveBeenCalledTimes(2)
expect(userSelectedVersionMock).toHaveBeenCalledWith([version1, version2], config)
expect(userSelectedVersionMock).toHaveBeenCalledWith([version1, version], config)
expect(fetchBranchPositionMock).toHaveBeenCalledTimes(2)
expect(fetchBranchPositionMock).toHaveBeenCalledWith(version2.value)
expect(fetchBranchPositionMock).toHaveBeenCalledWith(version.value)
expect(fetchBranchPositionMock).toHaveBeenCalledWith(version1.value)
expect(fetchChromeUrlMock).toHaveBeenCalledTimes(2)
expect(fetchChromeUrlMock).toHaveBeenCalledWith('branch-position2', OS_SETTINGS)
Expand Down
1 change: 1 addition & 0 deletions versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export async function getChromeDownloadUrl(config: IChromeConfig, mappedVersions

if (!chromeUrl && !selectedVersion.disabled) {
const invalidVersion = mappedVersions[index]
invalidVersion.disable()
logger.error()
if (config.store) {
// TODO: remove await?
Expand Down

0 comments on commit 15a6be6

Please sign in to comment.