Skip to content

Commit

Permalink
better example
Browse files Browse the repository at this point in the history
  • Loading branch information
lagden committed May 21, 2021
1 parent 016680c commit 99db5ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 78 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import 'condition' from '@tadashi/condition'
const data = {
age: 65,
gender: 'F',
hasCar: true,
city: 'São Paulo',
country: 'Brasil'
hasCar: true,
colors: ['red', 'blue']
}

const conditions = [
Expand All @@ -59,11 +59,11 @@ const conditions = [
{
field: 'city',
operator: 'assigned',
value: true
value: false
}, {
field: 'country',
field: 'colors',
operator: 'intersection',
value: ['Brasil', 'Japan']
value: ['blue', 'green']
}
]
}, {
Expand Down
95 changes: 22 additions & 73 deletions test/condition.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@ import condition from '../src/condition.js'
import {intersection} from '../src/helper.js'

const data = {
tipo_pessoa: 'PF',
age: 65,
sexo: 'F',
aposentada: true,
foo: 'bar',
eu: 'vc',
gender: 'F',
city: 'São Paulo',
country: 'Brazil',
hasCar: true,
cidade: 'São Paulo'
colors: ['red', 'blue']
}

const conditions = [
{
join_operator: 'and',
args: [
{
field: 'tipo_pessoa',
field: 'gender',
operator: 'eq',
value: 'PF'
value: 'F'
}, {
field: 'age',
operator: 'gt',
Expand All @@ -29,58 +27,36 @@ const conditions = [
join_operator: 'or',
args: [
{
field: 'sexo',
operator: 'eq',
value: 'F'
field: 'city',
operator: 'assigned',
value: false
}, {
field: 'aposentada',
operator: 'eq',
value: true
}, {
join_operator: 'and',
args: [
{
field: 'foo',
operator: 'eq',
value: 'bar'
}, {
field: 'eu',
operator: 'ne',
value: 'vc'
}
]
field: 'country',
operator: 'intersection',
value: ['Japan', 'Brazil']
}
]
}, {
field: 'hasCar',
operator: 'eq',
value: true
}
]
}
]

const condition_intersection = [
{
join_operator: '',
args: [
{
field: 'cidade',
}, {
field: 'colors',
operator: 'intersection',
value: ['Aparecida', 'Lorena', 123]
value: ['blue', 'green', 123]
}
]
}
]

const condition_intersection_other = [
const condition_intersection = [
{
join_operator: '',
args: [
{
field: 'cidade',
field: 'colors',
operator: 'intersection',
value: ['São Paulo', 'Campinas']
value: ['yellow', 'green']
}
]
}
Expand All @@ -91,33 +67,20 @@ const condition_assigned = [
join_operator: '',
args: [
{
field: 'uf',
operator: 'assigned',
value: true
}
]
}
]

const condition_assigned_other = [
{
join_operator: '',
args: [
{
field: 'cidade',
field: 'state',
operator: 'assigned',
value: 'true'
}
]
}
]

const condition_intersection_other_more = [
const condition_assigned_other = [
{
join_operator: '',
args: [
{
field: 'cidade',
field: 'city',
operator: 'assigned',
value: '1'
}
Expand All @@ -138,36 +101,22 @@ const condition_wrong_operator = [
}
]

test('condition', t => {
test('conditions', t => {
const fn = condition(conditions)
const response = fn(data)
t.true(response)
})

// Verifica se contem
test('condition_intersection', t => {
const fn = condition(condition_intersection)
const response = fn(data)
t.false(response)
})

test('condition_intersection_other', t => {
const fn = condition(condition_intersection_other)
const response = fn(data)
t.true(response)
})

test('condition_intersection_other_more', t => {
const fn = condition(condition_intersection_other_more)
const response = fn(data)
t.true(response)
})

test('intersection', t => {
t.true(intersection('tadashi', ['tadashi', 'takamoto']))
})

// Verifica se o campo já foi preenchido
test('condition_assigned', t => {
const fn = condition(condition_assigned)
const response = fn(data)
Expand Down

0 comments on commit 99db5ea

Please sign in to comment.