-
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
f412ad3
commit f4c6ff2
Showing
6 changed files
with
253 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
169 changes: 169 additions & 0 deletions
169
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,169 @@ | ||
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'); | ||
}); | ||
|
||
it('should throw an error if no versions are supported', async() => { | ||
(fetch as jest.Mock).mockReturnValueOnce({ | ||
json: () => Promise.resolve({ | ||
requestIntervalInMinutes: 100, | ||
versions: [ | ||
{ | ||
Name: 'v1.2.3', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: false, | ||
Tags: [], | ||
}, | ||
{ | ||
Name: 'v3.2.1', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: false, | ||
Tags: [], | ||
}, | ||
{ | ||
Name: 'v2.1.3', | ||
ReleaseDate: 'testreleasedate', | ||
Supported: false, | ||
Tags: [], | ||
}, | ||
], | ||
}), | ||
}); | ||
const result = queryUpgradeResponder('testurl', new semver.SemVer('v1.2.3')); | ||
|
||
await expect(result).rejects.toThrow('Could not find latest version'); | ||
}); | ||
|
||
it('should treat all versions as supported when server does not include Supported key', async() => { | ||
(fetch as jest.Mock).mockReturnValueOnce({ | ||
json: () => Promise.resolve({ | ||
requestIntervalInMinutes: 100, | ||
versions: [ | ||
{ | ||
Name: 'v1.2.3', | ||
ReleaseDate: 'testreleasedate', | ||
Tags: [], | ||
}, | ||
{ | ||
Name: 'v3.2.1', | ||
ReleaseDate: 'testreleasedate', | ||
Tags: [], | ||
}, | ||
{ | ||
Name: 'v2.1.3', | ||
ReleaseDate: 'testreleasedate', | ||
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
Oops, something went wrong.