-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: tweak libraries/bower service classes and tests
- Loading branch information
1 parent
e4588b4
commit baab63c
Showing
9 changed files
with
171 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { expect } from 'chai' | ||
import { test, given } from 'sazerac' | ||
import nock from 'nock' | ||
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js' | ||
import { InvalidResponse } from '../index.js' | ||
import LibrariesIoApiProvider from '../librariesio/librariesio-api-provider.js' | ||
import { BowerVersion } from './bower-version.service.js' | ||
|
||
describe('BowerVersion', function () { | ||
test(BowerVersion.transform, () => { | ||
given( | ||
{ | ||
latest_release_number: '2.0.0-beta', | ||
latest_stable_release_number: '1.8.3', | ||
}, | ||
false | ||
).expect('1.8.3') | ||
given( | ||
{ | ||
latest_release_number: '2.0.0-beta', | ||
latest_stable_release_number: '1.8.3', | ||
}, | ||
true | ||
).expect('2.0.0-beta') | ||
}) | ||
|
||
it('throws `no releases` InvalidResponse if no stable version', function () { | ||
expect(() => | ||
BowerVersion.transform({ latest_release_number: 'panda' }, false) | ||
) | ||
.to.throw(InvalidResponse) | ||
.with.property('prettyMessage', 'no releases') | ||
}) | ||
|
||
it('throws `no releases` InvalidResponse if no prereleases', function () { | ||
expect(() => | ||
BowerVersion.transform({ latest_stable_release_number: 'penguin' }, true) | ||
) | ||
.to.throw(InvalidResponse) | ||
.with.property('prettyMessage', 'no releases') | ||
}) | ||
|
||
context('auth', function () { | ||
cleanUpNockAfterEach() | ||
const fakeApiKey = 'fakeness' | ||
const response = { | ||
normalized_licenses: [], | ||
latest_release_number: '2.0.0-beta', | ||
latest_stable_release_number: '1.8.3', | ||
} | ||
const config = { | ||
private: { | ||
librariesio_tokens: fakeApiKey, | ||
}, | ||
} | ||
const librariesIoApiProvider = new LibrariesIoApiProvider({ | ||
baseUrl: 'https://libraries.io/api', | ||
tokens: [fakeApiKey], | ||
}) | ||
|
||
it('sends the auth information as configured', async function () { | ||
const scope = nock('https://libraries.io/api') | ||
// This ensures that the expected credentials are actually being sent with the HTTP request. | ||
// Without this the request wouldn't match and the test would fail. | ||
.get(`/bower/bootstrap?api_key=${fakeApiKey}`) | ||
.reply(200, response) | ||
|
||
expect( | ||
await BowerVersion.invoke( | ||
{ | ||
...defaultContext, | ||
librariesIoApiProvider, | ||
}, | ||
config, | ||
{ | ||
platform: 'bower', | ||
packageName: 'bootstrap', | ||
}, | ||
{ | ||
include_prereleases: '', | ||
} | ||
) | ||
).to.deep.equal({ | ||
message: 'v2.0.0-beta', | ||
color: 'orange', | ||
label: undefined, | ||
}) | ||
|
||
scope.done() | ||
}) | ||
}) | ||
}) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { expect } from 'chai' | ||
import nock from 'nock' | ||
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js' | ||
import LibrariesIoSourcerank from './librariesio-sourcerank.service.js' | ||
import LibrariesIoApiProvider from './librariesio-api-provider.js' | ||
|
||
describe('LibrariesIoSourcerank', function () { | ||
cleanUpNockAfterEach() | ||
const fakeApiKey = 'fakeness' | ||
const response = { | ||
platform: 'npm', | ||
dependents_count: 150, | ||
dependent_repos_count: 191, | ||
rank: 100, | ||
} | ||
const config = { | ||
private: { | ||
librariesio_tokens: fakeApiKey, | ||
}, | ||
} | ||
const librariesIoApiProvider = new LibrariesIoApiProvider({ | ||
baseUrl: 'https://libraries.io/api', | ||
tokens: [fakeApiKey], | ||
}) | ||
|
||
it('sends the auth information as configured', async function () { | ||
const scope = nock('https://libraries.io/api') | ||
// This ensures that the expected credentials are actually being sent with the HTTP request. | ||
// Without this the request wouldn't match and the test would fail. | ||
.get(`/npm/badge-maker?api_key=${fakeApiKey}`) | ||
.reply(200, response) | ||
|
||
expect( | ||
await LibrariesIoSourcerank.invoke( | ||
{ | ||
...defaultContext, | ||
librariesIoApiProvider, | ||
}, | ||
config, | ||
{ | ||
platform: 'npm', | ||
packageName: 'badge-maker', | ||
} | ||
) | ||
).to.deep.equal({ | ||
message: 100, | ||
color: 'brightgreen', | ||
}) | ||
|
||
scope.done() | ||
}) | ||
}) |