-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #797 from CMSgov/QPPA-8974
QPPA-8974: Update Measures Unit Test Coverage
- Loading branch information
Showing
129 changed files
with
2,376 additions
and
11,642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
import appRoot from 'app-root-path'; | ||
import { parse } from 'csv-parse/sync'; | ||
import fs from 'fs'; | ||
import _ from 'lodash'; | ||
import path from 'path'; | ||
|
||
import * as Util from './update-measures-util'; | ||
import { ingestStrata } from './ingest-strata'; | ||
import { DataValidationError } from '../../errors'; | ||
|
||
const performanceYear = 2022 | ||
const testDataPath = `test/measures/${performanceYear}`; | ||
const measuresPath = `${testDataPath}/test-measures.json`; | ||
|
||
const measuresJson = JSON.parse( | ||
fs.readFileSync(path.join(appRoot + "", measuresPath), "utf8") | ||
); | ||
|
||
describe('ingest-strata', () => { | ||
it('successfully ingests strata changes', () => { | ||
const strataPath = `${testDataPath}/quality-strata.csv`; | ||
const measuresResultPath = `${testDataPath}/test-measures-result.json`; | ||
const measuresResultJson = JSON.parse( | ||
fs.readFileSync(path.join(appRoot + "", measuresResultPath), "utf8") | ||
); | ||
jest.spyOn(JSON, 'parse').mockReturnValueOnce(measuresJson); | ||
const writeSpy = jest.spyOn(Util, 'writeToFile'); | ||
writeSpy.mockImplementation(); | ||
|
||
ingestStrata(performanceYear, strataPath); | ||
|
||
expect(writeSpy).toBeCalledWith(measuresResultJson, `measures/${performanceYear}/measures-data.json`); | ||
}); | ||
|
||
it('fails to ingest strata if the measureId is blank in the csv.', () => { | ||
const strataPath = `${testDataPath}/blank-measureid-quality-strata.csv`; | ||
jest.spyOn(JSON, 'parse').mockReturnValueOnce(measuresJson); | ||
const writeSpy = jest.spyOn(Util, 'writeToFile'); | ||
writeSpy.mockImplementation(); | ||
|
||
expect(() => { | ||
ingestStrata(performanceYear, strataPath); | ||
}).toThrowError(new DataValidationError(strataPath, 'MeasureId is required.')); | ||
}); | ||
|
||
it('fails to ingest strata if the name or description is blank in the csv.', () => { | ||
const strataPath = `${testDataPath}/bad-quality-strata.csv`; | ||
jest.spyOn(JSON, 'parse').mockReturnValueOnce(measuresJson); | ||
const writeSpy = jest.spyOn(Util, 'writeToFile'); | ||
writeSpy.mockImplementation(); | ||
|
||
expect(() => { | ||
ingestStrata(performanceYear, strataPath); | ||
}).toThrowError(new DataValidationError(strataPath, 'Name and description are required.')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
import appRoot from 'app-root-path'; | ||
import { parse } from 'csv-parse/sync'; | ||
import fs from 'fs'; | ||
import _ from 'lodash'; | ||
import path from 'path'; | ||
|
||
import * as Lib from '../lib/measures-lib'; | ||
import { ingestStrata } from './ingest-strata'; | ||
import { DataValidationError } from '../../errors'; | ||
|
||
const performanceYear = 2024 | ||
const testDataPath = `test/measures/${performanceYear}`; | ||
const measuresPath = `${testDataPath}/test-measures.json`; | ||
|
||
const measuresJson = JSON.parse( | ||
fs.readFileSync(path.join(appRoot + "", measuresPath), "utf8") | ||
); | ||
|
||
describe('ingest-strata', () => { | ||
it('successfully ingests strata changes', () => { | ||
const strataPath = `${testDataPath}/test-strata.csv`; | ||
const measuresResultPath = `${testDataPath}/test-measures-result.json`; | ||
const measuresResultJson = JSON.parse( | ||
fs.readFileSync(path.join(appRoot + "", measuresResultPath), "utf8") | ||
); | ||
jest.spyOn(JSON, 'parse').mockReturnValueOnce(measuresJson); | ||
const writeSpy = jest.spyOn(Lib, 'writeToFile'); | ||
writeSpy.mockImplementation(); | ||
|
||
ingestStrata(performanceYear, strataPath); | ||
|
||
expect(writeSpy).toBeCalledWith(measuresResultJson, `measures/${performanceYear}/measures-data.json`); | ||
}); | ||
|
||
it('fails to ingest strata if the measureId is blank in the csv.', () => { | ||
const strataPath = `${testDataPath}/blank-measureid-test-strata.csv`; | ||
jest.spyOn(JSON, 'parse').mockReturnValueOnce(measuresJson); | ||
const writeSpy = jest.spyOn(Lib, 'writeToFile'); | ||
writeSpy.mockImplementation(); | ||
|
||
expect(() => { | ||
ingestStrata(performanceYear, strataPath); | ||
}).toThrowError(new DataValidationError(strataPath, 'MeasureId is required.')); | ||
}); | ||
|
||
it('fails to ingest strata if the name or description is blank in the csv.', () => { | ||
const strataPath = `${testDataPath}/bad-test-strata.csv`; | ||
jest.spyOn(JSON, 'parse').mockReturnValueOnce(measuresJson); | ||
const writeSpy = jest.spyOn(Lib, 'writeToFile'); | ||
writeSpy.mockImplementation(); | ||
|
||
expect(() => { | ||
ingestStrata(performanceYear, strataPath); | ||
}).toThrowError(new DataValidationError(strataPath, 'Name and description are required.')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
import appRoot from 'app-root-path'; | ||
import { parse } from 'csv-parse/sync'; | ||
import fs from 'fs'; | ||
import _ from 'lodash'; | ||
import path from 'path'; | ||
|
||
import * as Lib from '../lib/measures-lib'; | ||
import { ingestStrata } from './ingest-strata'; | ||
import { DataValidationError } from '../../errors'; | ||
|
||
const performanceYear = 2023 | ||
const testDataPath = `test/measures/${performanceYear}`; | ||
const measuresPath = `${testDataPath}/test-measures.json`; | ||
|
||
const measuresJson = JSON.parse( | ||
fs.readFileSync(path.join(appRoot + "", measuresPath), "utf8") | ||
); | ||
|
||
describe('ingest-strata', () => { | ||
it('successfully ingests strata changes', () => { | ||
const strataPath = `${testDataPath}/test-strata.csv`; | ||
const measuresResultPath = `${testDataPath}/test-measures-result.json`; | ||
const measuresResultJson = JSON.parse( | ||
fs.readFileSync(path.join(appRoot + "", measuresResultPath), "utf8") | ||
); | ||
jest.spyOn(JSON, 'parse').mockReturnValueOnce(measuresJson); | ||
const writeSpy = jest.spyOn(Lib, 'writeToFile'); | ||
writeSpy.mockImplementation(); | ||
|
||
ingestStrata(performanceYear, strataPath); | ||
|
||
expect(writeSpy).toBeCalledWith(measuresResultJson, `measures/${performanceYear}/measures-data.json`); | ||
}); | ||
|
||
it('fails to ingest strata if the measureId is blank in the csv.', () => { | ||
const strataPath = `${testDataPath}/blank-measureid-test-strata.csv`; | ||
jest.spyOn(JSON, 'parse').mockReturnValueOnce(measuresJson); | ||
const writeSpy = jest.spyOn(Lib, 'writeToFile'); | ||
writeSpy.mockImplementation(); | ||
|
||
expect(() => { | ||
ingestStrata(performanceYear, strataPath); | ||
}).toThrowError(new DataValidationError(strataPath, 'MeasureId is required.')); | ||
}); | ||
|
||
it('fails to ingest strata if the name or description is blank in the csv.', () => { | ||
const strataPath = `${testDataPath}/bad-test-strata.csv`; | ||
jest.spyOn(JSON, 'parse').mockReturnValueOnce(measuresJson); | ||
const writeSpy = jest.spyOn(Lib, 'writeToFile'); | ||
writeSpy.mockImplementation(); | ||
|
||
expect(() => { | ||
ingestStrata(performanceYear, strataPath); | ||
}).toThrowError(new DataValidationError(strataPath, 'Name and description are required.')); | ||
}); | ||
}); |
Oops, something went wrong.