2021-02-03 11:33:04 -05:00
|
|
|
import assert from 'assert';
|
2020-08-13 16:27:00 -05:00
|
|
|
import { Package } from '@verdaccio/types';
|
2021-09-25 17:08:00 -05:00
|
|
|
import { DIST_TAGS } from '@verdaccio/core';
|
2020-11-15 05:14:09 -05:00
|
|
|
import { normalizePackage, mergeUplinkTimeIntoLocal, STORAGE } from '../src/storage-utils';
|
2018-06-14 15:44:06 -05:00
|
|
|
|
2021-02-03 11:33:04 -05:00
|
|
|
import { tagVersion } from '../src/storage-utils';
|
2020-08-13 16:27:00 -05:00
|
|
|
import { readFile } from './fixtures/test.utils';
|
2018-06-14 15:44:06 -05:00
|
|
|
|
|
|
|
describe('Storage Utils', () => {
|
2018-06-15 00:55:30 -05:00
|
|
|
describe('normalizePackage', () => {
|
|
|
|
test('normalizePackage clean', () => {
|
|
|
|
const pkg = normalizePackage({
|
|
|
|
_attachments: {},
|
|
|
|
_distfiles: {},
|
|
|
|
_rev: '',
|
|
|
|
_uplinks: {},
|
|
|
|
name: '',
|
|
|
|
versions: {},
|
2020-03-03 17:59:19 -05:00
|
|
|
[DIST_TAGS]: {},
|
2018-06-15 00:55:30 -05: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 01:40:01 -05:00
|
|
|
// @ts-ignore
|
2020-03-03 17:59:19 -05:00
|
|
|
const pkg = normalizePackage(readFile('metadata'));
|
2018-06-15 00:55:30 -05: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);
|
2018-06-14 15:44:06 -05:00
|
|
|
});
|
|
|
|
|
2018-06-15 00:55:30 -05:00
|
|
|
test('normalizePackage partial default revision', () => {
|
2019-07-16 01:40:01 -05:00
|
|
|
// @ts-ignore
|
2020-03-03 17:59:19 -05:00
|
|
|
const pkg = normalizePackage(readFile('metadata'));
|
2018-06-15 00:55:30 -05:00
|
|
|
expect(pkg).toBeDefined();
|
|
|
|
expect(pkg._rev).toBeDefined();
|
2018-10-02 00:47:46 -05:00
|
|
|
expect(pkg._rev).toBe(STORAGE.DEFAULT_REVISION);
|
2018-06-15 00:55:30 -05:00
|
|
|
});
|
2018-06-14 15:44:06 -05:00
|
|
|
});
|
|
|
|
|
2018-06-15 00:55:30 -05:00
|
|
|
describe('mergeTime', () => {
|
|
|
|
const vGroup1 = {
|
2020-08-13 16:27:00 -05: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 00:55:30 -05:00
|
|
|
};
|
|
|
|
const vGroup2 = {
|
2020-08-13 16:27:00 -05:00
|
|
|
'1.0.6': '2018-06-07T05:50:21.505Z',
|
|
|
|
'1.0.7': '2018-06-12T20:35:07.621Z',
|
2018-06-15 00:55:30 -05:00
|
|
|
};
|
|
|
|
test('mergeTime basic', () => {
|
|
|
|
const pkg1: Package = {
|
|
|
|
_attachments: {},
|
|
|
|
_distfiles: {},
|
|
|
|
_rev: '',
|
|
|
|
_uplinks: {},
|
|
|
|
time: {
|
2020-08-13 16:27:00 -05:00
|
|
|
modified: '2018-06-13T06:44:45.747Z',
|
|
|
|
created: '2018-06-07T05:50:21.505Z',
|
|
|
|
...vGroup1,
|
2018-06-15 00:55:30 -05:00
|
|
|
},
|
|
|
|
name: '',
|
|
|
|
versions: {},
|
2020-03-03 17:59:19 -05:00
|
|
|
[DIST_TAGS]: {},
|
2018-06-15 00:55:30 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const pkg2: Package = {
|
|
|
|
_attachments: {},
|
|
|
|
_distfiles: {},
|
|
|
|
_rev: '',
|
|
|
|
_uplinks: {},
|
|
|
|
name: '',
|
|
|
|
time: {
|
2020-08-13 16:27:00 -05:00
|
|
|
modified: '2019-06-13T06:44:45.747Z',
|
|
|
|
created: '2019-06-07T05:50:21.505Z',
|
|
|
|
...vGroup2,
|
2018-06-15 00:55:30 -05:00
|
|
|
},
|
|
|
|
versions: {},
|
2020-03-03 17:59:19 -05:00
|
|
|
[DIST_TAGS]: {},
|
2018-06-15 00:55:30 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const mergedPkg = mergeUplinkTimeIntoLocal(pkg1, pkg2);
|
2020-09-16 23:48:16 -05:00
|
|
|
expect(Object.keys(mergedPkg)).toEqual([
|
|
|
|
'modified',
|
|
|
|
'created',
|
|
|
|
...Object.keys(vGroup1),
|
|
|
|
...Object.keys(vGroup2),
|
|
|
|
]);
|
2018-06-15 00:55:30 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('mergeTime remote empty', () => {
|
|
|
|
const pkg1: Package = {
|
|
|
|
_attachments: {},
|
|
|
|
_distfiles: {},
|
|
|
|
_rev: '',
|
|
|
|
_uplinks: {},
|
|
|
|
name: '',
|
|
|
|
time: {
|
2020-08-13 16:27:00 -05:00
|
|
|
modified: '2018-06-13T06:44:45.747Z',
|
|
|
|
created: '2018-06-07T05:50:21.505Z',
|
|
|
|
...vGroup1,
|
2018-06-15 00:55:30 -05:00
|
|
|
},
|
|
|
|
versions: {},
|
2020-03-03 17:59:19 -05:00
|
|
|
[DIST_TAGS]: {},
|
2018-06-15 00:55:30 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const pkg2: Package = {
|
|
|
|
_attachments: {},
|
|
|
|
_distfiles: {},
|
|
|
|
_rev: '',
|
|
|
|
_uplinks: {},
|
|
|
|
name: '',
|
|
|
|
versions: {},
|
2020-03-03 17:59:19 -05:00
|
|
|
[DIST_TAGS]: {},
|
2018-06-15 00:55:30 -05:00
|
|
|
};
|
|
|
|
const mergedPkg = mergeUplinkTimeIntoLocal(pkg1, pkg2);
|
2020-08-13 16:27:00 -05:00
|
|
|
expect(Object.keys(mergedPkg)).toEqual(['modified', 'created', ...Object.keys(vGroup1)]);
|
2018-06-15 00:55:30 -05:00
|
|
|
});
|
2018-06-14 15:44:06 -05:00
|
|
|
});
|
2021-02-03 11:33:04 -05:00
|
|
|
|
|
|
|
describe('tagVersion', () => {
|
|
|
|
test('add new one', () => {
|
|
|
|
let pkg = {
|
|
|
|
versions: {},
|
|
|
|
'dist-tags': {},
|
|
|
|
};
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
assert(tagVersion(pkg, '1.1.1', 'foo', {}));
|
|
|
|
assert.deepEqual(pkg, {
|
|
|
|
versions: {},
|
|
|
|
'dist-tags': { foo: '1.1.1' },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('add (compat)', () => {
|
|
|
|
const x = {
|
|
|
|
versions: {},
|
|
|
|
'dist-tags': { foo: '1.1.0' },
|
|
|
|
};
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
assert(tagVersion(x, '1.1.1', 'foo'));
|
|
|
|
assert.deepEqual(x, {
|
|
|
|
versions: {},
|
|
|
|
'dist-tags': { foo: '1.1.1' },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('add fresh tag', () => {
|
|
|
|
let x = {
|
|
|
|
versions: {},
|
|
|
|
'dist-tags': { foo: '1.1.0' },
|
|
|
|
};
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
assert(tagVersion(x, '1.1.1', 'foo'));
|
|
|
|
assert.deepEqual(x, {
|
|
|
|
versions: {},
|
|
|
|
'dist-tags': { foo: '1.1.1' },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-06-14 15:44:06 -05:00
|
|
|
});
|