2018-02-19 19:29:14 +01:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
import httpMocks from 'node-mocks-http';
|
|
|
|
// $FlowFixMe
|
2018-06-17 13:34:59 +02:00
|
|
|
import configExample from '../partials/config/index';
|
|
|
|
import AppConfig from '../../../src/lib/config';
|
|
|
|
import Storage from '../../../src/lib/storage';
|
|
|
|
import {setup} from '../../../src/lib/logger';
|
2018-02-19 19:29:14 +01:00
|
|
|
|
2018-02-26 21:28:09 +01:00
|
|
|
import type {Config} from '@verdaccio/types';
|
2018-06-17 13:34:59 +02:00
|
|
|
import type {IStorageHandler} from '../../../types/index';
|
2018-06-24 10:11:52 +02:00
|
|
|
import {API_ERROR} from '../../../src/lib/constants';
|
2018-02-19 19:29:14 +01:00
|
|
|
|
|
|
|
setup(configExample.logs);
|
|
|
|
|
2018-04-21 18:36:06 +02:00
|
|
|
const generateStorage = async function() {
|
2018-02-19 19:29:14 +01:00
|
|
|
const storageConfig = _.clone(configExample);
|
|
|
|
const storage = `./unit/partials/store/test-storage-store.spec`;
|
|
|
|
storageConfig.self_path = __dirname;
|
|
|
|
storageConfig.storage = storage;
|
|
|
|
const config: Config = new AppConfig(storageConfig);
|
2018-04-21 18:36:06 +02:00
|
|
|
const store: IStorageHandler = new Storage(config);
|
|
|
|
await store.init(config);
|
2018-02-19 19:29:14 +01:00
|
|
|
|
2018-04-21 18:36:06 +02:00
|
|
|
return store;
|
2018-02-19 19:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('StorageTest', () => {
|
|
|
|
|
2018-02-24 07:59:36 +01:00
|
|
|
jest.setTimeout(10000);
|
2018-02-19 19:29:14 +01:00
|
|
|
|
2018-04-21 18:36:06 +02:00
|
|
|
beforeAll(async (done)=> {
|
|
|
|
const storage: IStorageHandler = await generateStorage();
|
2018-02-19 19:29:14 +01:00
|
|
|
var request = httpMocks.createRequest({
|
|
|
|
method: 'GET',
|
|
|
|
url: '/react',
|
|
|
|
params: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
storage.getPackage({
|
|
|
|
name: 'react',
|
|
|
|
req: request,
|
|
|
|
callback: () => {
|
2018-03-17 11:54:57 +01:00
|
|
|
const stream = storage.getTarball('react', 'react-16.1.0.tgz');
|
2018-02-19 19:29:14 +01:00
|
|
|
stream.on('content-length', function(content) {
|
|
|
|
if (content) {
|
|
|
|
expect(content).toBeTruthy();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-21 18:36:06 +02:00
|
|
|
test('should be defined', async () => {
|
|
|
|
const storage: IStorageHandler = await generateStorage();
|
2018-02-19 19:29:14 +01:00
|
|
|
|
|
|
|
expect(storage).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2018-04-21 18:36:06 +02:00
|
|
|
test('should fetch from uplink react metadata from nmpjs', async (done) => {
|
|
|
|
const storage: IStorageHandler = await generateStorage();
|
2018-02-19 19:29:14 +01:00
|
|
|
|
|
|
|
// $FlowFixMe
|
|
|
|
storage._syncUplinksMetadata('react', null, {}, (err, metadata, errors) => {
|
|
|
|
expect(metadata).toBeInstanceOf(Object);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-21 18:36:06 +02:00
|
|
|
test('should fails on fetch from uplink metadata from nmpjs', async (done) => {
|
|
|
|
const storage: IStorageHandler = await generateStorage();
|
2018-02-19 19:29:14 +01:00
|
|
|
|
|
|
|
// $FlowFixMe
|
|
|
|
storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, metadata, errors) => {
|
|
|
|
expect(errors).toBeInstanceOf(Array);
|
|
|
|
expect(errors[0][0].statusCode).toBe(404);
|
2018-06-24 10:11:52 +02:00
|
|
|
expect(errors[0][0].message).toMatch(API_ERROR.NOT_PACKAGE_UPLINK);
|
2018-02-19 19:29:14 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|