Skip to content
Snippets Groups Projects
Unverified Commit 4437106c authored by Michael Kriese's avatar Michael Kriese Committed by GitHub
Browse files

test: add http mock (#11290)

parent 6ab6fba2
No related branches found
No related tags found
No related merge requests found
import * as httpMock from '../../test/http-mock';
import { getName, logger, mocked } from '../../test/util'; import { getName, logger, mocked } from '../../test/util';
import { import {
EXTERNAL_HOST_ERROR, EXTERNAL_HOST_ERROR,
...@@ -151,6 +152,11 @@ describe(getName(), () => { ...@@ -151,6 +152,11 @@ describe(getName(), () => {
}); });
}); });
it('ignores and warns for registryUrls', async () => { it('ignores and warns for registryUrls', async () => {
httpMock
.scope('https://galaxy.ansible.com')
.get('/api/v1/roles/')
.query({ owner__username: 'some', name: 'dep' })
.reply(200, {});
await datasource.getPkgReleases({ await datasource.getPkgReleases({
datasource: GalaxyDatasource.id, datasource: GalaxyDatasource.id,
depName: 'some.dep', depName: 'some.dep',
......
...@@ -2,37 +2,6 @@ ...@@ -2,37 +2,6 @@
exports[`platform/index escapes names 1`] = `"name [what]"`; exports[`platform/index escapes names 1`] = `"name [what]"`;
exports[`platform/index initializes 1`] = `
Object {
"endpoint": "https://api.bitbucket.org/",
"gitAuthor": "user@domain.com",
"hostRules": Array [
Object {
"hostType": "bitbucket",
"matchHost": "api.bitbucket.org",
"password": "123",
"username": "abc",
},
],
"platform": "bitbucket",
}
`;
exports[`platform/index initializes no author 1`] = `
Object {
"endpoint": "https://api.bitbucket.org/",
"hostRules": Array [
Object {
"hostType": "bitbucket",
"matchHost": "api.bitbucket.org",
"password": "123",
"username": "abc",
},
],
"platform": "bitbucket",
}
`;
exports[`platform/index parses bot email 1`] = ` exports[`platform/index parses bot email 1`] = `
Object { Object {
"address": "some[bot]@users.noreply.github.com", "address": "some[bot]@users.noreply.github.com",
......
import * as httpMock from '../../test/http-mock';
import { getName } from '../../test/util'; import { getName } from '../../test/util';
import { PLATFORM_NOT_FOUND } from '../constants/error-messages'; import { PLATFORM_NOT_FOUND } from '../constants/error-messages';
import { PLATFORM_TYPE_BITBUCKET } from '../constants/platforms'; import { PLATFORM_TYPE_BITBUCKET } from '../constants/platforms';
...@@ -45,24 +46,32 @@ describe(getName(), () => { ...@@ -45,24 +46,32 @@ describe(getName(), () => {
await expect(platform.initPlatform(config)).rejects.toThrow(); await expect(platform.initPlatform(config)).rejects.toThrow();
}); });
it('initializes', async () => { it('initializes', async () => {
httpMock
.scope('https://api.bitbucket.org')
.get('/2.0/user')
.basicAuth({ user: 'abc', pass: '123' })
.reply(200, { uuid: 123 });
const config = { const config = {
platform: PLATFORM_TYPE_BITBUCKET, platform: PLATFORM_TYPE_BITBUCKET,
gitAuthor: 'user@domain.com', gitAuthor: 'user@domain.com',
username: 'abc', username: 'abc',
password: '123', password: '123',
}; };
// FIXME: explicit assert condition expect(await platform.initPlatform(config)).toEqual({
expect(await platform.initPlatform(config)).toMatchSnapshot(); endpoint: 'https://api.bitbucket.org/',
}); gitAuthor: 'user@domain.com',
it('initializes no author', async () => { hostRules: [
const config = { {
platform: PLATFORM_TYPE_BITBUCKET, hostType: 'bitbucket',
username: 'abc', matchHost: 'api.bitbucket.org',
password: '123', password: '123',
}; username: 'abc',
// FIXME: explicit assert condition },
expect(await platform.initPlatform(config)).toMatchSnapshot(); ],
platform: PLATFORM_TYPE_BITBUCKET,
});
}); });
it('returns null if empty email given', () => { it('returns null if empty email given', () => {
expect(platform.parseGitAuthor(undefined)).toBeNull(); expect(platform.parseGitAuthor(undefined)).toBeNull();
}); });
......
// Check for missing or pending http mocks
import './http-mock';
jest.mock('../lib/platform', () => ({ jest.mock('../lib/platform', () => ({
platform: jest.createMockFromModule('../lib/platform/github'), platform: jest.createMockFromModule('../lib/platform/github'),
initPlatform: jest.fn(), initPlatform: jest.fn(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment