0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-20 22:52:46 -05:00

Merge pull request #759 from verdaccio/fix-758

fix: normalize package was broken #758
This commit is contained in:
Juan Picado @jotadeveloper 2018-06-15 06:11:04 +02:00 committed by GitHub
commit ace1d76bf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 3 deletions

View file

@ -11,7 +11,7 @@ import type {IStorage} from '../../types';
const pkgFileName = 'package.json';
const fileExist: string = 'EEXISTS';
const noSuchFile: string = 'ENOENT';
const DEFAULT_REVISION: string = `0-0000000000000000`;
export const DEFAULT_REVISION: string = `0-0000000000000000`;
const generatePackageTemplate = function(name: string): Package {
return {
@ -41,7 +41,9 @@ function normalizePackage(pkg: Package) {
'time'];
pkgProperties.forEach((key) => {
if (_.isNil(isObject(pkg[key]))) {
const pkgProp = pkg[key];
if (_.isNil(pkgProp) || isObject(pkgProp) === false) {
pkg[key] = {};
}
});
@ -221,7 +223,6 @@ export {
generateRevision,
getLatestReadme,
cleanUpReadme,
DEFAULT_REVISION,
fileExist,
noSuchFile,
pkgFileName,

View file

@ -0,0 +1,46 @@
// @flow
import {DEFAULT_REVISION, normalizePackage} from "../../src/lib/storage-utils";
import {DIST_TAGS} from "../../src/lib/utils";
import {readFile} from "../functional/lib/test.utils";
const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`);
describe('Storage Utils', () => {
test('normalizePackage clean', () => {
const pkg = normalizePackage({
_attachments: {},
_distfiles: {},
_rev: '',
_uplinks: {},
name: '',
versions: {},
[DIST_TAGS]: {},
});
expect(pkg).toBeDefined();
expect(pkg.time).toBeInstanceOf(Object);
expect(pkg.versions).toBeInstanceOf(Object);
expect(pkg[DIST_TAGS]).toBeInstanceOf(Object);
expect(pkg._distfiles).toBeInstanceOf(Object);
expect(pkg._attachments).toBeInstanceOf(Object);
expect(pkg._uplinks).toBeInstanceOf(Object);
});
test('normalizePackage partial metadata', () => {
const pkg = normalizePackage(readMetadata('metadata'));
expect(pkg).toBeDefined();
expect(pkg.time).toBeInstanceOf(Object);
expect(pkg.versions).toBeInstanceOf(Object);
expect(pkg[DIST_TAGS]).toBeInstanceOf(Object);
expect(pkg._distfiles).toBeInstanceOf(Object);
expect(pkg._attachments).toBeInstanceOf(Object);
expect(pkg._uplinks).toBeInstanceOf(Object);
});
test('normalizePackage partial default revision', () => {
const pkg = normalizePackage(readMetadata('metadata'));
expect(pkg).toBeDefined();
expect(pkg._rev).toBeDefined();
expect(pkg._rev).toBe(DEFAULT_REVISION);
});
});