Skip to content

Commit

Permalink
test (analytics/value): update import and correctly use jest function
Browse files Browse the repository at this point in the history
  • Loading branch information
AlasDiablo committed Jan 24, 2024
1 parent a2b91d2 commit 1043270
Showing 1 changed file with 65 additions and 48 deletions.
113 changes: 65 additions & 48 deletions packages/analytics/test/value.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import ezs from '@ezs/core/src';
import from from 'from';
import assert from 'assert';
import ezs from '../../core/src';
import value from '../src/value';

ezs.addPath(__dirname);

describe('value', () => {
/**
* Helper function use to call ezs in each tests
* @param ezsRuntime {(name: string, options: any, environment?: unknown) => NodeJS.WritableStream}
* @param dataSet {Array<unknown>}
* @param path {string | undefined}
* @returns {Promise<Array<unknown>>}
*/
const runEzs = (ezsRuntime, dataSet, path) => new Promise((resolve) => {
const result = [];
from(dataSet)
Expand All @@ -22,32 +28,42 @@ describe('value', () => {
const simpleData = [
{
'id': 1,
'value': 1
'value': 3
},
{
'id': 2,
'value': 2
'value': 4
}
];

it('should extract the id (path = id)', async () => {
ezs.use({ value });
const result = await runEzs(ezs, simpleData, 'id');

assert.deepStrictEqual(result.length, 2);
expect(result).toHaveLength(2);

assert.deepStrictEqual(result[0], 1);
assert.deepStrictEqual(result[1], 2);
expect(result[0]).toStrictEqual(1);
expect(result[1]).toStrictEqual(2);
});

it('should extract the value (path = value)', async () => {
ezs.use({ value });
const result = await runEzs(ezs, simpleData, 'value');

assert.deepStrictEqual(result.length, 2);
expect(result).toHaveLength(2);

assert.deepStrictEqual(result[0], 1);
assert.deepStrictEqual(result[1], 2);
expect(result[0]).toStrictEqual(3);
expect(result[1]).toStrictEqual(4);
});

it('should extract the value (path = undefined)', async () => {
ezs.use({ value });
const result = await runEzs(ezs, simpleData);

expect(result).toHaveLength(2);

expect(result[0]).toStrictEqual(3);
expect(result[1]).toStrictEqual(4);
});
});

Expand All @@ -67,20 +83,20 @@ describe('value', () => {
ezs.use({ value });
const result = await runEzs(ezs, arrayData, 'id');

assert.deepStrictEqual(result.length, 2);
expect(result).toHaveLength(2);

assert.deepStrictEqual(result[0], 1);
assert.deepStrictEqual(result[1], 2);
expect(result[0]).toStrictEqual(1);
expect(result[1]).toStrictEqual(2);
});

it('should extract the value (path = value)', async () => {
ezs.use({ value });
const result = await runEzs(ezs, arrayData, 'value');

assert.deepStrictEqual(result.length, 2);
expect(result).toHaveLength(2);

assert.deepStrictEqual(result[0], [1, 1]);
assert.deepStrictEqual(result[1], [2, 2]);
expect(result[0]).toStrictEqual([1, 1]);
expect(result[1]).toStrictEqual([2, 2]);
});
});

Expand All @@ -104,20 +120,20 @@ describe('value', () => {
ezs.use({ value });
const result = await runEzs(ezs, objectData, 'id');

assert.deepStrictEqual(result.length, 2);
expect(result).toHaveLength(2);

assert.deepStrictEqual(result[0], 1);
assert.deepStrictEqual(result[1], 2);
expect(result[0]).toStrictEqual(1);
expect(result[1]).toStrictEqual(2);
});

it('should extract the value (path = value)', async () => {
ezs.use({ value });
const result = await runEzs(ezs, objectData, 'value');

assert.deepStrictEqual(result.length, 2);
expect(result).toHaveLength(2);

assert.deepStrictEqual(result[0], { a: 1 });
assert.deepStrictEqual(result[1], { b: 2 });
expect(result[0]).toStrictEqual({ a: 1 });
expect(result[1]).toStrictEqual({ b: 2 });
});
});

Expand Down Expand Up @@ -161,19 +177,20 @@ describe('value', () => {
ezs.use({ value });
const result = await runEzs(ezs, deepObjectData, 'id');

assert.deepStrictEqual(result.length, 2);
expect(result).toHaveLength(2);

assert.deepStrictEqual(result[0], 1);
assert.deepStrictEqual(result[1], 2);
expect(result[0]).toStrictEqual(1);
expect(result[1]).toStrictEqual(2);
});

