helpers.test.js 1.05 KB
/**
 * library helpers 类单元测试
 * @author jeff.jiang<jeff.jiang@yoho.cn>
 * @date 2016/05/17
 */

'use strict';

const test = require('ava');
const helpers = require('../../library/helpers');

test('qiniu image url handle', t => {
    let url = 'http://img11.static.yhbimg.com/yhb-img01/2016/04/18/03/016d50b20cfdec5a91c614b68546bc9d72.jpg?imageView2/{mode}/w/{width}/h/{height}';
    let expected = 'http://img11.static.yhbimg.com/yhb-img01/2016/04/18/03/016d50b20cfdec5a91c614b68546bc9d72.jpg?imageView2/2/w/400/h/300';

    t.is(helpers.image(url, 400, 300), expected);
});

test('uri format', t => {
    let uri = '/test';
    let qs = { name: 'yoho' };
    let mod = 'list';
    let expected = '//list.yohobuy.com/test?name=yoho';

    t.is(helpers.urlFormat(uri, qs, mod), expected);
});

test('upper char to lowercase', t => {
    let str = 'ABc';
    let expected = 'abc';

    t.is(helpers.lowerCase(str), expected);
});

test('lower char to uppercase', t => {
    let str = 'abc!';
    let expected = 'ABC!';

    t.is(helpers.upperCase(str), expected);
});