Skip to content

Commit

Permalink
Change order of fields and field/title names on Cost Allocation and O…
Browse files Browse the repository at this point in the history
…ther Funding + Budget and FFP pages. #2322 (#2474)

* use node v10 via node version manager* prefer doc format output from tap
* add validateApd function, validate development seed data
* validate seed data, fix bad seed data
* refactor apd.json schema
* remove vcap junk
* Update CHANGELOG.md
* add knex-console script, add {migrate,seed}-dev scripts
* update audit ci
* render costAllocationNarrative keys that are years
  • Loading branch information
radavis authored Oct 5, 2020
1 parent 840ed02 commit e4624b1
Show file tree
Hide file tree
Showing 62 changed files with 2,772 additions and 2,092 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ npm-debug.log*
pgdata
__files
api/test-data/files
notes.md
schema.sql
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
10 changes: 2 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
Anticipated release: September 21st, 2020

#### 🚀 New features

- Results of previous activities fields are missing in export view ([#2420])
- Standards and conditions is in the wrong area on export view ([#2386])
- Match private contractor costs section on export view to builder ([#2393])
- Change order of fields and field/title names on Cost Allocation and Other Funding + Budget and FFP pages. ([#2322])

#### 🐛 Bugs fixed

Expand All @@ -17,7 +14,4 @@ Anticipated release: September 21st, 2020
# Previous releases

See our [release history](https://github.com/CMSgov/eAPD/releases)

[#2420]: https://github.com/CMSgov/eAPD/issues/2420
[#2386]: https://github.com/CMSgov/eAPD/issues/2386
[#2393]: https://github.com/CMSgov/eAPD/issues/2393
[#2322]: https://github.com/CMSgov/eAPD/issues/2322
11 changes: 9 additions & 2 deletions api/db/knex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const knex = require('knex');
const config = require('../knexfile');

const db = process.env.NODE_ENV ? knex(config[process.env.NODE_ENV]) : () => {};
const { NODE_ENV } = process.env;
if (!NODE_ENV) {
let msg = "❌ NODE_ENV is not set, unable to determine knex configuration\n";
msg += "Please set NODE_ENV to 'development', 'test', or 'production'\n";
msg += "Terminating...";
console.error(msg); /* eslint-disable-line no-console */
process.exit(1);
}

module.exports = db;
module.exports = knex(config[NODE_ENV]);
19 changes: 1 addition & 18 deletions api/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,8 @@ const defaults = {
STORE_TYPE: 'null' // default to using the /dev/null store
};

// Check if there are any CloudFoundry user-provided services
// offering up environment variables. If there are, extract
// them and merge them into our environment.
const upsEnv = {};
if (process.env.VCAP_SERVICES) {
try {
const vcap = JSON.parse(process.env.VCAP_SERVICES);
if (Array.isArray(vcap['user-provided'])) {
vcap['user-provided'].forEach(ups => {
Object.entries(ups.credentials).forEach(([name, value]) => {
upsEnv[name] = value;
});
});
}
} catch (e) {} // eslint-disable-line no-empty
}

dotenv.config();
process.env = { ...defaults, ...upsEnv, ...process.env };
process.env = { ...defaults, ...process.env };

// Don't require this until process.env is finished setting up, since that
// defines how the logger works.
Expand Down
22 changes: 0 additions & 22 deletions api/env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,6 @@ tap.test('environment setup', async envTest => {
}
);

envTest.test(
'reads environment variables from CF user-provided services',
async test => {
process.env.VCAP_SERVICES = JSON.stringify({
'user-provided': [
{
credentials: {
VCAP_VAR1: 'var1',
VCAP_VAR2: 'var2'
}
}
]
});
require('./env'); // eslint-disable-line global-require
test.match(
process.env,
{ VCAP_VAR1: 'var1', VCAP_VAR2: 'var2' },
'sets variables from CF user-provided service'
);
}
);

envTest.test(
'does not override environment variables that have been set externally',
async test => {
Expand Down
17 changes: 17 additions & 0 deletions api/knexrepl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// https://medium.com/@sobinsunny/orm-console-with-repl-961ee264ed93

// usage:
// $ npm run knex-console
// knex> const rows = await knex('apds')
// knex> rows[0].document.activities
// knex> .exit

require('dotenv').config();
const repl = require('repl');
const knex = require('./db/knex')

const r = repl.start('knex> ');
const run = async () => {
r.context.knex = await knex;
};
run();
24 changes: 24 additions & 0 deletions api/migrations/20200918103000_add-ffy-to-other-funding-desc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable no-param-reassign */
exports.up = async knex => {
const apdRecords = await knex('apds').select('document', 'id', 'years');

apdRecords.forEach(({ document, id }) => {
const years = document.years;

document.activities.forEach(activity => {
const otherSources = activity.costAllocationNarrative.otherSources || ""
years.forEach(year => {
activity.costAllocationNarrative[year] = {
otherSources
}
});
delete activity.costAllocationNarrative.otherSources;
});

knex('apds')
.where('id', id)
.update({ document });
});
};

exports.down = async () => {};
6 changes: 6 additions & 0 deletions api/package-lock.json

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

9 changes: 7 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
"main": "main.js",
"scripts": {
"audit": "npx audit-ci --config ./audit-ci.json",
"knex-console": "NODE_ENV=development node --experimental-repl-await knexrepl.js",
"lint": "eslint '**/*.js'",
"make-migrate": "knex migrate:make",
"migrate": "knex migrate:latest",
"migrate-dev": "NODE_ENV=development DEV_DB_HOST=localhost npm run migrate",
"rollback": "knex migrate:rollback",
"seed": "knex seed:run",
"seed-dev": "NODE_ENV=development DEV_DB_HOST=localhost npm run seed",
"start": "node main.js",
"start-dev": "nodemon ./main.js -e js",
"start-dev": "NODE_ENV=development DEV_DB_HOST=localhost nodemon ./main.js -e js",
"jest": "NODE_ENV=test jest",
"tap": "NODE_ENV=test tap -J --no-browser --no-coverage --no-timeout ${TESTS:-'{,!(node_modules)/**/}*.test.js'}",
"tap": "NODE_ENV=test tap -J --no-browser --no-coverage --no-timeout --reporter=spec ${TESTS:-'{,!(node_modules)/**/}*.test.js'}",
"test": "NODE_ENV=test tap -J --cov --coverage-report=lcov --no-browser --no-timeout --reporter=spec --test-arg=--silent '{,!(node_modules)/**/}*.test.js'",
"test-endpoints": "jest --detectOpenHandles --runInBand '.+\\.endpoint\\.js'",
"test-specific": "NODE_ENV=test tap --cov --coverage-report=lcov --no-browser --reporter=spec",
Expand Down Expand Up @@ -96,6 +100,7 @@
"jest": "^25.2.1",
"nodemon": "^2.0.4",
"prettier": "^1.19.1",
"repl": "^0.1.3",
"sinon": "^8.1.1",
"stream-mock": "^2.0.5",
"tap": "^14.10.8"
Expand Down
59 changes: 49 additions & 10 deletions api/routes/apds/__snapshots__/get.endpoint.js.snap

Large diffs are not rendered by default.

200 changes: 184 additions & 16 deletions api/routes/apds/__snapshots__/patch.endpoint.js.snap

Large diffs are not rendered by default.

43 changes: 24 additions & 19 deletions api/routes/apds/__snapshots__/post.endpoint.js.snap

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

Loading

0 comments on commit e4624b1

Please sign in to comment.