Test case for filter payload generator

This commit is contained in:
Fayaz Ahmed 2021-10-26 16:48:58 +05:30 committed by Tejaswini
parent 2e716b9375
commit 792ee4dd53

View file

@ -0,0 +1,64 @@
import filterQueryGenerator from '../filterQueryGenerator';
const payload = [
{
attribute_key: 'status',
filter_operator: 'equal_to',
values: [
{ id: 'pending', name: 'Pending' },
{ id: 'resolved', name: 'Resolved' },
],
query_operator: 'and',
},
{
attribute_key: 'assignee',
filter_operator: 'equal_to',
values: {
id: 3,
account_id: 1,
auto_offline: true,
confirmed: true,
email: 'fayazara@gmail.com',
available_name: 'Fayaz',
name: 'Fayaz',
role: 'agent',
thumbnail:
'https://www.gravatar.com/avatar/a35bf18a632f734c8d0c883dcc9fa0ef?d=404',
},
query_operator: 'and',
},
{
attribute_key: 'id',
filter_operator: 'equal_to',
values: 'This is a test',
query_operator: null,
},
];
const finalResult = [
{
attribute_key: 'status',
filter_operator: 'equal_to',
values: ['pending', 'resolved'],
query_operator: 'and',
},
{
attribute_key: 'assignee',
filter_operator: 'equal_to',
values: [3],
query_operator: 'and',
},
{
attribute_key: 'id',
filter_operator: 'equal_to',
values: ['This is a test'],
query_operator: null,
},
];
describe('#filterQueryGenerator', () => {
it('returns the correct format of filter query', () => {
expect(filterQueryGenerator(payload)).toMatchObject(finalResult);
expect(finalResult.every(i => Array.isArray(i.values))).toBe(true);
});
});