Skip to content

Commit

Permalink
PP-11877 new test for date validation and PR update
Browse files Browse the repository at this point in the history
  • Loading branch information
olatomgds committed Dec 20, 2023
1 parent c90d350 commit 9d6b7ea
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ describe('All service transactions - GET', () => {
it('should return the response with the date-range failing validation with empty transaction results indicator', async () => {
await getController()(request, response, next)

sinon.assert.called(response.render)
expect(response.render.firstCall.args[0]).to.equal('transactions/index')
expect(response.render.firstCall.args[1].hasResults).to.equal(false)
expect(response.render.firstCall.args[1].isInvalidDateRange).to.equal(true)
expect(response.render.firstCall.args[1].fromDateParam).to.equal('03/5/2018')
expect(response.render.firstCall.args[1].toDateParam).to.equal('01/5/2018')
sinon.assert.calledWith(response.render,'transactions/index',response.render.firstCall.args[1])
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ describe('The /transactions endpoint', () => {
it('should return the response with the date-range failing validation with empty transaction results indicator', async () => {
await getController()(request, response, next)

sinon.assert.called(response.render)
expect(response.render.firstCall.args[0]).to.equal('transactions/index')
expect(response.render.firstCall.args[1].hasResults).to.equal(false)
expect(response.render.firstCall.args[1].isInvalidDateRange).to.equal(true)
expect(response.render.firstCall.args[1].fromDateParam).to.equal('03/5/2018')
expect(response.render.firstCall.args[1].toDateParam).to.equal('01/5/2018')
sinon.assert.calledWith(response.render,'transactions/index',response.render.firstCall.args[1])
})
})

Expand Down
3 changes: 2 additions & 1 deletion app/utils/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ function describeFilters (filters) {

module.exports = {
getFilters: getFilters,
describeFilters: describeFilters
describeFilters: describeFilters,
validateDateRange: validateDateRange
}
13 changes: 13 additions & 0 deletions app/utils/filters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,18 @@ describe('filters', () => {
expect(result.trim()).to.equal('from <strong>from-date</strong> to <strong>to-date</strong>')
})
})

describe('validateDateRange', () => {
it('should validate the date range filter and return an array with the result and the associated from and to date', function () {
const testFilter = {
fromDate: '03/03/2023',
toDate: '01/03/2023'
}
const result = filters.validateDateRange(testFilter)
expect(result.isInvalidDateRange).to.equal(true)
expect(result.fromDateParam).to.equal('03/03/2023')
expect(result.toDateParam).to.equal('01/03/2023')
})
})
})
})
15 changes: 1 addition & 14 deletions test/cypress/integration/transactions/transaction-search.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ describe('Transactions List', () => {
'test@example.org', '–£15.00', 'Visa', 'Refund submitted')
})

it('should be display error message when searching with from date later than to date', () => {
it('should display error message when searching with from date later than to date', () => {
cy.task('setupStubs', [
...sharedStubs(),
transactionsStubs.getLedgerTransactionsSuccess({ gatewayAccountId, transactions: unfilteredTransactions }),
Expand All @@ -350,46 +350,33 @@ describe('Transactions List', () => {
])
cy.visit(transactionsUrl)

// 1. Filtering FROM
// Ensure both the date/time pickers aren't showing
cy.get('.datepicker').should('not.exist')
cy.get('.ui-timepicker-wrapper').should('not.exist')

// Fill in a from date
cy.get('#fromDate').type('03/5/2018')

// Ensure only the datepicker is showing
cy.get('.datepicker').should('be.visible')
cy.get('.ui-timepicker-wrapper').should('not.exist')

// Fill in a from time
cy.get('#fromTime').type('01:00:00')

// Ensure only the timepicker is showing
cy.get('.datepicker').should('not.exist')
cy.get('.ui-timepicker-wrapper').should('be.visible')

// Fill in the to date
cy.get('#toDate').type('02/5/2018')

// Ensure only the datepicker is showing
cy.get('.datepicker').should('be.visible')
cy.get('.ui-timepicker-wrapper').should('not.be.visible')

// Fill in the to time
cy.get('#toTime').type('01:00:00')

// Ensure only the timepicker is showing
cy.get('.datepicker').should('not.exist')
cy.get('.ui-timepicker-wrapper').should('be.visible')

// Click the filter button
cy.get('#filter').click()

// Ensure that transaction list is not displayed
cy.get('#transactions-list tbody').should('not.exist')

// Ensure a filter failed validation message is displayed
cy.get('h3').contains('End date must be after start date' )
})
})
Expand Down

0 comments on commit 9d6b7ea

Please sign in to comment.