mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-04-08 02:54:13 -05:00
test: add unit test for utilities
This commit is contained in:
parent
7237ab340f
commit
37d2aa8d49
3 changed files with 72 additions and 33 deletions
|
@ -1,6 +1,8 @@
|
|||
// @flow
|
||||
import {stringToMD5} from './string';
|
||||
|
||||
|
||||
export const GRAVATAR_DEFAULT = 'https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mm';
|
||||
/**
|
||||
* Generate gravatar url from email address
|
||||
*/
|
||||
|
@ -11,6 +13,6 @@ export function generateGravatarUrl(email?: string): string {
|
|||
|
||||
return `https://www.gravatar.com/avatar/${emailMD5}`;
|
||||
} else {
|
||||
return 'https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mm';
|
||||
return GRAVATAR_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
// @flow
|
||||
import _ from 'lodash';
|
||||
import ProxyStorage from '../../src/lib/up-storage';
|
||||
import AppConfig from '../../src/lib/config';
|
||||
import _ from 'lodash';
|
||||
// $FlowFixMe
|
||||
import configExample from './partials/config';
|
||||
import {setup} from '../../src/lib/logger';
|
||||
|
||||
import type {Config, UpLinkConf} from '@verdaccio/types';
|
||||
import type {IProxy} from '../../types';
|
||||
|
||||
|
|
|
@ -1,42 +1,78 @@
|
|||
let assert = require('assert');
|
||||
let validate = require('../../src/lib/utils').validate_name;
|
||||
// @flow
|
||||
|
||||
describe('Validate', () => {
|
||||
test('good ones', () => {
|
||||
assert( validate('verdaccio') );
|
||||
assert( validate('some.weird.package-zzz') );
|
||||
assert( validate('old-package@0.1.2.tgz') );
|
||||
import assert from 'assert';
|
||||
import {validate_name as validate} from '../../src/lib/utils';
|
||||
import {generateGravatarUrl, GRAVATAR_DEFAULT} from '../../src/utils/user';
|
||||
import {spliceURL} from '../../src/utils/string';
|
||||
|
||||
describe('Utilities', () => {
|
||||
|
||||
describe('String utilities', () => {
|
||||
test('should splice two strings and generate a url', () => {
|
||||
const url: string = spliceURL('http://domain.com', '/-/static/logo.png');
|
||||
|
||||
expect(url).toMatch('http://domain.com/-/static/logo.png');
|
||||
});
|
||||
|
||||
test('should splice a empty strings and generate a url', () => {
|
||||
const url: string = spliceURL('', '/-/static/logo.png');
|
||||
|
||||
expect(url).toMatch('/-/static/logo.png');
|
||||
});
|
||||
});
|
||||
|
||||
test('uppercase', () => {
|
||||
assert( validate('EVE') );
|
||||
assert( validate('JSONStream') );
|
||||
describe('User utilities', () => {
|
||||
test('should generate gravatar url with email', () => {
|
||||
const gravatarUrl: string = generateGravatarUrl('user@verdaccio.org');
|
||||
|
||||
expect(gravatarUrl).toMatch('https://www.gravatar.com/avatar/');
|
||||
expect(gravatarUrl).not.toMatch('000000000');
|
||||
});
|
||||
|
||||
test('should generate generic gravatar url', () => {
|
||||
const gravatarUrl: string = generateGravatarUrl();
|
||||
|
||||
expect(gravatarUrl).toMatch(GRAVATAR_DEFAULT);
|
||||
});
|
||||
});
|
||||
|
||||
test('no package.json', () => {
|
||||
assert( !validate('package.json') );
|
||||
});
|
||||
describe('Validations', () => {
|
||||
test('good ones', () => {
|
||||
assert( validate('verdaccio') );
|
||||
assert( validate('some.weird.package-zzz') );
|
||||
assert( validate('old-package@0.1.2.tgz') );
|
||||
});
|
||||
|
||||
test('no path seps', () => {
|
||||
assert( !validate('some/thing') );
|
||||
assert( !validate('some\\thing') );
|
||||
});
|
||||
test('uppercase', () => {
|
||||
assert( validate('EVE') );
|
||||
assert( validate('JSONStream') );
|
||||
});
|
||||
|
||||
test('no hidden', () => {
|
||||
assert( !validate('.bin') );
|
||||
});
|
||||
test('no package.json', () => {
|
||||
assert( !validate('package.json') );
|
||||
});
|
||||
|
||||
test('no reserved', () => {
|
||||
assert( !validate('favicon.ico') );
|
||||
assert( !validate('node_modules') );
|
||||
assert( !validate('__proto__') );
|
||||
});
|
||||
test('no path seps', () => {
|
||||
assert( !validate('some/thing') );
|
||||
assert( !validate('some\\thing') );
|
||||
});
|
||||
|
||||
test('other', () => {
|
||||
assert( !validate('pk g') );
|
||||
assert( !validate('pk\tg') );
|
||||
assert( !validate('pk%20g') );
|
||||
assert( !validate('pk+g') );
|
||||
assert( !validate('pk:g') );
|
||||
test('no hidden', () => {
|
||||
assert( !validate('.bin') );
|
||||
});
|
||||
|
||||
test('no reserved', () => {
|
||||
assert( !validate('favicon.ico') );
|
||||
assert( !validate('node_modules') );
|
||||
assert( !validate('__proto__') );
|
||||
});
|
||||
|
||||
test('other', () => {
|
||||
assert( !validate('pk g') );
|
||||
assert( !validate('pk\tg') );
|
||||
assert( !validate('pk%20g') );
|
||||
assert( !validate('pk+g') );
|
||||
assert( !validate('pk:g') );
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue