0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/test/unit/modules/storage/storage-utils.spec.ts
Juan Picado @jotadeveloper 66f4197236
feat: convert project to typescript (#1374)
* chore: test

* chore: add

* chore: more progress

* chore: progress in migration, fix prettier parser

* chore: reduce tsc errors

* chore: refactor storage utils types

* chore: refactor utils types

* chore: refactor local storage types

* chore: refactor config utils types

* chore: refactor tsc types

* refactor: apply eslint fix, tabs etc

* chore: fix lint errors

* test: update unit test conf to typescript setup

few test refactored to typescript

* chore: enable more unit test

migrate to typescript

* chore: migrate storage test to tsc

* chore: migrate up storage test to tsc

* refactor: enable plugin and auth test

* chore: migrate plugin loader test

* chore: update dependencies

* chore: migrate functional test to typescript

* chore: add codecove

* chore: update express

* chore: downgrade puppeteer

The latest version does not seems to work properly fine.

* chore: update dependencies
2019-07-16 08:40:01 +02:00

126 lines
3.7 KiB
TypeScript

import {normalizePackage, mergeUplinkTimeIntoLocal} from "../../../../src/lib/storage-utils";
import { STORAGE, DIST_TAGS } from '../../../../src/lib/constants';
import {readFile} from "../../../functional/lib/test.utils";
import {Package} from '@verdaccio/types';
const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`);
describe('Storage Utils', () => {
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', () => {
// @ts-ignore
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', () => {
// @ts-ignore
const pkg = normalizePackage(readMetadata('metadata'));
expect(pkg).toBeDefined();
expect(pkg._rev).toBeDefined();
expect(pkg._rev).toBe(STORAGE.DEFAULT_REVISION);
});
});
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]: {},
};
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)]);
});
});
});