mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
test: add unit test merge time method
This commit is contained in:
parent
07eece71ac
commit
c01cc4b851
3 changed files with 115 additions and 35 deletions
|
@ -180,7 +180,7 @@ export function checkPackageRemote(name: string, isAllowPublishOffline: boolean,
|
|||
});
|
||||
}
|
||||
|
||||
export function mergeTime(localMetadata: Package, remoteMetadata: Package) {
|
||||
export function mergeUplinkTimeIntoLocal(localMetadata: Package, remoteMetadata: Package): any {
|
||||
if ('time' in remoteMetadata) {
|
||||
return Object.assign({}, localMetadata.time, remoteMetadata.time);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import Search from './search';
|
|||
import LocalStorage from './local-storage';
|
||||
import {ReadTarball} from '@verdaccio/streams';
|
||||
import {checkPackageLocal, publishPackage, checkPackageRemote, cleanUpLinksRef,
|
||||
mergeTime, generatePackageTemplate} from './storage-utils';
|
||||
mergeUplinkTimeIntoLocal, generatePackageTemplate} from './storage-utils';
|
||||
import {setupUpLinks, updateVersionsHiddenUpLink} from './uplink-util';
|
||||
import {mergeVersions} from './metadata-utils';
|
||||
import {ErrorCode, normalizeDistTags, validate_metadata, isObject, DIST_TAGS} from './utils';
|
||||
|
@ -456,7 +456,7 @@ class Storage implements IStorageHandler {
|
|||
fetched: Date.now(),
|
||||
};
|
||||
|
||||
packageInfo.time = mergeTime(packageInfo, upLinkResponse);
|
||||
packageInfo.time = mergeUplinkTimeIntoLocal(packageInfo, upLinkResponse);
|
||||
|
||||
updateVersionsHiddenUpLink(upLinkResponse.versions, upLink);
|
||||
|
||||
|
|
|
@ -1,46 +1,126 @@
|
|||
// @flow
|
||||
|
||||
import {DEFAULT_REVISION, normalizePackage} from "../../src/lib/storage-utils";
|
||||
import {DEFAULT_REVISION, normalizePackage, mergeUplinkTimeIntoLocal} from "../../src/lib/storage-utils";
|
||||
import {DIST_TAGS} from "../../src/lib/utils";
|
||||
import {readFile} from "../functional/lib/test.utils";
|
||||
|
||||
import type {Package} from '@verdaccio/types';
|
||||
|
||||
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]: {},
|
||||
describe('normalizePackage', () => {
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
describe('mergeTime', () => {
|
||||
const vGroup1 = {
|
||||
"1.0.15": "2018-06-12T23:15:05.864Z",
|
||||
"1.0.16": "2018-06-12T23:17:46.578Z",
|
||||
"1.0.17": "2018-06-12T23:20:59.106Z"
|
||||
};
|
||||
const vGroup2 = {
|
||||
"1.0.6": "2018-06-07T05:50:21.505Z",
|
||||
"1.0.7": "2018-06-12T20:35:07.621Z"
|
||||
};
|
||||
test('mergeTime basic', () => {
|
||||
const pkg1: Package = {
|
||||
_attachments: {},
|
||||
_distfiles: {},
|
||||
_rev: '',
|
||||
_uplinks: {},
|
||||
time: {
|
||||
"modified": "2018-06-13T06:44:45.747Z",
|
||||
"created": "2018-06-07T05:50:21.505Z",
|
||||
...vGroup1
|
||||
},
|
||||
name: '',
|
||||
versions: {},
|
||||
[DIST_TAGS]: {},
|
||||
};
|
||||
|
||||
test('normalizePackage partial default revision', () => {
|
||||
const pkg = normalizePackage(readMetadata('metadata'));
|
||||
expect(pkg).toBeDefined();
|
||||
expect(pkg._rev).toBeDefined();
|
||||
expect(pkg._rev).toBe(DEFAULT_REVISION);
|
||||
const pkg2: Package = {
|
||||
_attachments: {},
|
||||
_distfiles: {},
|
||||
_rev: '',
|
||||
_uplinks: {},
|
||||
name: '',
|
||||
time: {
|
||||
"modified": "2019-06-13T06:44:45.747Z",
|
||||
"created": "2019-06-07T05:50:21.505Z",
|
||||
...vGroup2
|
||||
},
|
||||
versions: {},
|
||||
[DIST_TAGS]: {},
|
||||
};
|
||||
|
||||
const mergedPkg = mergeUplinkTimeIntoLocal(pkg1, pkg2);
|
||||
expect(Object.keys(mergedPkg)).toEqual(["modified", "created",
|
||||
...Object.keys(vGroup1), ...Object.keys(vGroup2)]);
|
||||
});
|
||||
|
||||
test('mergeTime remote empty', () => {
|
||||
const pkg1: Package = {
|
||||
_attachments: {},
|
||||
_distfiles: {},
|
||||
_rev: '',
|
||||
_uplinks: {},
|
||||
name: '',
|
||||
time: {
|
||||
"modified": "2018-06-13T06:44:45.747Z",
|
||||
"created": "2018-06-07T05:50:21.505Z",
|
||||
...vGroup1
|
||||
},
|
||||
versions: {},
|
||||
[DIST_TAGS]: {},
|
||||
};
|
||||
|
||||
const pkg2: Package = {
|
||||
_attachments: {},
|
||||
_distfiles: {},
|
||||
_rev: '',
|
||||
_uplinks: {},
|
||||
name: '',
|
||||
versions: {},
|
||||
[DIST_TAGS]: {},
|
||||
};
|
||||
const mergedPkg = mergeUplinkTimeIntoLocal(pkg1, pkg2);
|
||||
expect(Object.keys(mergedPkg)).toEqual(["modified", "created", ...Object.keys(vGroup1)]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue