mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-23 22:27:34 -05:00
154b2ecd34
* migrate api package * migrate auth * migrate config * refactor: remove @verdaccio/commons-api in favor @verdaccio/core * fix lint * relocate pkg * relocate pkg * fix tsconfig
65 lines
2 KiB
TypeScript
65 lines
2 KiB
TypeScript
import * as httpMocks from 'node-mocks-http';
|
|
import { HEADERS } from '@verdaccio/core';
|
|
import { convertDistRemoteToLocalTarballUrls } from '../src';
|
|
|
|
describe('convertDistRemoteToLocalTarballUrls', () => {
|
|
const fakeHost = 'fake.com';
|
|
const buildURI = (host, version) => `http://${host}/npm_test/-/npm_test-${version}.tgz`;
|
|
const cloneMetadata = (pkg = metadata) => Object.assign({}, pkg);
|
|
const metadata: any = {
|
|
name: 'npm_test',
|
|
versions: {
|
|
'1.0.0': {
|
|
dist: {
|
|
tarball: 'http://registry.org/npm_test/-/npm_test-1.0.0.tgz',
|
|
},
|
|
},
|
|
'1.0.1': {
|
|
dist: {
|
|
tarball: 'http://registry.org/npm_test/-/npm_test-1.0.1.tgz',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
test('should build a URI for dist tarball based on new domain', () => {
|
|
const req = httpMocks.createRequest({
|
|
method: 'GET',
|
|
headers: {
|
|
host: fakeHost,
|
|
[HEADERS.FORWARDED_PROTO]: 'http',
|
|
},
|
|
url: '/',
|
|
});
|
|
const convertDist = convertDistRemoteToLocalTarballUrls(cloneMetadata(), req);
|
|
expect(convertDist.versions['1.0.0'].dist.tarball).toEqual(buildURI(fakeHost, '1.0.0'));
|
|
expect(convertDist.versions['1.0.1'].dist.tarball).toEqual(buildURI(fakeHost, '1.0.1'));
|
|
});
|
|
|
|
test('should return same URI whether host is missing', () => {
|
|
const req = httpMocks.createRequest({
|
|
method: 'GET',
|
|
headers: {
|
|
host: 'http',
|
|
},
|
|
url: '/',
|
|
});
|
|
const convertDist = convertDistRemoteToLocalTarballUrls(cloneMetadata(), req);
|
|
expect(convertDist.versions['1.0.0'].dist.tarball).toEqual(
|
|
convertDist.versions['1.0.0'].dist.tarball
|
|
);
|
|
});
|
|
|
|
test('should return same URI whether host is undefined', () => {
|
|
const req = httpMocks.createRequest({
|
|
method: 'GET',
|
|
headers: {
|
|
host: undefined,
|
|
},
|
|
url: '/',
|
|
});
|
|
const convertDist = convertDistRemoteToLocalTarballUrls(cloneMetadata(), req);
|
|
expect(convertDist.versions['1.0.0'].dist.tarball).toEqual(
|
|
convertDist.versions['1.0.0'].dist.tarball
|
|
);
|
|
});
|
|
});
|