Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 committed Nov 2, 2021
1 parent 4e4d86a commit ec256fd
Showing 1 changed file with 98 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const input = {
configIds: [],
title: 'title',
textDescription: 'text description',
htmlDescription: 'html description'
htmlDescription: 'html description',
},
trigger: {
trigger_type: 'On demand',
Expand All @@ -78,30 +78,41 @@ describe('test create saved search report', () => {
const client = mockOpenSearchClient(hits);
const { timeCreated, fileName } = await createSavedSearchReport(
input,
client
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);
expect(fileName).toContain(`test report table order_`);
}, 20000);

test('create report with expected file name extension', async () => {
const csvReport = await createSavedSearchReport(
input,
mockOpenSearchClient([])
mockOpenSearchClient([]),
'MM/DD/YYYY h:mm:ss.SSS a',
','
);
expect(csvReport.fileName).toContain('.csv');

input.report_definition.report_params.core_params.report_format = 'xlsx';
const xlsxReport = await createSavedSearchReport(
input,
mockOpenSearchClient([])
mockOpenSearchClient([]),
'MM/DD/YYYY h:mm:ss.SSS a',
','
);
expect(xlsxReport.fileName).toContain('.xlsx');
}, 20000);

test('create report for empty data set', async () => {
const hits: Array<{ _source: any }> = [];
const client = mockOpenSearchClient(hits);
const { dataUrl } = await createSavedSearchReport(input, client);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);
expect(dataUrl).toEqual('');
}, 20000);

Expand All @@ -114,7 +125,12 @@ describe('test create saved search report', () => {
hit({ category: 'c5', customer_gender: 'Male' }),
];
const client = mockOpenSearchClient(hits);
const { dataUrl } = await createSavedSearchReport(input, client);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);

expect(dataUrl).toEqual(
'category,customer_gender\n' +
Expand All @@ -141,7 +157,12 @@ describe('test create saved search report', () => {
hit({ category: 'c11', customer_gender: 'Male' }),
];
const client = mockOpenSearchClient(hits);
const { dataUrl } = await createSavedSearchReport(input, client);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);

expect(dataUrl).toEqual(
'category,customer_gender\n' +
Expand Down Expand Up @@ -171,7 +192,12 @@ describe('test create saved search report', () => {
hit({ category: 'c5', customer_gender: 'Male' }),
];
const client = mockOpenSearchClient(hits);
const { dataUrl } = await createSavedSearchReport(input, client);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);

expect(dataUrl).toEqual('category,customer_gender\n' + 'c1,Male');
}, 20000);
Expand All @@ -193,7 +219,12 @@ describe('test create saved search report', () => {
hit({ category: 'c10', customer_gender: 'Female' }),
];
const client = mockOpenSearchClient(hits);
const { dataUrl } = await createSavedSearchReport(input, client);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);

expect(dataUrl).toEqual(
'category,customer_gender\n' +
Expand All @@ -219,7 +250,12 @@ describe('test create saved search report', () => {
hit({ category: 'c6', customer_gender: 'Female' }),
];
const client = mockOpenSearchClient(hits);
const { dataUrl } = await createSavedSearchReport(input, client);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);

expect(dataUrl).toEqual(
'category,customer_gender\n' +
Expand All @@ -239,7 +275,12 @@ describe('test create saved search report', () => {
hit({ category: ',,c3', customer_gender: 'Male,,,' }),
];
const client = mockOpenSearchClient(hits);
const { dataUrl } = await createSavedSearchReport(input, client);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);

expect(dataUrl).toEqual(
'category,customer_gender\n' +
Expand All @@ -249,6 +290,28 @@ describe('test create saved search report', () => {
);
}, 20000);

test('create report for data set with comma and custom separator', async () => {
const hits = [
hit({ category: ',c1', customer_gender: 'Ma,le' }),
hit({ category: 'c2,', customer_gender: 'M,ale' }),
hit({ category: ',,c3', customer_gender: 'Male,,,' }),
];
const client = mockOpenSearchClient(hits);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
'|'
);

expect(dataUrl).toEqual(
'category|customer_gender\n' +
',c1|Ma,le\n' +
'c2,|M,ale\n' +
',,c3|Male,,,'
);
}, 20000);

test('create report for data set with nested fields', async () => {
const hits = [
hit({
Expand All @@ -265,7 +328,12 @@ describe('test create saved search report', () => {
hits,
'"geoip.country_iso_code", "geoip.city_name", "geoip.location"'
);
const { dataUrl } = await createSavedSearchReport(input, client);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);

expect(dataUrl).toEqual(
'geoip.country_iso_code,geoip.location.lon,geoip.location.lat,geoip.city_name\n' +
Expand All @@ -283,7 +351,12 @@ describe('test create saved search report', () => {
hit({ category: ',,,@c5', customer_gender: 'Male' }),
];
const client = mockOpenSearchClient(hits);
const { dataUrl } = await createSavedSearchReport(input, client);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);

expect(dataUrl).toEqual(
'category,customer_gender\n' +
Expand All @@ -307,7 +380,12 @@ describe('test create saved search report', () => {
hit({ category: ',,,@c5', customer_gender: 'Male' }),
];
const client = mockOpenSearchClient(hits);
const { dataUrl } = await createSavedSearchReport(input, client);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);

expect(dataUrl).toEqual(
'category,customer_gender\n' +
Expand All @@ -327,7 +405,12 @@ test('create report for data set contains null field value', async () => {
hit({ category: 'c3', customer_gender: null }),
];
const client = mockOpenSearchClient(hits);
const { dataUrl } = await createSavedSearchReport(input, client);
const { dataUrl } = await createSavedSearchReport(
input,
client,
'MM/DD/YYYY h:mm:ss.SSS a',
','
);

expect(dataUrl).toEqual(
'category,customer_gender\n' + 'c1,Ma\n' + 'c2,le\n' + 'c3, '
Expand Down

0 comments on commit ec256fd

Please sign in to comment.