0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-20 22:52:46 -05:00

refactor: update jetst match

using more consntants
This commit is contained in:
Juan Picado @jotadeveloper 2018-06-21 08:10:33 +02:00
parent 55927d5408
commit 2c8c8f0295
No known key found for this signature in database
GPG key ID: 18AC54485952D158
7 changed files with 73 additions and 55 deletions

View file

@ -17,10 +17,12 @@ export const DEFAULT_REGISTRY = 'https://registry.npmjs.org/';
export const HTTP_STATUS = {
INTERNAL_ERROR: 500,
SERVICE_UNAVAILABLE: 503,
OK: 200,
CREATED: 201,
BAD_REQUEST: 400,
UNAUTHORIZED: 401,
FORBIDDEN: 403,
NOT_FOUND: 404,
CONFLICT: 409,
};

View file

@ -1,3 +1,5 @@
import {HTTP_STATUS} from "../../../src/lib/constants";
export default function(server) {
describe('npm adduser', () => {
const user = String(Math.random());
@ -5,7 +7,7 @@ export default function(server) {
beforeAll(function() {
return server.auth(user, pass)
.status(201)
.status(HTTP_STATUS.CREATED)
.body_ok(/user .* created/);
});
@ -13,13 +15,13 @@ export default function(server) {
test('should log in', () => {
return server.auth(user, pass)
.status(201)
.status(HTTP_STATUS.CREATED)
.body_ok(/you are authenticated as/);
});
test('should not register more users', () => {
return server.auth(String(Math.random()), String(Math.random()))
.status(409)
.status(HTTP_STATUS.CONFLICT)
.body_error(/maximum amount of users reached/);
});
});

View file

@ -1,9 +1,11 @@
import {HTTP_STATUS} from "../../../src/lib/constants";
export default function(server) {
describe('logout', () => {
test('should log out', () => {
return server.logout('some-token')
.status(200)
.status(HTTP_STATUS.OK)
.body_ok(/Logged out/);
});
});

View file

@ -1,34 +1,39 @@
import assert from 'assert';
import crypto from 'crypto';
// @flow
import fs from 'fs';
import path from 'path';
import {createTarballHash} from "../../../src/lib/crypto-utils";
import {HTTP_STATUS} from "../../../src/lib/constants";
import {CREDENTIALS} from "../config.func";
import whoIam from './whoIam';
import ping from './ping';
function readfile(folderPath) {
return require('fs').readFileSync(__dirname + '/' + folderPath);
return fs.readFileSync(path.join(__dirname, '/', folderPath));
}
function getPackage(name) {
return require('../fixtures/package')(name);
}
function createHash() {
return crypto.createHash('sha1');
}
export default function(server, server2) {
export default function(server: any, server2: any) {
describe('basic test endpoints', () => {
const PKG_NAME:string = 'testpkg';
beforeAll(function() {
return server.auth('test', 'test')
.status(201)
return server.auth(CREDENTIALS.user, CREDENTIALS.password)
.status(HTTP_STATUS.CREATED)
.body_ok(/'test'/);
});
require('./whoIam')(server);
require('./ping')(server);
whoIam(server);
ping(server);
describe('handling packages', () => {
beforeAll(function () {
return server.addPackage('testpkg');
return server.addPackage(PKG_NAME);
});
beforeAll(function () {
@ -39,29 +44,31 @@ export default function(server, server2) {
});
test('downloading non-existent tarball', () => {
return server.getTarball('testpkg', 'blahblah').status(404).body_error(/no such file/);
return server.getTarball(PKG_NAME, 'blahblah')
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such file/);
});
test('uploading incomplete tarball', () => {
return server.putTarballIncomplete('testpkg', 'blahblah1', readfile('../fixtures/binary'), 3000);
return server.putTarballIncomplete(PKG_NAME, 'blahblah1', readfile('../fixtures/binary'), 3000);
});
describe('publishing package', () => {
beforeAll(function () {
return server.putTarball('testpkg', 'blahblah', readfile('../fixtures/binary'))
.status(201)
return server.putTarball(PKG_NAME, 'blahblah', readfile('../fixtures/binary'))
.status(HTTP_STATUS.CREATED)
.body_ok(/.*/);
});
beforeAll(function () {
return server.putTarball('testpkg-single-tarball', 'single', readfile('../fixtures/binary'))
.status(201)
.status(HTTP_STATUS.CREATED)
.body_ok(/.*/);
});
afterAll(function () {
return server.removeTarball('testpkg').status(201);
return server.removeTarball(PKG_NAME).status(HTTP_STATUS.CREATED);
});
test('remove a tarball', () => {
@ -73,46 +80,46 @@ export default function(server, server2) {
});
test('remove non existing tarball', () => {
return server.removeTarball('testpkg404').status(404);
return server.removeTarball('testpkg404').status(HTTP_STATUS.NOT_FOUND);
});
test('remove non existing single tarball', () => {
return server.removeSingleTarball('', 'fakeFile').status(404);
return server.removeSingleTarball('', 'fakeFile').status(HTTP_STATUS.NOT_FOUND);
});
// testexp-incomplete
test('remove existing single tarball', () => {
return server.removeSingleTarball('testpkg-single-tarball', 'single').status(201);
return server.removeSingleTarball('testpkg-single-tarball', 'single').status(HTTP_STATUS.CREATED);
});
// testexp-incomplete
test('downloading newly created tarball', () => {
return server.getTarball('testpkg', 'blahblah')
return server.getTarball(PKG_NAME, 'blahblah')
.status(200)
.then(function (body) {
assert.deepEqual(body, readfile('../fixtures/binary'));
expect(body).toEqual(readfile('../fixtures/binary'));
});
});
test('uploading new package version (bad sha)', () => {
let pkg = getPackage('testpkg');
pkg.dist.shasum = createHash().update('fake').digest('hex');
let pkg = getPackage(PKG_NAME);
pkg.dist.shasum = createTarballHash().update('fake').digest('hex');
return server.putVersion('testpkg', '0.0.1', pkg)
.status(400)
return server.putVersion(PKG_NAME, '0.0.1', pkg)
.status(HTTP_STATUS.BAD_REQUEST)
.body_error(/shasum error/);
});
describe('publishing version', () => {
beforeAll(function () {
const pkg = getPackage('testpkg');
const pkg = getPackage(PKG_NAME);
pkg.dist.shasum = createHash().update(readfile('../fixtures/binary')).digest('hex');
return server.putVersion('testpkg', '0.0.1', pkg)
.status(201)
pkg.dist.shasum = createTarballHash().update(readfile('../fixtures/binary')).digest('hex');
return server.putVersion(PKG_NAME, '0.0.1', pkg)
.status(HTTP_STATUS.CREATED)
.body_ok(/published/);
});
@ -123,31 +130,31 @@ export default function(server, server2) {
describe('should download a package', () => {
beforeAll(function() {
return server.auth('test', 'test')
.status(201)
.status(HTTP_STATUS.CREATED)
.body_ok(/'test'/);
});
test('should download a newly created package from server1', () => {
return server.getPackage('testpkg')
return server.getPackage(PKG_NAME)
.status(200)
.then(function (body) {
assert.equal(body.name, 'testpkg');
assert.equal(body.versions['0.0.1'].name, 'testpkg');
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/testpkg/-/blahblah');
assert.deepEqual(body['dist-tags'], {
expect(body.name).toEqual(PKG_NAME);
expect(body.versions['0.0.1'].name).toEqual(PKG_NAME);
expect(body.versions['0.0.1'].dist.tarball).toEqual('http://localhost:55551/testpkg/-/blahblah');
expect(body['dist-tags']).toEqual({
latest: '0.0.1'
});
});
});
test('should downloading a package from server2', () => {
return server2.getPackage('testpkg')
return server2.getPackage(PKG_NAME)
.status(200)
.then(function (body) {
assert.equal(body.name, 'testpkg');
assert.equal(body.versions['0.0.1'].name, 'testpkg');
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55552/testpkg/-/blahblah');
assert.deepEqual(body['dist-tags'], {
expect(body.name).toEqual(PKG_NAME);
expect(body.versions['0.0.1'].name).toEqual(PKG_NAME);
expect(body.versions['0.0.1'].dist.tarball).toEqual('http://localhost:55552/testpkg/-/blahblah');
expect(body['dist-tags']).toEqual({
latest: '0.0.1'
});
});
@ -163,27 +170,27 @@ export default function(server, server2) {
test('should fails trying to fetch non-existent package', () => {
return server.getPackage('testpkg').status(404).body_error(/no such package/);
return server.getPackage(PKG_NAME).status(HTTP_STATUS.NOT_FOUND).body_error(/no such package/);
});
test(
'should fails on publish a version for non existing package',
() => {
return server.putVersion('testpxg', '0.0.1', getPackage('testpxg'))
.status(404)
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such package/);
}
);
test('should be a package not found', () => {
return server.putTarball('nonExistingPackage', 'blahblah', readfile('../fixtures/binary'))
.status(404)
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such/);
});
test('should fails on publish package in a bad uplink', () => {
return server.putPackage('baduplink', getPackage('baduplink'))
.status(503)
.status(HTTP_STATUS.SERVICE_UNAVAILABLE)
.body_error(/one of the uplinks is down, refuse to publish/);
});

View file

@ -1,12 +1,11 @@
const assert = require('assert');
const _ = require('lodash');
import _ from 'lodash';
module.exports = function(server) {
test('ping', () => {
return server.ping().then(function (data) {
// it's always an empty object
assert.ok(_.isObject(data));
expect(_.isObject(data)).toBeDefined();
});
});

View file

@ -1,8 +1,10 @@
import {CREDENTIALS} from "../config.func";
module.exports = function(server) {
test('who am I?', () => {
return server.whoami().then(function (username) {
expect(username).toMatch('test');
expect(username).toMatch(CREDENTIALS.user);
});
});

View file

@ -0,0 +1,4 @@
export const CREDENTIALS = {
user: 'test',
password: 'test'
};