mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Implement contact form on server side
This commit is contained in:
parent
8d00889b60
commit
a4101923e6
32 changed files with 541 additions and 49 deletions
|
@ -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
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue