2018-02-19 19:29:14 +01:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
// $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-06-24 22:39:09 +02:00
|
|
|
import {mockServer} from './mock';
|
|
|
|
import {DOMAIN_SERVERS} from '../../functional/config.functional';
|
2018-02-19 19:29:14 +01:00
|
|
|
|
|
|
|
setup(configExample.logs);
|
|
|
|
|
2018-06-24 22:39:09 +02:00
|
|
|
const mockServerPort: number = 55548;
|
|
|
|
const generateStorage = async function(port = mockServerPort) {
|
2018-02-19 19:29:14 +01:00
|
|
|
const storageConfig = _.clone(configExample);
|
2018-06-24 22:39:09 +02:00
|
|
|
const storage = `./unit/partials/store/test-storage-store.spec`;
|
2018-02-19 19:29:14 +01:00
|
|
|
storageConfig.self_path = __dirname;
|
|
|
|
storageConfig.storage = storage;
|
2018-06-24 22:39:09 +02:00
|
|
|
storageConfig.uplinks = {
|
|
|
|
npmjs: {
|
|
|
|
url: `http://${DOMAIN_SERVERS}:${port}`
|
|
|
|
}
|
|
|
|
};
|
|
|
|
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-06-24 22:39:09 +02:00
|
|
|
return store;
|
2018-02-19 19:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('StorageTest', () => {
|
2018-06-24 22:39:09 +02:00
|
|
|
let mockRegistry;
|
2018-02-19 19:29:14 +01:00
|
|
|
|
2018-06-24 22:39:09 +02:00
|
|
|
beforeAll(async () => {
|
|
|
|
mockRegistry = await mockServer(mockServerPort).init();
|
|
|
|
});
|
2018-02-19 19:29:14 +01:00
|
|
|
|
2018-06-24 22:39:09 +02:00
|
|
|
afterAll(function(done) {
|
|
|
|
mockRegistry[0].stop();
|
|
|
|
done();
|
|
|
|
});
|
2018-02-19 19:29:14 +01:00
|
|
|
|
2018-06-24 22:39:09 +02:00
|
|
|
test('should be defined', async () => {
|
|
|
|
const storage: IStorageHandler = await generateStorage();
|
2018-02-19 19:29:14 +01:00
|
|
|
|
|
|
|
expect(storage).toBeDefined();
|
2018-06-24 22:39:09 +02:00
|
|
|
});
|
2018-02-19 19:29:14 +01:00
|
|
|
|
2018-06-24 22:39:09 +02:00
|
|
|
test('should fetch from uplink jquery metadata from nmpjs', async (done) => {
|
|
|
|
const storage: IStorageHandler = await generateStorage();
|
2018-02-19 19:29:14 +01:00
|
|
|
|
2018-06-24 22:39:09 +02:00
|
|
|
// $FlowFixMe
|
|
|
|
storage._syncUplinksMetadata('jquery', null, {}, (err, metadata, errors) => {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
expect(metadata).toBeDefined();
|
|
|
|
expect(metadata).toBeInstanceOf(Object);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-02-19 19:29:14 +01:00
|
|
|
|
2018-06-24 22:39:09 +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
|
|
|
|
2018-06-24 22:39:09 +02:00
|
|
|
// $FlowFixMe
|
|
|
|
storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, metadata, errors) => {
|
|
|
|
expect(err).not.toBeNull();
|
|
|
|
expect(errors).toBeInstanceOf(Array);
|
|
|
|
expect(errors[0][0].statusCode).toBe(404);
|
|
|
|
expect(errors[0][0].message).toMatch(API_ERROR.NOT_PACKAGE_UPLINK);
|
|
|
|
done();
|
|
|
|
});
|
2018-02-19 19:29:14 +01:00
|
|
|
});
|
|
|
|
});
|