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

9069 audit date validation #185

Merged
merged 3 commits into from
Mar 14, 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
4 changes: 2 additions & 2 deletions frontend/src/components/coverage/enrollment/NameSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import useVuelidate from '@vuelidate/core'
import dayjs from 'dayjs'
import { API_DATE_FORMAT, GENDERS } from '../../../util/constants'
import { validateDOB, validateFirstName, validateSecondName, validateSurname, VALIDATE_DOB_MESSAGE, VALIDATE_FIRST_NAME_MESSAGE, VALIDATE_SECOND_NAME_MESSAGE, VALIDATE_SURNAME_MESSAGE } from '../../../util/validators'
import { validateFutureDate, validateFirstName, validateSecondName, validateSurname, VALIDATE_DOB_MESSAGE, VALIDATE_FIRST_NAME_MESSAGE, VALIDATE_SECOND_NAME_MESSAGE, VALIDATE_SURNAME_MESSAGE } from '../../../util/validators'
import { required, helpers, maxLength } from '@vuelidate/validators'
import { useAlertStore } from '../../../stores/alert'
import AppRadioButton from '../../ui/AppRadioButton.vue'
Expand Down Expand Up @@ -128,7 +128,7 @@ export default {
},
dateOfBirth: {
required,
validateDOB: helpers.withMessage(VALIDATE_DOB_MESSAGE, validateDOB),
validateDOB: helpers.withMessage(VALIDATE_DOB_MESSAGE, validateFutureDate),
},
gender: {
required,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ import {
validateGroupNumber,
validateGroupMemberNumber,
validateDepartmentNumber,
validateDOB,
validateFutureDate,
validateTelephone,
validateMailingPostalCode,
validatePostalCode,
Expand Down Expand Up @@ -353,7 +353,7 @@ export default {
},
dateOfBirth: {
required,
validateDOB: helpers.withMessage(VALIDATE_DOB_MESSAGE, validateDOB),
validateDOB: helpers.withMessage(VALIDATE_DOB_MESSAGE, validateFutureDate),
},
gender: {
required,
Expand Down
11 changes: 4 additions & 7 deletions frontend/src/util/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,13 @@ function validatePostalCodeFormat(postalCode) {
}

/**
* Validates that the Date of Birth is not in the future.
* Validates that the Date is not in the future.
*/
export function validateDOB(dateOfBirth) {
if (!helpers.req(dateOfBirth)) {
export function validateFutureDate(date) {
if (!helpers.req(date)) {
return true
}
if (dayjs(dateOfBirth).isAfter(dayjs().startOf('day'))) {
return false
}
return true
return !dayjs(date).isAfter(dayjs(), 'day')
}

/**
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/eligibility/CoverageStatusCheck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ import AppHelp from '../../components/ui/AppHelp.vue'
import AppTooltip from '../../components/ui/AppTooltip.vue'
import EligibilityService from '../../services/EligibilityService'
import useVuelidate from '@vuelidate/core'
import { validateDOB, validatePHN, VALIDATE_DOB_MESSAGE, VALIDATE_PHN_MESSAGE } from '../../util/validators'
import { validateFutureDate, validatePHN, VALIDATE_DOB_MESSAGE, VALIDATE_PHN_MESSAGE } from '../../util/validators'
import { API_DATE_FORMAT, COVERAGE_END_REASONS } from '../../util/constants'
import { required, helpers } from '@vuelidate/validators'
import dayjs from 'dayjs'
Expand Down Expand Up @@ -305,7 +305,7 @@ export default {
},
dateOfBirth: {
required,
validateDOB: helpers.withMessage(VALIDATE_DOB_MESSAGE, validateDOB),
validateDOB: helpers.withMessage(VALIDATE_DOB_MESSAGE, validateFutureDate),
},
dateOfService: {
required,
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/views/reports/AuditReporting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ import { API_DATE_TIME_FORMAT } from '../../util/constants'
import useVuelidate from '@vuelidate/core'
import { required, helpers } from '@vuelidate/validators'
import { DEFAULT_ERROR_MESSAGE } from '../../util/constants.js'
import { validateUserIdLength, VALIDATE_USER_ID_MESSAGE } from '../../util/validators'
import { validateFutureDate, validateUserIdLength, VALIDATE_USER_ID_MESSAGE } from '../../util/validators'
import { useAlertStore } from '../../stores/alert'
import { handleServiceError } from '../../util/utils'
import AppLabel from '../../components/ui/AppLabel.vue'
Expand All @@ -113,6 +113,9 @@ import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
import DataTable from 'primevue/datatable'
import Column from 'primevue/column'

const VALIDATE_END_DATE_MESSAGE = 'End Date must not be in the future'
const VALIDATE_START_DATE_MESSAGE = 'Start Date must not be in the future'

export default {
components: { AppLabel, Column, DataTable, AppDownloadLink },
name: 'AuditReporting',
Expand Down Expand Up @@ -358,9 +361,11 @@ export default {
},
startDate: {
required,
validateFutureDate: helpers.withMessage(VALIDATE_START_DATE_MESSAGE, validateFutureDate),
},
endDate: {
required,
validateFutureDate: helpers.withMessage(VALIDATE_END_DATE_MESSAGE, validateFutureDate),
},
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const INVALID_DOB_ERROR_MESSAGE = 'Date of Birth must not be in the future'

const DOS_REQUIRED_MESSAGE = 'Date Of Service is required'
const INVALID_PHN_ERROR_MESSAGE = 'PHN format is invalid'
const SUCCESS_MESSAGE = 'HJMB001I SUCCESSFULLY COMPLETED'
const SUCCESS_MESSAGE = 'HJMB001I TRANSACTION COMPLETED'

const PAGE_TO_TEST = SITE_UNDER_TEST + '/eligibility/coverageStatusCheck'

Expand Down
57 changes: 46 additions & 11 deletions frontend/tests/e2e/tests/reports/AuditReportingTest.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import AlertPage from '../../pages/AlertPage'
import AuditReportingPage from '../../pages/reports/AuditReportingPage'
import dayjs from 'dayjs'

import { OUTPUT_DATE_FORMAT } from '../../../../src/util/constants'
import { SITE_UNDER_TEST } from '../../configuration'
import dayjs from 'dayjs'
import AlertPage from '../../pages/AlertPage'
import AuditReportingPage from '../../pages/reports/AuditReportingPage'
import { regularAccUser } from '../../roles/roles'

const ERROR_MESSAGE = 'Please correct errors before submitting'
const USER_ID_EXCEEDS_LENGTH = 'User ID cannot be longer than 100 characters'
const START_DATE_REQUIRED_MESSAGE = 'Start Date is required'
const END_DATE_REQUIRED_MESSAGE = 'End Date is required'
const START_DATE_FUTURE_MESSAGE = 'Start Date must not be in the future'
const END_DATE_FUTURE_MESSAGE = 'End Date must not be in the future'
const START_DATE_AFTER_END_DATE = 'Start Date should not be after End Date'
const DATE_RANGE_EXCEEDS_THREE_MONTH = 'End Date should not be more than 3 months from Start Date'
const SUCCESS_MESSAGE = 'Transaction completed successfully'
Expand Down Expand Up @@ -38,7 +41,8 @@ test('Check required fields validation', async (t) => {
.expect(AuditReportingPage.errorText.nth(1).textContent)
.contains(END_DATE_REQUIRED_MESSAGE)
})
test('Check user id not exceeds 100 character validation', async (t) => {

test('Check user id not exceeds 100 character validation', async (t) => {
await t
// Given required fields aren't filled out (Start Date, End Date)
// When I click the submit button
Expand Down Expand Up @@ -68,7 +72,7 @@ test('Check Error message when end date exceeds 3 months from start date', async
.pressKey('tab')
// When I click the submit button
.click(AuditReportingPage.submitButton)
// I expect a success message
// I expect an error message
.expect(AlertPage.alertBannerText.textContent)
.contains(DATE_RANGE_EXCEEDS_THREE_MONTH)
})
Expand All @@ -91,11 +95,40 @@ test('Check Error message when end date is before start date', async (t) => {
.pressKey('tab')
// When I click the submit button
.click(AuditReportingPage.submitButton)
// I expect a success message
// I expect an error message
.expect(AlertPage.alertBannerText.textContent)
.contains(START_DATE_AFTER_END_DATE)
})

test('Check Error message when start date and end date are in the future', async (t) => {
let tomorrow = dayjs().add(1, 'day')
await t
// Given the page is filled out correctly
.typeText(AuditReportingPage.userIdInput, 'hnweb1')
.click(AuditReportingPage.checkBoxInput1) //Check box
.click(AuditReportingPage.checkBoxInput2) //Check box
.click(AuditReportingPage.checkBoxInput3) //Check box
.click(AuditReportingPage.checkBoxInput4) //Check box
.selectText(AuditReportingPage.startDateInput)
.pressKey('delete')
.typeText(AuditReportingPage.startDateInput, tomorrow.format(OUTPUT_DATE_FORMAT))
.pressKey('tab')
.selectText(AuditReportingPage.endDateInput)
.pressKey('delete')
.typeText(AuditReportingPage.endDateInput, tomorrow.format(OUTPUT_DATE_FORMAT))
.pressKey('tab')
// When I click the submit button
.click(AuditReportingPage.submitButton)
// I expect an error message stating the page had errors and individual error messages for
// the Start Date and End Date fields
.expect(AlertPage.alertBannerText.textContent)
.contains(ERROR_MESSAGE)
.expect(AuditReportingPage.errorText.nth(0).textContent)
.contains(START_DATE_FUTURE_MESSAGE)
.expect(AuditReportingPage.errorText.nth(1).textContent)
.contains(END_DATE_FUTURE_MESSAGE)
})

test('Check properly filled form passes validation and validate results', async (t) => {
await t
// Given the page is filled out correctly
Expand Down Expand Up @@ -136,16 +169,18 @@ test('Check properly filled form passes validation and validate results', async
.expect(AuditReportingPage.resultsRow1.child('td').nth(1).textContent)
.eql('00000010')
.expect(AuditReportingPage.resultsRow1.child('td').nth(2).textContent)
.eql('TRAININGHEALTHAUTH')
.eql('')
.expect(AuditReportingPage.resultsRow1.child('td').nth(3).textContent)
.eql('hnweb1')
.eql('TRAININGHEALTHAUTH')
.expect(AuditReportingPage.resultsRow1.child('td').nth(4).textContent)
.eql('2022-12-12T13:53:12.059')
.eql('hnweb1')
.expect(AuditReportingPage.resultsRow1.child('td').nth(5).textContent)
.eql('9873102617')
.contains('2022-12-12')
.expect(AuditReportingPage.resultsRow1.child('td').nth(6).textContent)
.eql('PHN')
.eql('9873102617')
.expect(AuditReportingPage.resultsRow1.child('td').nth(7).textContent)
.eql('PHN')
.expect(AuditReportingPage.resultsRow1.child('td').nth(8).textContent)
.eql('d9291fb5-6a30-43ea-bd71-891c02b939d0')
})

Expand Down