Skip to content

Commit

Permalink
EMP-434 tidy up code
Browse files Browse the repository at this point in the history
  • Loading branch information
muyinatech committed Aug 14, 2024
1 parent a7df9dc commit ba7c3f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
40 changes: 20 additions & 20 deletions server/utils/generateReportValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Generate Report Validation', () => {
'endDate',
{ crmType: 'crm4', startDate: '2024-01-01', endDate: '2023-12-01' },
],
])('should return error for %s', (errorMessage: string, fieldName: string, reportParams: Record<string, string>) => {
])('should return "%s" error', (errorMessage: string, fieldName: string, reportParams: Record<string, string>) => {
const result = validateReportParams(reportParams)

expect(result).toEqual({
Expand All @@ -40,6 +40,25 @@ describe('Generate Report Validation', () => {
})
})

it('should return "Date range cannot not be more than 1 month" error', () => {
const reportParams: Record<string, string> = {
crmType: 'crm4',
startDate: '2024-01-01',
endDate: '2024-04-01',
}
const result = validateReportParams(reportParams)

expect(result).toEqual({
list: [
{
href: `#`,
text: 'Date range cannot not be more than 1 month',
},
],
messages: {},
})
})

it('should return errors for missing Start Date', () => {
const reportParams: Record<string, string> = {
crmType: 'crm4',
Expand Down Expand Up @@ -70,25 +89,6 @@ describe('Generate Report Validation', () => {
})
})

it('should return "Date range cannot not be more than 1 month" errors', () => {
const reportParams: Record<string, string> = {
crmType: 'crm4',
startDate: '2024-01-01',
endDate: '2024-04-01',
}
const result = validateReportParams(reportParams)

expect(result).toEqual({
list: [
{
href: `#`,
text: 'Date range cannot not be more than 1 month',
},
],
messages: {},
})
})

it('should return multiple errors', () => {
const reportParams: Record<string, string> = {
crmType: 'xxx',
Expand Down
5 changes: 2 additions & 3 deletions server/utils/searchEformValidation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import validateSearchParams from './searchEformValidation'
import validateReportParams from './generateReportValidation'

describe('Search Eform Validation', () => {
it('should validate search parameters', () => {
Expand Down Expand Up @@ -53,11 +52,11 @@ describe('Search Eform Validation', () => {
['Start date must be a valid date', 'startDate', '5555-55-55'],
['End date must be a valid date', 'endDate', '5555-55-55'],
])('should return "%s" error for %s = %s', (errorMessage: string, fieldName: string, fieldValue: string) => {
const formData = {
const searchParams: Record<string, string> = {
[fieldName]: fieldValue,
}

const result = validateSearchParams(formData)
const result = validateSearchParams(searchParams)

expect(result).toEqual({
list: [
Expand Down

0 comments on commit ba7c3f7

Please sign in to comment.