-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for queryUpdateResponder
Signed-off-by: Adam Pickering <[email protected]>
- Loading branch information
1 parent
99c9695
commit a052bbc
Showing
6 changed files
with
193 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
pkg/rancher-desktop/main/update/__tests__/LonghornProvider.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import semver from 'semver'; | ||
|
||
import { queryUpgradeResponder } from '../LonghornProvider'; | ||
|
||
import fetch from '@pkg/utils/fetch'; | ||
|
||
jest.mock('@pkg/utils/fetch', () => { | ||
return { | ||
__esModule: true, | ||
default: jest.fn(), | ||
}; | ||
}); | ||
|
||
describe('queryUpgradeResponder', () => { | ||
it('should return the latest version', async() => { | ||
(fetch as jest.Mock).mockReturnValueOnce({ | ||
json: () => Promise.resolve({ | ||
requestIntervalInMinutes: 100, | ||
versions: [ | ||
{ | ||
Name: 'v1.2.3', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: true, | ||
Tags: [], | ||
}, | ||
{ | ||
Name: 'v3.2.1', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: true, | ||
Tags: [], | ||
}, | ||
{ | ||
Name: 'v2.1.3', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: true, | ||
Tags: [], | ||
}, | ||
], | ||
}), | ||
}); | ||
const result = await queryUpgradeResponder('testurl', new semver.SemVer('v1.2.3')); | ||
|
||
expect(result.latest.Name).toEqual('v3.2.1'); | ||
}); | ||
|
||
it('should set unsupportedUpgradeAvailable to true when a newer-than-latest version is unsupported', async() => { | ||
(fetch as jest.Mock).mockReturnValueOnce({ | ||
json: () => Promise.resolve({ | ||
requestIntervalInMinutes: 100, | ||
versions: [ | ||
{ | ||
Name: 'v1.2.3', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: true, | ||
Tags: [], | ||
}, | ||
{ | ||
Name: 'v3.2.1', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: false, | ||
Tags: [], | ||
}, | ||
{ | ||
Name: 'v2.1.3', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: true, | ||
Tags: [], | ||
}, | ||
], | ||
}), | ||
}); | ||
const result = await queryUpgradeResponder('testurl', new semver.SemVer('v1.2.3')); | ||
|
||
expect(result.unsupportedUpgradeAvailable).toBe(true); | ||
expect(result.latest.Name).toEqual('v2.1.3'); | ||
}); | ||
|
||
it('should set unsupportedUpgradeAvailable to false when no newer-than-latest versions are unsupported', async() => { | ||
(fetch as jest.Mock).mockReturnValueOnce({ | ||
json: () => Promise.resolve({ | ||
requestIntervalInMinutes: 100, | ||
versions: [ | ||
{ | ||
Name: 'v1.2.3', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: true, | ||
Tags: [], | ||
}, | ||
{ | ||
Name: 'v3.2.1', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: true, | ||
Tags: [], | ||
}, | ||
{ | ||
Name: 'v2.1.3', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: false, | ||
Tags: [], | ||
}, | ||
], | ||
}), | ||
}); | ||
const result = await queryUpgradeResponder('testurl', new semver.SemVer('v1.2.3')); | ||
|
||
expect(result.unsupportedUpgradeAvailable).toBe(false); | ||
expect(result.latest.Name).toEqual('v3.2.1'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters