This commit is contained in:
root
2023-03-29 15:20:05 +00:00
parent 5ec489e0e0
commit a0bb8f2d1e
25468 changed files with 3063105 additions and 28 deletions

View File

@@ -0,0 +1,28 @@
import test from 'ava';
import dateDifference from '../dateDifference';
test('module should be a function', t => {
t.is(typeof dateDifference, 'function');
});
test('should return difference in days', t => {
t.is(dateDifference(new Date('06-20-2018'), new Date('06-26-2018'), 'days'), 6);
});
test('should return difference in hours', t => {
t.is(dateDifference(new Date('06-20-2018'), new Date('06-26-2018'), 'hours'), 144);
t.is(dateDifference(new Date('06-26-2018 10:00'), new Date('06-26-2018 08:00'), 'hours'), 2)
});
test('should return difference in minutes', t => {
t.is(dateDifference(new Date('06-20-2018'), new Date('06-26-2018'), 'minutes'), 8640);
});
test('should return difference in milliseconds', t => {
t.is(dateDifference(new Date('06-26-2018'), new Date('06-20-2018'), 'milliseconds'), 518400000);
});
test('should return all difference types in object', t => {
const diffResult = { days: 6, hours: 2, minutes: 10, milliseconds: 526200000 };
t.deepEqual(dateDifference(new Date('06-26-2018 10:10'), new Date('06-20-2018 08:00'), 'all'), diffResult);
});

View File

@@ -0,0 +1,26 @@
import test from 'ava';
import dateDifferenceFromNow from '../dateDifferenceFromNow';
test('module should be a function', t => {
t.is(typeof dateDifferenceFromNow, 'function');
});
test('should return Number: days', t => {
t.is(typeof dateDifferenceFromNow(new Date('12-20-2017'), 'days'), 'number');
});
test('should return Number: hours', t => {
t.is(typeof dateDifferenceFromNow(new Date('12-20-2017'), 'hours'), 'number');
});
test('should return Number: minutes', t => {
t.is(typeof dateDifferenceFromNow(new Date('12-20-2017'), 'minutes'), 'number');
});
test('should return Number: milliseconds', t => {
t.is(typeof dateDifferenceFromNow(new Date('12-20-2017'), 'milliseconds'), 'number');
});
test('should return Object: all', t => {
t.deepEqual(typeof dateDifferenceFromNow(new Date('12-20-2017'), 'all'), 'object');
});

View File

@@ -0,0 +1,17 @@
import test from 'ava';
import isValuesUnique from './../isValuesUnique';
const notUniqueData = [{email: 'api@test.com'}, {email: 'api@test.com'}];
const uniqueData = [{email: 'api@test.com'}, {email: 'api_1@test.com'}];
test('module should be a function', t => {
t.is(typeof isValuesUnique, 'function');
});
test('should return true when values are unique', t => {
t.is(isValuesUnique(uniqueData, 'email'), true);
});
test('should return false when values are not unique', t => {
t.is(isValuesUnique(notUniqueData, 'email'), false);
});

View File

@@ -0,0 +1,19 @@
import test from 'ava';
import objectInterface from './../objectInterface';
const result = {body: "Hello world!", count: 1, sender: "Vasyl Stokolosa", isRead: false, created: 1531119600000};
test('module should be a function', t => {
t.is(typeof objectInterface, 'function');
});
test('should return object based on interface configuration', t => {
let email = objectInterface([
'body', 'count/1', 'sender|this.firstName + " " + this.lastName', 'created: Date.parse("Tue Jul 09 2018 17 GMT-0700")', 'isRead: false'
]);
t.deepEqual(email({
body: 'Hello world!', count: '', firstName: 'Vasyl', lastName: 'Stokolosa', another: ''
}), result
);
});

View File

@@ -0,0 +1,13 @@
import test from 'ava';
import sortAndAddFirstElement from './../sortAndAddFirstElement';
test('module should be a function', t => {
t.is(typeof sortAndAddFirstElement, 'function');
});
test('should sort and add first element', t => {
t.deepEqual(
sortAndAddFirstElement([{name:'Bob'}, {name:'Aron'}], 'name', {name:'All'}),
[ {name:'All'}, {name:'Aron'}, {name:'Bob'} ]
);
});

View File

@@ -0,0 +1,18 @@
import test from 'ava';
import substr from './../substr';
test('module should be a function', t => {
t.is(typeof substr, 'function');
});
test('should substring "Hello"', t => {
t.is(substr('Hello World!', 0, 5), 'Hello');
});
test('should substring "World!"', t => {
t.is(substr('Hello World!', 6), 'World!');
});
test('should return value if it is not correct', t => {
t.deepEqual(substr({}, 0, 5), {});
});