2021-03-14 08:42:46 +01:00
|
|
|
import { normalizePackage, mergeUplinkTimeIntoLocal } from '../../../../src/lib/storage-utils';
|
2019-05-20 07:53:47 +02:00
|
|
|
import { STORAGE, DIST_TAGS } from '../../../../src/lib/constants';
|
2021-03-14 08:42:46 +01:00
|
|
|
import { readFile } from '../../../functional/lib/test.utils';
|
2018-06-14 22:44:06 +02:00
|
|
|
|
2021-03-14 08:42:46 +01:00
|
|
|
import { Package } from '@verdaccio/types';
|
2018-06-15 07:55:30 +02:00
|
|
|
|
2019-09-26 18:22:14 +02:00
|
|
|
const readMetadata = (fileName = 'metadata') => readFile(`../../unit/partials/${fileName}`);
|
2018-06-14 22:44:06 +02:00
|
|
|
|
|
|
|
describe('Storage Utils', () => {
|
2018-06-15 07:55:30 +02:00
|
|
|
describe('normalizePackage', () => {
|
|
|
|
test('normalizePackage clean', () => {
|
|
|
|
const pkg = normalizePackage({
|
|
|
|
_attachments: {},
|
|
|
|
_distfiles: {},
|
|
|
|
_rev: '',
|
|
|
|
_uplinks: {},
|
|
|
|
name: '',
|
|
|
|
versions: {},
|
2021-03-14 08:42:46 +01:00
|
|
|
[DIST_TAGS]: {}
|
2018-06-15 07:55:30 +02:00
|
|
|
});
|
|
|
|
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', () => {
|
2019-07-16 08:40:01 +02:00
|
|
|
// @ts-ignore
|
2018-06-15 07:55:30 +02:00
|
|
|
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);
|
2018-06-14 22:44:06 +02:00
|
|
|
});
|
|
|
|
|
2018-06-15 07:55:30 +02:00
|
|
|
test('normalizePackage partial default revision', () => {
|
2019-07-16 08:40:01 +02:00
|
|
|
// @ts-ignore
|
2018-06-15 07:55:30 +02:00
|
|
|
const pkg = normalizePackage(readMetadata('metadata'));
|
|
|
|
expect(pkg).toBeDefined();
|
|
|
|
expect(pkg._rev).toBeDefined();
|
2018-10-02 07:47:46 +02:00
|
|
|
expect(pkg._rev).toBe(STORAGE.DEFAULT_REVISION);
|
2018-06-15 07:55:30 +02:00
|
|
|
});
|
2018-06-14 22:44:06 +02:00
|
|
|
});
|
|
|
|
|
2018-06-15 07:55:30 +02:00
|
|
|
describe('mergeTime', () => {
|
|
|
|
const vGroup1 = {
|
2021-03-14 08:42:46 +01:00
|
|
|
'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'
|
2018-06-15 07:55:30 +02:00
|
|
|
};
|
|
|
|
const vGroup2 = {
|
2021-03-14 08:42:46 +01:00
|
|
|
'1.0.6': '2018-06-07T05:50:21.505Z',
|
|
|
|
'1.0.7': '2018-06-12T20:35:07.621Z'
|
2018-06-15 07:55:30 +02:00
|
|
|
};
|
|
|
|
test('mergeTime basic', () => {
|
|
|
|
const pkg1: Package = {
|
|
|
|
_attachments: {},
|
|
|
|
_distfiles: {},
|
|
|
|
_rev: '',
|
|
|
|
_uplinks: {},
|
|
|
|
time: {
|
2021-03-14 08:42:46 +01:00
|
|
|
modified: '2018-06-13T06:44:45.747Z',
|
|
|
|
created: '2018-06-07T05:50:21.505Z',
|
2018-06-15 07:55:30 +02:00
|
|
|
...vGroup1
|
|
|
|
},
|
|
|
|
name: '',
|
|
|
|
versions: {},
|
2021-03-14 08:42:46 +01:00
|
|
|
[DIST_TAGS]: {}
|
2018-06-15 07:55:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const pkg2: Package = {
|
|
|
|
_attachments: {},
|
|
|
|
_distfiles: {},
|
|
|
|
_rev: '',
|
|
|
|
_uplinks: {},
|
|
|
|
name: '',
|
|
|
|
time: {
|
2021-03-14 08:42:46 +01:00
|
|
|
modified: '2019-06-13T06:44:45.747Z',
|
|
|
|
created: '2019-06-07T05:50:21.505Z',
|
2018-06-15 07:55:30 +02:00
|
|
|
...vGroup2
|
|
|
|
},
|
|
|
|
versions: {},
|
2021-03-14 08:42:46 +01:00
|
|
|
[DIST_TAGS]: {}
|
2018-06-15 07:55:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const mergedPkg = mergeUplinkTimeIntoLocal(pkg1, pkg2);
|
2021-03-14 08:42:46 +01:00
|
|
|
expect(Object.keys(mergedPkg)).toEqual([
|
|
|
|
'modified',
|
|
|
|
'created',
|
|
|
|
...Object.keys(vGroup1),
|
|
|
|
...Object.keys(vGroup2)
|
|
|
|
]);
|
2018-06-15 07:55:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('mergeTime remote empty', () => {
|
|
|
|
const pkg1: Package = {
|
|
|
|
_attachments: {},
|
|
|
|
_distfiles: {},
|
|
|
|
_rev: '',
|
|
|
|
_uplinks: {},
|
|
|
|
name: '',
|
|
|
|
time: {
|
2021-03-14 08:42:46 +01:00
|
|
|
modified: '2018-06-13T06:44:45.747Z',
|
|
|
|
created: '2018-06-07T05:50:21.505Z',
|
2018-06-15 07:55:30 +02:00
|
|
|
...vGroup1
|
|
|
|
},
|
|
|
|
versions: {},
|
2021-03-14 08:42:46 +01:00
|
|
|
[DIST_TAGS]: {}
|
2018-06-15 07:55:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const pkg2: Package = {
|
|
|
|
_attachments: {},
|
|
|
|
_distfiles: {},
|
|
|
|
_rev: '',
|
|
|
|
_uplinks: {},
|
|
|
|
name: '',
|
|
|
|
versions: {},
|
2021-03-14 08:42:46 +01:00
|
|
|
[DIST_TAGS]: {}
|
2018-06-15 07:55:30 +02:00
|
|
|
};
|
|
|
|
const mergedPkg = mergeUplinkTimeIntoLocal(pkg1, pkg2);
|
2021-03-14 08:42:46 +01:00
|
|
|
expect(Object.keys(mergedPkg)).toEqual(['modified', 'created', ...Object.keys(vGroup1)]);
|
2018-06-15 07:55:30 +02:00
|
|
|
});
|
2018-06-14 22:44:06 +02:00
|
|
|
});
|
|
|
|
});
|