0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

refactor: add tags test

This commit is contained in:
Juan Picado @jotadeveloper 2018-06-23 11:51:58 +02:00
parent 1294477ff3
commit 40f2aa46b1
No known key found for this signature in database
GPG key ID: 18AC54485952D158
5 changed files with 64 additions and 36 deletions

View file

@ -48,6 +48,7 @@ export const API_ERROR = {
CONTENT_MISMATCH: 'content length mismatch',
NOT_FILE_UPLINK: 'file doesn\'t exist on uplink',
MAX_USERS_REACHED: 'maximum amount of users reached',
VERSION_NOT_EXIST: 'this version doesn\'t exist',
};
export const DEFAULT_NO_README = 'ERROR: No README data found!';

View file

@ -34,6 +34,7 @@ IUploadTarball,
IReadTarball,
} from '@verdaccio/streams';
import type {IStorage, StringValue} from '../../types';
import {API_ERROR} from './constants';
/**
* Implements Storage interface (same for storage.js, local-storage.js, up-storage.js).
@ -298,7 +299,7 @@ class LocalStorage implements IStorage {
* @private
*/
_getVersionNotFound() {
return ErrorCode.getNotFound('this version doesn\'t exist');
return ErrorCode.getNotFound(API_ERROR.VERSION_NOT_EXIST);
}
/**

View file

@ -1,8 +1,8 @@
import {createTarballHash} from "../../../src/lib/crypto-utils";
import {HTTP_STATUS} from "../../../src/lib/constants";
import fs from 'fs';
import path from 'path';
import {TARBALL} from '../config.func';
import {HTTP_STATUS} from "../../../src/lib/constants";
import {createTarballHash} from "../../../src/lib/crypto-utils";
function readfile(filePath) {
const folder = path.join(__dirname , filePath);

View file

@ -1,44 +1,69 @@
import {readFile} from '../lib/test.utils';
import {HTTP_STATUS} from "../../../src/lib/constants";
import {API_ERROR, HTTP_STATUS} from "../../../src/lib/constants";
const readTags = () => readFile('../fixtures/publish.json5');
export default function(server) {
test('add tag - 404', () => {
return server.addTag('testpkg-tag', 'tagtagtag', '0.0.1')
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such package/);
});
describe('addtag', () => {
beforeAll(function() {
return server.putPackage('testpkg-tag', eval(
'(' + readTags()
.toString('utf8')
.replace(/__NAME__/g, 'testpkg-tag')
.replace(/__VERSION__/g, '0.0.1')
+ ')'
)).status(HTTP_STATUS.CREATED);
describe('should test add tag', () => {
const PKG_NAME = 'testpkg-tag';
const PKG_VERSION = '0.0.1';
test('should fails on add tag to non existing package', () => {
return server.addTag(PKG_NAME, 'tagtagtag', PKG_VERSION)
.status(HTTP_STATUS.NOT_FOUND).body_error(API_ERROR.NO_PACKAGE);
});
test('add testpkg-tag', () => {});
describe('should test add tag to a package', () => {
beforeAll(function() {
return server.putPackage(PKG_NAME, eval(
'(' + readTags()
.toString('utf8')
.replace(/__NAME__/g, PKG_NAME)
.replace(/__VERSION__/g, PKG_VERSION)
+ ')'
)).status(HTTP_STATUS.CREATED);
});
test('should fails on add non semver version tag ', () => {
return server.addTag('testpkg-tag', 'tagtagtag', '0.0.1-x')
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/version doesn't exist/);
});
describe('should test valid formats tags', () => {
test('should fails on add a tag that do not exist', () => {
return server.addTag(PKG_NAME, 'tagtagtag', '4.0.0-no-exist')
.status(HTTP_STATUS.NOT_FOUND)
.body_error(API_ERROR.VERSION_NOT_EXIST);
});
test('add tag - bad tag', () => {
return server.addTag('testpkg-tag', 'tag/tag/tag', '0.0.1-x')
.status(HTTP_STATUS.FORBIDDEN)
.body_error(/invalid tag/);
});
test('should add tag succesfully minor version', () => {
return server.addTag(PKG_NAME, 'tagtagtag', PKG_VERSION)
.status(HTTP_STATUS.CREATED)
.body_ok(/tagged/);
});
});
test('add tag - good', () => {
return server.addTag('testpkg-tag', 'tagtagtag', '0.0.1')
.status(HTTP_STATUS.CREATED)
.body_ok(/tagged/);
describe('should test handle invalid tag and version names', () => {
const INVALID_TAG ='tag/tag/tag';
const handleInvalidTag = function handleInvalidTag(tag, version) {
return server.addTag(PKG_NAME, tag, version)
.status(HTTP_STATUS.FORBIDDEN)
.body_error(/invalid tag/);
};
test('should fails on add tag for bad format', () => {
return handleInvalidTag(INVALID_TAG, '0.0.1-x');
});
test('should fails on add tag for bad format negative version', () => {
return handleInvalidTag(INVALID_TAG, '-0.0.1');
});
test('should fails on add tag for bad format empty version', () => {
return handleInvalidTag(INVALID_TAG, '');
});
test('should fails on add tag for bad format symbols', () => {
return handleInvalidTag(INVALID_TAG, '%^$%&$%^%$$#@');
});
});
});
});
}

View file

@ -3,8 +3,9 @@ import _ from 'lodash';
import rimRaf from 'rimraf';
import path from 'path';
import {fork} from 'child_process';
import type {IVerdaccioConfig, IServerBridge, IServerProcess} from '../types';
import {CREDENTIALS} from '../functional/config.func';
import {HTTP_STATUS} from '../../src/lib/constants';
import type {IVerdaccioConfig, IServerBridge, IServerProcess} from '../types';
export default class VerdaccioProcess implements IServerProcess {
@ -46,9 +47,9 @@ export default class VerdaccioProcess implements IServerProcess {
this.childFork.on('message', (msg) => {
if ('verdaccio_started' in msg) {
this.bridge.debug().status(200).then((body) => {
this.bridge.debug().status(HTTP_STATUS.OK).then((body) => {
this.bridge.auth(CREDENTIALS.user, CREDENTIALS.password)
.status(201)
.status(HTTP_STATUS.CREATED)
.body_ok(new RegExp(CREDENTIALS.user))
.then(() => {
resolve([this, body.pid]);