it('should extract the value (path = value)', async () => {
ezs.use({ value });
const result = await runEzs(ezs, deepObjectData, 'value');

assert.deepStrictEqual(result.length, 2);
expect(result).toHaveLength(2);


assert.deepStrictEqual(result[0], {
expect(result[0]).toStrictEqual({
a: 1,
b: {
a: '1',
Expand All @@ -186,7 +203,7 @@ describe('value', () => {
c: [1, 2],
d: [1.0002, 0.0057, 1000.100056]
});
assert.deepStrictEqual(result[1], {
expect(result[1]).toStrictEqual({
a: 2,
b: {
a: '2',
Expand Down Expand Up @@ -252,42 +269,42 @@ describe('value', () => {
ezs.use({ value });
const result = await runEzs(ezs, animalia100Data, 'id');

assert.deepStrictEqual(result.length, 5);
expect(result).toHaveLength(5);

assert.deepStrictEqual(result[0], '0000000000000000000.02702702702702702506');
assert.deepStrictEqual(result[1], '0000000000000000000.03571428571428571924');
assert.deepStrictEqual(result[2], '0000000000000000000.07142857142857143848');
assert.deepStrictEqual(result[3], '0000000000000000000.08333333333333334259');
assert.deepStrictEqual(result[4], '0000000000000000000.08333333333333334259');
expect(result[0]).toStrictEqual('0000000000000000000.02702702702702702506');
expect(result[1]).toStrictEqual('0000000000000000000.03571428571428571924');
expect(result[2]).toStrictEqual('0000000000000000000.07142857142857143848');
expect(result[3]).toStrictEqual('0000000000000000000.08333333333333334259');
expect(result[4]).toStrictEqual('0000000000000000000.08333333333333334259');
});

it('should extract the value (path = value)', async () => {
ezs.use({ value });
const result = await runEzs(ezs, animalia100Data, 'value');

assert.deepStrictEqual(result.length, 5);
expect(result).toHaveLength(5);

assert.deepStrictEqual(result[0], {
expect(result[0]).toStrictEqual({
id: ['uid:/0579J7JN', 'uid:/KRVCJDGF'],
value: 0.027027027027027025,
values: [0, 0.05405405405405405],
});
assert.deepStrictEqual(result[1], {
expect(result[1]).toStrictEqual({
id: ['uid:/0579J7JN', 'uid:/JW63WRFP'],
value: 0.03571428571428572,
values: [0, 0.07142857142857144],
});
assert.deepStrictEqual(result[2], {
expect(result[2]).toStrictEqual({
id: ['uid:/0579J7JN', 'uid:/WC0F9P1S'],
value: 0.07142857142857144,
values: [0, 0.14285714285714288],
});
assert.deepStrictEqual(result[3], {
expect(result[3]).toStrictEqual({
id: ['uid:/0579J7JN', 'uid:/J9N9N456'],
value: 0.08333333333333334,
values: [0.16666666666666669, 0],
});
assert.deepStrictEqual(result[4], {
expect(result[4]).toStrictEqual({
id: ['uid:/0579J7JN', 'uid:/V572XQCD'],
value: 0.08333333333333334,
values: [0.16666666666666669, 0],
Expand All @@ -296,12 +313,12 @@ describe('value', () => {
});

describe('genrated data', () => {
const LENGHT = 1000;
const LENGTH = 1000;
let genratedData = [];

beforeEach(() => {
const data = [];
for (let i = 0; i < LENGHT; i += 1) {
for (let i = 0; i < LENGTH; i += 1) {
data.push({
id: i,
value: i * 2,
Expand All @@ -314,21 +331,21 @@ describe('value', () => {
ezs.use({ value });
const result = await runEzs(ezs, genratedData, 'id');

assert.deepStrictEqual(result.length, LENGHT);
expect(result).toHaveLength(LENGTH);

for (let i = 0; i < LENGHT; i += 1) {
assert.deepStrictEqual(result[i], i);
for (let i = 0; i < LENGTH; i += 1) {
expect(result[i]).toStrictEqual(i);
}
});

it('should extract the value (path = value)', async () => {
ezs.use({ value });
const result = await runEzs(ezs, genratedData, 'value');

assert.deepStrictEqual(result.length, LENGHT);
expect(result).toHaveLength(LENGTH);

for (let i = 0; i < LENGHT; i += 1) {
assert.deepStrictEqual(result[i], i * 2);
for (let i = 0; i < LENGTH; i += 1) {
expect(result[i]).toStrictEqual(i * 2);
}
});
});
Expand Down

0 comments on commit 1043270

Please sign in to comment.