Skip to content

Commit

Permalink
Merge pull request #200 from CMSgov/develop
Browse files Browse the repository at this point in the history
Merge Develop to Master
  • Loading branch information
lavioli-work committed Jan 5, 2023
2 parents b113068 + 59d0abc commit 7b9827e
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 16.17.0

- name: Install dependencies
run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-beta-publish.yml
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 18.10.0
node-version: 16.17.0
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 18.10.0
node-version: 16.17.0
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
Expand Down
21 changes: 19 additions & 2 deletions file-uploader-util.js
Expand Up @@ -141,7 +141,10 @@ export function getExistingSubmission(submission, baseOptions) {
* @return {Object}
*/
export function putMeasurementSet(measurementSet, baseOptions, measurementSetId) {
return axios.put(baseOptions.url + '/measurement-sets/' + measurementSetId, measurementSet, {
//if we are using measurementSet.id, we do not need the submissionId
delete measurementSet.submissionId;

return axios.put(baseOptions.url + '/measurement-sets/' + measurementSetId, removeReadOnlyProperties(measurementSet), {
headers:baseOptions.headers
}).then((body) => {
// Assuming a 200 response here
Expand All @@ -161,7 +164,7 @@ export function putMeasurementSet(measurementSet, baseOptions, measurementSetId)
* @return {Object}
*/
export function postMeasurementSet(measurementSet, baseOptions) {
return axios.post(baseOptions.url + '/measurement-sets', measurementSet, {
return axios.post(baseOptions.url + '/measurement-sets', removeReadOnlyProperties(measurementSet), {
headers: baseOptions.headers
}).then((body) => {
// Assuming a 201 response here
Expand Down Expand Up @@ -287,3 +290,17 @@ function createErrorDetails(type, ...details) {
};
});
}

function isReadOnlyMeasurementSetProperty(propertyName) {
return ['suppressed', 'createdAt', 'updatedAt', 'submitterId', 'submitterType', 'version', 'id'].includes(propertyName);
}

function removeReadOnlyProperties(object) {
Object.keys(object).forEach(key => {
if (object[key] === null || isReadOnlyMeasurementSetProperty(key)) {
delete object[key];
}
});

return object;
}
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "qpp-file-upload-api-client",
"version": "1.4.9",
"version": "1.4.10",
"description": "An npm package to send the necessary requests to the Submissions API to execute the functionality required by a file upload client",
"main": "./dist/index.js",
"types": "index.d.ts",
Expand Down Expand Up @@ -47,7 +47,7 @@
"pre-push": "^0.1.1",
"rimraf": "^3.0.2",
"sinon": "^11.1.1",
"snyk": "^1.985.0",
"snyk": "^1.1065.0",
"terser-webpack-plugin": "^5.1.4",
"webpack": "^5.41.0",
"webpack-cli": "^4.7.2"
Expand Down
84 changes: 84 additions & 0 deletions test/file-uploader-util.spec.js
Expand Up @@ -38,6 +38,46 @@ const validSubmission = {
}]
};

const putSubmissionWithReadyOnlyFields = {
programName: 'mips',
entityType: 'individual',
taxpayerIdentificationNumber: '000123456',
nationalProviderIdentifier: '0123456789',
performanceYear: 2017,
id: 'abc',
measurementSets: [{
category: 'ia',
submissionMethod: 'registry',
performanceStart: '2017-01-01',
performanceEnd: '2017-06-01',
submissionId: 'abc',
id: 'some-mset-id',
measurements: [{
measureId: 'IA_EPA_4',
value: true
}]
}]
};

const postSubmissionWithReadyOnlyFields = {
programName: 'mips',
entityType: 'individual',
taxpayerIdentificationNumber: '000123456',
nationalProviderIdentifier: '0123456789',
performanceYear: 2017,
measurementSets: [{
category: 'ia',
submissionMethod: 'registry',
performanceStart: '2017-01-01',
performanceEnd: '2017-06-01',
suppressed: true,
measurements: [{
measureId: 'IA_EPA_4',
value: true
}]
}]
};

const cpcPlusSubmission = {
programName: 'mips',
entityType: 'individual',
Expand Down Expand Up @@ -368,6 +408,27 @@ describe('fileUploaderUtils', () => {
});
});

it('makes a network call to PUT /measurement-sets with nestJs read only properties removed', () => {
const axiosPutStub = sandbox.stub(axios, 'put').returns(new Promise((resolve, reject) => {
resolve({
data: {
data: {
measurementSet: validSubmission.measurementSets[0]
}
}
});
}));

return putMeasurementSet(putSubmissionWithReadyOnlyFields.measurementSets[0], baseOptions, '001')
.then((mSet) => {
sinon.assert.calledOnce(axiosPutStub);
assert.strictEqual(axiosPutStub.firstCall.args[0], '/measurement-sets/001');

assert.exists(mSet);
assert.deepEqual(validSubmission.measurementSets[0], mSet.measurementSet);
});
});

it('throws an error if the API returns anything other than a 200', () => {
sandbox.stub(axios, 'put').returns(new Promise((resolve, reject) => {
reject(new Error('Random API Error'));
Expand Down Expand Up @@ -407,6 +468,29 @@ describe('fileUploaderUtils', () => {
});
});

it('makes a network call to POST /measurement-sets with nestJs read only properties removed', () => {
const axiosPostStub = sandbox.stub(axios, 'post').returns(new Promise((resolve, reject) => {
resolve({
data: {
data: {
measurementSet: validSubmission.measurementSets[0],
warnings: ['test warning']
}
}
});
}));

return postMeasurementSet(postSubmissionWithReadyOnlyFields.measurementSets[0], baseOptions)
.then((mSet) => {
sinon.assert.calledOnce(axiosPostStub);
assert.strictEqual(axiosPostStub.firstCall.args[0], '/measurement-sets');

assert.exists(mSet);
assert.deepEqual(validSubmission.measurementSets[0], mSet.measurementSet);
assert.deepEqual(['test warning'], mSet.warnings);
});
});

it('throws an error if the API returns anything other than a 201', () => {
sandbox.stub(axios, 'post').returns(new Promise((resolve, reject) => {
reject(new Error('Random API Error'));
Expand Down

0 comments on commit 7b9827e

Please sign in to comment.