From 0e5ff97f6fdf9a4cebe5a15f5a390380465803ad Mon Sep 17 00:00:00 2001 From: BRAINS YUM <43896676+McFlat@users.noreply.github.com> Date: Sat, 13 Oct 2018 01:43:55 -0500 Subject: add parseBytes utility function and tests (#1239) * add parseBytes utility function and tests make it parse TB MB fix parseBytes; * 1024 test bytes too, and make parseByte to parse quotas add test in travis.sh in misc * fix parseBytes and test to pass linting --- server/tests/helpers/core-utils.ts | 48 ++++++++++++++++++++++++++++++++++++++ server/tests/helpers/index.ts | 1 + 2 files changed, 49 insertions(+) create mode 100644 server/tests/helpers/core-utils.ts create mode 100644 server/tests/helpers/index.ts (limited to 'server/tests/helpers') diff --git a/server/tests/helpers/core-utils.ts b/server/tests/helpers/core-utils.ts new file mode 100644 index 000000000..a6d829a9f --- /dev/null +++ b/server/tests/helpers/core-utils.ts @@ -0,0 +1,48 @@ +/* tslint:disable:no-unused-expression */ + +import * as chai from 'chai' +import 'mocha' +import { + parseBytes +} from '../../helpers/core-utils' + +const expect = chai.expect + +describe('Parse Bytes', function () { + it('Should pass when given valid value', async function () { + // just return it + expect(parseBytes(1024)).to.be.eq(1024) + expect(parseBytes(1048576)).to.be.eq(1048576) + expect(parseBytes('1024')).to.be.eq(1024) + expect(parseBytes('1048576')).to.be.eq(1048576) + + // sizes + expect(parseBytes('1B')).to.be.eq(1024) + expect(parseBytes('1MB')).to.be.eq(1048576) + expect(parseBytes('1GB')).to.be.eq(1073741824) + expect(parseBytes('1TB')).to.be.eq(1099511627776) + + expect(parseBytes('5GB')).to.be.eq(5368709120) + expect(parseBytes('5TB')).to.be.eq(5497558138880) + + expect(parseBytes('1024B')).to.be.eq(1048576) + expect(parseBytes('1024MB')).to.be.eq(1073741824) + expect(parseBytes('1024GB')).to.be.eq(1099511627776) + expect(parseBytes('1024TB')).to.be.eq(1125899906842624) + + // with whitespace + expect(parseBytes('1 GB')).to.be.eq(1073741824) + expect(parseBytes('1\tGB')).to.be.eq(1073741824) + + // sum value + expect(parseBytes('1TB 1024MB')).to.be.eq(1100585369600) + expect(parseBytes('4GB 1024MB')).to.be.eq(5368709120) + expect(parseBytes('4TB 1024GB')).to.be.eq(5497558138880) + expect(parseBytes('4TB 1024GB 0MB')).to.be.eq(5497558138880) + expect(parseBytes('1024TB 1024GB 1024MB')).to.be.eq(1127000492212224) + }) + + it('Should be invalid when given invalid value', async function () { + expect(parseBytes('6GB 1GB')).to.be.eq(6) + }) +}) diff --git a/server/tests/helpers/index.ts b/server/tests/helpers/index.ts new file mode 100644 index 000000000..40c7dc70e --- /dev/null +++ b/server/tests/helpers/index.ts @@ -0,0 +1 @@ +import './core-utils' -- cgit v1.2.3 From f7cc67b455a12ccae9b0ea16876d166720364357 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 4 Jan 2019 08:56:20 +0100 Subject: Add new follow, mention and user registered notifs --- server/tests/helpers/comment-model.ts | 25 +++++++++++++++++++++++++ server/tests/helpers/index.ts | 1 + 2 files changed, 26 insertions(+) create mode 100644 server/tests/helpers/comment-model.ts (limited to 'server/tests/helpers') diff --git a/server/tests/helpers/comment-model.ts b/server/tests/helpers/comment-model.ts new file mode 100644 index 000000000..76bb0f212 --- /dev/null +++ b/server/tests/helpers/comment-model.ts @@ -0,0 +1,25 @@ +/* tslint:disable:no-unused-expression */ + +import * as chai from 'chai' +import 'mocha' +import { VideoCommentModel } from '../../models/video/video-comment' + +const expect = chai.expect + +class CommentMock { + text: string + + extractMentions = VideoCommentModel.prototype.extractMentions +} + +describe('Comment model', function () { + it('Should correctly extract mentions', async function () { + const comment = new CommentMock() + + comment.text = '@florian @jean@localhost:9000 @flo @another@localhost:9000 @flo2@jean.com hello ' + + 'email@localhost:9000 coucou.com no? @chocobozzz @chocobozzz @end' + const result = comment.extractMentions().sort() + + expect(result).to.deep.equal([ 'another', 'chocobozzz', 'end', 'flo', 'florian', 'jean' ]) + }) +}) diff --git a/server/tests/helpers/index.ts b/server/tests/helpers/index.ts index 40c7dc70e..551208245 100644 --- a/server/tests/helpers/index.ts +++ b/server/tests/helpers/index.ts @@ -1 +1,2 @@ import './core-utils' +import './comment-model' -- cgit v1.2.3 From a4101923e699e49ceb9ff36e971c75417fafc9f0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 9 Jan 2019 15:14:29 +0100 Subject: Implement contact form on server side --- server/tests/helpers/core-utils.ts | 52 +++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'server/tests/helpers') diff --git a/server/tests/helpers/core-utils.ts b/server/tests/helpers/core-utils.ts index a6d829a9f..e604cf7e3 100644 --- a/server/tests/helpers/core-utils.ts +++ b/server/tests/helpers/core-utils.ts @@ -2,13 +2,16 @@ import * as chai from 'chai' import 'mocha' +import { snakeCase, isNumber } from 'lodash' import { - parseBytes + parseBytes, objectConverter } from '../../helpers/core-utils' +import { isNumeric } from 'validator' const expect = chai.expect describe('Parse Bytes', function () { + it('Should pass when given valid value', async function () { // just return it expect(parseBytes(1024)).to.be.eq(1024) @@ -45,4 +48,51 @@ describe('Parse Bytes', function () { it('Should be invalid when given invalid value', async function () { expect(parseBytes('6GB 1GB')).to.be.eq(6) }) + + it('Should convert an object', async function () { + function keyConverter (k: string) { + return snakeCase(k) + } + + function valueConverter (v: any) { + if (isNumeric(v + '')) return parseInt('' + v, 10) + + return v + } + + const obj = { + mySuperKey: 'hello', + mySuper2Key: '45', + mySuper3Key: { + mySuperSubKey: '15', + mySuperSub2Key: 'hello', + mySuperSub3Key: [ '1', 'hello', 2 ], + mySuperSub4Key: 4 + }, + mySuper4Key: 45, + toto: { + super_key: '15', + superKey2: 'hello' + }, + super_key: { + superKey4: 15 + } + } + + const res = objectConverter(obj, keyConverter, valueConverter) + + expect(res.my_super_key).to.equal('hello') + expect(res.my_super_2_key).to.equal(45) + expect(res.my_super_3_key.my_super_sub_key).to.equal(15) + expect(res.my_super_3_key.my_super_sub_2_key).to.equal('hello') + expect(res.my_super_3_key.my_super_sub_3_key).to.deep.equal([ 1, 'hello', 2 ]) + expect(res.my_super_3_key.my_super_sub_4_key).to.equal(4) + expect(res.toto.super_key).to.equal(15) + expect(res.toto.super_key_2).to.equal('hello') + expect(res.super_key.super_key_4).to.equal(15) + + // Immutable + expect(res.mySuperKey).to.be.undefined + expect(obj['my_super_key']).to.be.undefined + }) }) -- cgit v1.2.3