Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#19: add relevant mocha tests from cert repo #30

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ const readFile = async (path = '') => {
}
};

const reportTypes = {
DATA_DICTIONARY: {
name: 'data_dictionary'
},
WEB_API_SERVER_CORE: {
name: 'web_api_server_core'
},
DATA_DICTIONARY_WITH_IDX_PAYLOAD: {
name: 'data_dictionary_with_IDX_payload'
},
DATA_AVAILABILITY: {
name: 'data_availability'
}
};

module.exports = {
getFieldDetails,
getIdxCounts,
Expand All @@ -213,5 +228,6 @@ module.exports = {
readFile,
getMetadata,
getLookupMap,
getStandardMetadata
getStandardMetadata,
reportTypes
};
2 changes: 1 addition & 1 deletion lib/process-cucumber-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const parseErrorLogSingleLine = (log = '') => {
};
};

// some logs can have new line in the moddle of the message. this causes an issue when parsing multi-line logs. we fix this issue here.
// some logs can have new line in the middle of the message. this causes an issue when parsing multi-line logs. we fix this issue here.
const sanitizeLogs = (logs = []) => {
const timestampRegex = /^\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\]/;
return logs.reduce((acc, curr) => {
Expand Down
10 changes: 5 additions & 5 deletions test/etl.js → test/cucumber-reports.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const fs = require('fs');
const { processCucumberJson: processCucumber } = require('../index');
const { parseErrorLog, processCucumberJson } = processCucumber;
const passedOnlyReport = require('./sample-reports/cucumber-passed-only.json');
const errorOnlyReport = require('./sample-reports/cucumber-error-only.json');
const errorAndPassed = require('./sample-reports/cucumber-passed-error.json');
const passedOnlyReport = require('./sample-cucumber-reports/cucumber-passed-only.json');
const errorOnlyReport = require('./sample-cucumber-reports/cucumber-error-only.json');
const errorAndPassed = require('./sample-cucumber-reports/cucumber-passed-error.json');
// Import the assert library
const assert = require('assert');

const errorLog = fs.readFileSync(`${__dirname}/sample-reports/error.log.txt`).toString();
const errorLog = fs.readFileSync(`${__dirname}/sample-cucumber-reports/error.log.txt`).toString();
const errorLogMultiline = fs
.readFileSync(`${__dirname}/sample-reports/error.multiline.log.txt`)
.readFileSync(`${__dirname}/sample-cucumber-reports/error.multiline.log.txt`)
.toString();

describe('processCucumberJson', function () {
Expand Down
13 changes: 13 additions & 0 deletions test/data-availability.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { daReport } = require('./sample-data-availability-reports/availability-report');
const expectedReport = require('./sample-data-availability-reports/expected-availability-report.json');
const {
processDataAvailability: { processDataAvailability }
} = require('..');
const assert = require('assert');

describe('process-metadata', function () {
it('should match the expected data', async () => {
const processedReport = await processDataAvailability(daReport);
assert.deepStrictEqual(JSON.parse(JSON.stringify(processedReport)), expectedReport);
});
});
13 changes: 13 additions & 0 deletions test/data-dictionary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { metadataReport } = require('./sample-data-dictionary-reports/metadata-report');
const expectedReport = require('./sample-data-dictionary-reports/expected-metadata-report.json');
const {
processMetadata: { processMetadataReport }
} = require('..');
const assert = require('assert');

describe('process-metadata', function () {
it('should match the expected data', () => {
const processedReport = processMetadataReport(metadataReport);
assert.deepStrictEqual(JSON.parse(JSON.stringify(processedReport)), expectedReport);
});
});
138 changes: 138 additions & 0 deletions test/sample-data-availability-reports/availability-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
const { reportTypes } = require('../../lib/common');

const daReport = {
description: 'RESO Data Availability Report',
version: '1.7',
generatedOn: '2022-03-15T10:12:32.319Z',
type: reportTypes.DATA_AVAILABILITY.name,
resources: [
{
resourceName: 'Office',
recordCount: 1000,
numRecordsFetched: 1000,
numSamples: 10,
pageSize: 100,
averageResponseBytes: 100000,
averageResponseTimeMillis: 1500,
dateField: 'ModificationTimestamp',
dateLow: '2021-03-15T10:12:32.319Z',
dateHigh: '2022-03-15T10:12:32.319Z',
keyFields: ['OfficeKey']
},
{
resourceName: 'Property',
recordCount: 1000,
numRecordsFetched: 1000,
numSamples: 10,
pageSize: 100,
averageResponseBytes: 100000,
averageResponseTimeMillis: 2000,
dateField: 'ModificationTimestamp',
dateLow: '2021-03-15T10:12:32.319Z',
dateHigh: '2022-03-15T10:12:32.319Z',
keyFields: ['ListingKey'],
postalCodes: ['12345', '67890']
}
],
fields: [
{
resourceName: 'Office',
fieldName: 'OfficeStateOrProvince',
frequency: 1000
},
{
resourceName: 'Property',
fieldName: 'AccessibilityFeatures',
frequency: 2000
},
{
resourceName: 'Property',
fieldName: 'StandardStatus',
frequency: 1000
},
{
resourceName: 'Property',
fieldName: 'ListPrice',
frequency: 999
},
{
resourceName: 'Property',
fieldName: 'CustomLookupField123',
frequency: 500
}
],
lookups: [
{
resourceName: 'Office',
fieldName: 'OfficeStateOrProvince',
numLookupsTotal: 1000
},
{
resourceName: 'Property',
fieldName: 'AccessibilityFeatures',
numLookupsTotal: 1000
},
{
resourceName: 'Property',
fieldName: 'StandardStatus',
numLookupsTotal: 1000
},
{
resourceName: 'Property',
fieldName: 'CustomLookupField123',
numLookupsTotal: 1000
}
],
lookupValues: [
{
resourceName: 'Office',
fieldName: 'OfficeStateOrProvince',
lookupValue: 'CA',
frequency: 900
},
{
resourceName: 'Office',
fieldName: 'OfficeStateOrProvince',
lookupValue: 'HI',
frequency: 100
},
{
resourceName: 'Property',
fieldName: 'AccessibilityFeatures',
lookupValue: 'Accessible Approach with Ramp',
frequency: 100
},
{
resourceName: 'Property',
fieldName: 'AccessibilityFeatures',
lookupValue: 'ReinforcedFloors',
frequency: 100
},
{
resourceName: 'Property',
fieldName: 'StandardStatus',
lookupValue: 'Active Under Contract',
frequency: 900
},
{
resourceName: 'Property',
fieldName: 'StandardStatus',
lookupValue: 'Pending',
frequency: 100
},
{
resourceName: 'Property',
fieldName: 'CustomLookupField123',
lookupValue: 'PENDING',
frequency: 10
},
{
resourceName: 'Property',
fieldName: 'CustomLookupField123',
lookupValue: 'NULL_VALUE',
frequency: 9990
}
]
};

module.exports = { daReport };
Loading
Loading