From 792ee4dd53b26fb6e4404cba1125450549499bba Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com> Date: Tue, 26 Oct 2021 16:48:58 +0530 Subject: [PATCH] Test case for filter payload generator --- .../helper/specs/filterQueryGenerator.spec.js | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js diff --git a/app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js b/app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js new file mode 100644 index 000000000..b979e09ca --- /dev/null +++ b/app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js @@ -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); + }); +});