Skip to content

Commit

Permalink
Dmirano/4570 new prev activities mmis (#4588)
Browse files Browse the repository at this point in the history
* added new files for mmis results of prev activities

* updated files related to schema changes

* updated migrations

* updated frontend tests

* added front end test for new mmis tables

* added cypress test

* updated backend tests

* updated file names

* updated file names again

* updated file paths

* for HITECH APDs, merged the hitech tables component and the mmis tables component together

* updated snapshots

* added plural to file name of prev activity tables

* updated prev act totals table file name

* fixed hitech prev activities

* updated snapshots

* updated front end tests

* updated cypress tests - hitech results of prev activities

* updated cypress test

* updated cypress tests again

* even more cypress fixes

* reverted some changes

* updated snapshots

* cypress change

* typo

* even more cypress fixes

* running into problem with tables being synced

* fixed table sync issue

* fixed frontend tests

* fixed linter

* removed console.log

* refactors based on Amy's comments

* updated backend snapshot

* results of previous activities should not inlude the current year

* reverted prev years change

* updated snapshots
  • Loading branch information
mirano-darren authored Mar 17, 2023
1 parent 5a745e6 commit 3a94636
Show file tree
Hide file tree
Showing 42 changed files with 2,870 additions and 991 deletions.
87 changes: 87 additions & 0 deletions api/migrations/20230302152346_results-of-prev-activities-mmis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import loggerFactory from '../logger/index.js';
import { setup, teardown } from '../db/mongodb.js';
import { MMIS } from '../models/index.js';

const logger = loggerFactory(
'mongoose-migrate/migrate-results-of-previous-activities-mmis'
);

/**
* Update Results of Previous Activities page in MMIS APDs to have DDI and M&O
*/
export const up = async () => {
//Grab all APDs
await setup();
const apds = await MMIS.find().lean();
logger.info(`Updating ${apds.length} APDs`);

const updatedApds = apds.map(apd => {
const years = apd.years;
let prevYears = [];

[0, 1, 2].map(past => prevYears.unshift(years[0] - past));

if (apd.previousActivities.actualExpenditures[prevYears[0]].ddi) {
return apd;
}

return {
...apd,
id: apd._id,
previousActivities: {
...apd.previousActivities,
actualExpenditures: prevYears.reduce(
(acc, year) => ({
...acc,
[year]: {
ddi: {
50: {
federalActual: 0,
totalApproved: 0
},
75: {
federalActual: 0,
totalApproved: 0
},
90: {
federalActual: 0,
totalApproved: 0
}
},
mando: {
50: {
federalActual: 0,
totalApproved: 0
},
75: {
federalActual: 0,
totalApproved: 0
}
}
}
}),
{}
)
}
};
});

// Update them into the database
await Promise.all(
updatedApds.map(async apd => {
logger.info(
`Updating MMIS APD ${apd.id} to add ddi and mando to results of previous activities`
);
return MMIS.replaceOne({ _id: apd.id }, { ...apd });
})
).catch(err => {
logger.error(err);
});
await teardown();
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export const down = async () => {};
24 changes: 23 additions & 1 deletion api/models/mmis.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const mmisSchema = new mongoose.Schema(
type: Map,
of: new mongoose.Schema(
{
mmis: {
ddi: {
50: {
federalActual: {
type: Number,
Expand Down Expand Up @@ -76,6 +76,28 @@ const mmisSchema = new mongoose.Schema(
default: 0
}
}
},
mando: {
50: {
federalActual: {
type: Number,
default: 0
},
totalApproved: {
type: Number,
default: 0
}
},
75: {
federalActual: {
type: Number,
default: 0
},
totalApproved: {
type: Number,
default: 0
}
}
}
},
{ _id: false }
Expand Down
36 changes: 33 additions & 3 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.

36 changes: 30 additions & 6 deletions api/routes/apds/post.data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,24 +429,36 @@ tap.test('APD data initializer', async apdTests => {
previousActivitySummary: '',
actualExpenditures: {
1997: {
mmis: {
ddi: {
90: { federalActual: 0, totalApproved: 0 },
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
},
mando: {
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
}
},
1996: {
mmis: {
ddi: {
90: { federalActual: 0, totalApproved: 0 },
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
},
mando: {
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
}
},
1995: {
mmis: {
ddi: {
90: { federalActual: 0, totalApproved: 0 },
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
},
mando: {
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
}
}
}
Expand Down Expand Up @@ -520,24 +532,36 @@ tap.test('APD data initializer', async apdTests => {
previousActivitySummary: '',
actualExpenditures: {
1997: {
mmis: {
ddi: {
90: { federalActual: 0, totalApproved: 0 },
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
},
mando: {
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
}
},
1996: {
mmis: {
ddi: {
90: { federalActual: 0, totalApproved: 0 },
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
},
mando: {
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
}
},
1995: {
mmis: {
ddi: {
90: { federalActual: 0, totalApproved: 0 },
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
},
mando: {
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion api/routes/apds/post.mmis.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ const getNewMmisApd = (years, yearOptions) => {
previousActivitySummary: '',
actualExpenditures: forAllYears(
{
mmis: {
ddi: {
90: { federalActual: 0, totalApproved: 0 },
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
},
mando: {
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
}
},
[0, 1, 2].map(past => yearOptions[0] - past)
Expand Down
18 changes: 15 additions & 3 deletions api/routes/apds/post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,24 +395,36 @@ tap.test('apds POST endpoint', async endpointTest => {
previousActivitySummary: '',
actualExpenditures: {
2004: {
mmis: {
ddi: {
90: { federalActual: 0, totalApproved: 0 },
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
},
mando: {
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
}
},
2003: {
mmis: {
ddi: {
90: { federalActual: 0, totalApproved: 0 },
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
},
mando: {
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
}
},
2002: {
mmis: {
ddi: {
90: { federalActual: 0, totalApproved: 0 },
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
},
mando: {
75: { federalActual: 0, totalApproved: 0 },
50: { federalActual: 0, totalApproved: 0 }
}
}
}
Expand Down
34 changes: 33 additions & 1 deletion api/routes/openAPI/__snapshots__/get.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 3a94636

Please sign in to comment.