0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00
verdaccio/test/functional/sanity/nullstorage.ts

90 lines
3.1 KiB
TypeScript
Raw Normal View History

import { readFile } from '../lib/test.utils';
import { createTarballHash } from '../../../src/lib/crypto-utils';
import { API_ERROR, HTTP_STATUS } from '../../../src/lib/constants';
import { DOMAIN_SERVERS, PORT_SERVER_1, TARBALL } from '../config.functional';
import generatePkg from '../fixtures/package';
import { DIST_TAGS } from '../../../src/lib/constants';
function getBinary() {
2017-12-02 05:19:08 -05:00
return readFile('../fixtures/binary');
}
2017-12-02 05:19:08 -05:00
export default function (server, server2) {
2018-06-23 01:35:06 -05:00
const PKG_NAME = 'test-nullstorage2';
const PKG_VERSION = '0.0.1';
2019-02-03 04:43:55 -05:00
// const TARBALL = `${PKG_NAME}-file.name`;
2018-06-23 01:35:06 -05:00
describe('should test a scenario when tarball is being fetch from uplink', () => {
describe(`should check whether ${PKG_NAME} is on server1`, () => {
test('should fails on fetch non-existent package on server1', () => {
return server
.getPackage('test-nullstorage-nonexist')
.status(HTTP_STATUS.NOT_FOUND)
.body_error(API_ERROR.NO_PACKAGE);
2017-04-19 14:15:28 -05:00
});
});
describe(`should check whether ${PKG_NAME} is on server2`, () => {
beforeAll(function () {
return server2.addPackage(PKG_NAME);
2017-04-19 14:15:28 -05:00
});
test('should create a new package on server2', () => {
/* test for before() */
});
test('should fails on download a non existent tarball from server1', () => {
return server
.getTarball(PKG_NAME, TARBALL)
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such file/);
2017-04-19 14:15:28 -05:00
});
describe(`should succesfully publish ${PKG_NAME} package on server2`, () => {
beforeAll(function () {
return server2
.putTarball(PKG_NAME, TARBALL, getBinary())
.status(HTTP_STATUS.CREATED)
.body_ok(/.*/);
});
beforeAll(function () {
let pkg = generatePkg(PKG_NAME);
pkg.dist.shasum = createTarballHash().update(getBinary()).digest('hex');
return server2
.putVersion(PKG_NAME, PKG_VERSION, pkg)
.status(HTTP_STATUS.CREATED)
.body_ok(/published/);
});
test(`should publish a new version for ${PKG_NAME} on server 2`, () => {
/* test for before() */
});
test(`should fetch the newly created published tarball for ${PKG_NAME} from server1 on server2`, () => {
return server
.getTarball(PKG_NAME, TARBALL)
.status(HTTP_STATUS.OK)
.then(function (body) {
expect(body).toEqual(getBinary());
});
});
test(`should fetch metadata for ${PKG_NAME} match from server1`, () => {
return server
.getPackage(PKG_NAME)
.status(HTTP_STATUS.OK)
.then(function (body) {
expect(body.name).toBe(PKG_NAME);
expect(body.versions[PKG_VERSION].name).toBe(PKG_NAME);
expect(body.versions[PKG_VERSION].dist.tarball).toBe(
`http://${DOMAIN_SERVERS}:${PORT_SERVER_1}/${PKG_NAME}/-/${TARBALL}`
);
expect(body[DIST_TAGS]).toEqual({ latest: PKG_VERSION });
});
});
2017-04-19 14:15:28 -05:00
});
});
2017-04-19 14:15:28 -05:00
});
2017-12-02 05:19:08 -05:00
}