-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to fetch tool versions from packagist
- Loading branch information
1 parent
0be6fa1
commit 6cc8b47
Showing
8 changed files
with
390 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as packagist from '../src/packagist'; | ||
import nock = require('nock'); | ||
|
||
describe('search function', () => { | ||
const mockResponse = { | ||
packages: { | ||
'test-package': [ | ||
{ | ||
require: { | ||
php: '8.0.0' | ||
}, | ||
version: '1.0.0' | ||
}, | ||
{ | ||
version: '2.0.0' | ||
} | ||
] | ||
} | ||
}; | ||
|
||
test('should return the version if matching php version is found', async () => { | ||
nock('https://repo.packagist.org') | ||
.get('/p2/test-package.json') | ||
.reply(200, mockResponse); | ||
const result = await packagist.search('test-package', '8.0'); | ||
expect(result).toBe('1.0.0'); | ||
}); | ||
|
||
test('should return null if no matching php version is found', async () => { | ||
nock('https://repo.packagist.org') | ||
.get('/p2/test-package.json') | ||
.reply(200, mockResponse); | ||
const result = await packagist.search('test-package', '5.6'); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
test('should return null if fetch fails', async () => { | ||
nock('https://repo.packagist.org').get('/p2/test-package.json').reply(404); | ||
const result = await packagist.search('test-package', '8.0'); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
test('should return null if the response is empty', async () => { | ||
nock('https://repo.packagist.org') | ||
.get('/p2/test-package.json') | ||
.reply(200, {error: true, data: '[]'}); | ||
const result = await packagist.search('test-package', '8.0'); | ||
expect(result).toBeNull(); | ||
}); | ||
}); |
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.