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

PP-10608: Correcting the number of days in transaction queries. #4178

Merged
merged 1 commit into from
Feb 23, 2024
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
2 changes: 1 addition & 1 deletion app/controllers/all-service-transactions/get.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = async function getTransactionsForAllServices (req, res, next) {
const searchResultOutput = await transactionService.search(userPermittedAccountsSummary.gatewayAccountIds, filters.result)
const cardTypes = await client.getAllCardTypes()
const downloadRoute = filterLiveAccounts ? paths.allServiceTransactions.download : paths.formattedPathFor(paths.allServiceTransactions.downloadStatusFilter, 'test')
const model = buildPaymentList(searchResultOutput, cardTypes, null, filters.result,filters.dateRangeState, downloadRoute, req.session.backPath)
const model = buildPaymentList(searchResultOutput, cardTypes, null, filters.result, filters.dateRangeState, downloadRoute, req.session.backPath)
delete req.session.backPath
model.search_path = filterLiveAccounts ? paths.allServiceTransactions.index : paths.formattedPathFor(paths.allServiceTransactions.indexStatusFilter, 'test')
model.filtersDescription = describeFilters(filters.result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ 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.calledWith(response.render,'transactions/index',sinon.match({
sinon.assert.calledWith(response.render, 'transactions/index', sinon.match({
'isInvalidDateRange': true,
'hasResults': false,
'fromDateParam': "03/5/2018",
'toDateParam': "01/5/2018",
'fromDateParam': '03/5/2018',
'toDateParam': '01/5/2018'
}))
})
})
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/dashboard/dashboard-activity.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ function getTransactionDateRange (period) {
daysAgo = 1
break
case 'previous-seven-days':
daysAgo = 8 // 7+1 because we count starting from yesterday
daysAgo = 7
break
case 'previous-thirty-days':
daysAgo = 31 // 30+1 because we count starting from yesterday
daysAgo = 30
break
}

Expand Down
25 changes: 12 additions & 13 deletions app/controllers/transactions/transaction-list.controller.it.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const paths = require('../../paths')
const formatAccountPathsFor = require('../../utils/format-account-paths-for')
const { validGatewayAccountResponse } = require('../../../test/fixtures/gateway-account.fixtures')
const transactionListController = require('./transaction-list.controller')
const proxyquire = require("proxyquire");
const ledgerTransactionFixture = require("../../../test/fixtures/ledger-transaction.fixtures");
const gatewayAccountFixture = require("../../../test/fixtures/gateway-account.fixtures");
const Service = require("../../models/Service.class");
const serviceFixtures = require("../../../test/fixtures/service.fixtures");
const User = require("../../models/User.class");
const userFixtures = require("../../../test/fixtures/user.fixtures");
const proxyquire = require('proxyquire')
const ledgerTransactionFixture = require('../../../test/fixtures/ledger-transaction.fixtures')
const gatewayAccountFixture = require('../../../test/fixtures/gateway-account.fixtures')
const Service = require('../../models/Service.class')
const serviceFixtures = require('../../../test/fixtures/service.fixtures')
const User = require('../../models/User.class')
const userFixtures = require('../../../test/fixtures/user.fixtures')

// Setup
const gatewayAccountId = '651342'
Expand All @@ -21,7 +21,7 @@ const headers = { 'x-request-id': requestId }

describe('The /transactions endpoint', () => {
const transactionSearchResponse = ledgerTransactionFixture.validTransactionSearchResponse(
{ transactions: [] })
{ transactions: [] })
const account = validGatewayAccountResponse(
{
external_id: EXTERNAL_GATEWAY_ACCOUNT_ID,
Expand Down Expand Up @@ -77,12 +77,12 @@ 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.calledWith(response.render,'transactions/index',sinon.match({
sinon.assert.calledWith(response.render, 'transactions/index', sinon.match({
'isInvalidDateRange': true,
'hasResults': false,
'fromDateParam': "03/5/2018",
'toDateParam': "01/5/2018",
}))
'fromDateParam': '03/5/2018',
'toDateParam': '01/5/2018'
}))
})
})

Expand Down Expand Up @@ -143,5 +143,4 @@ describe('The /transactions endpoint', () => {
}
})
}

})
8 changes: 4 additions & 4 deletions app/controllers/transactions/transaction-list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = async function showTransactionList (req, res, next) {
page: 1,
results: [],
_links: {},
filters: {},
filters: {}
}
req.session.filters = url.parse(req.url).query

Expand All @@ -32,10 +32,10 @@ module.exports = async function showTransactionList (req, res, next) {
}

let result
let transactionSearchResults = (filters.dateRangeState.isInvalidDateRange) ?
EMPTY_TRANSACTION_SEARCH_RESULTS : transactionService.search([accountId], filters.result)
let transactionSearchResults = (filters.dateRangeState.isInvalidDateRange)
? EMPTY_TRANSACTION_SEARCH_RESULTS : transactionService.search([accountId], filters.result)
try {
result = await Promise.all([ transactionSearchResults, client.getAllCardTypes() ])
result = await Promise.all([ transactionSearchResults, client.getAllCardTypes() ])
} catch (error) {
return next(error)
}
Expand Down
12 changes: 6 additions & 6 deletions app/utils/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ function trimFilterValues (filters) {
return filters
}

function validateDateRange(filters){
const result = moment(filters.fromDate, 'DD/MM/YYYY').isAfter(moment(filters.toDate, 'DD/MM/YYYY'))? 1: -1;
function validateDateRange (filters) {
const result = moment(filters.fromDate, 'DD/MM/YYYY').isAfter(moment(filters.toDate, 'DD/MM/YYYY')) ? 1 : -1
let isInvalid = false

if (result === 1) {
isInvalid = true
}
return {
if (result === 1) {
isInvalid = true
}
return {
isInvalidDateRange: isInvalid,
fromDateParam: filters.fromDate,
toDateParam: filters.toDate
Expand Down
2 changes: 1 addition & 1 deletion app/utils/transaction-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
connectorData.hasPageSizeLinks = hasPageSizeLinks(connectorData)
connectorData.pageSizeLinks = getPageSizeLinks(connectorData)

if(filtersDateRangeState){
if (filtersDateRangeState) {
connectorData.isInvalidDateRange = filtersDateRangeState.isInvalidDateRange === true
connectorData.fromDateParam = filtersDateRangeState.fromDateParam
connectorData.toDateParam = filtersDateRangeState.toDateParam
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Account dashboard', () => {
refundTotal: 2300
})
const prevSevenDaysStatisticsStub = transactionsSummaryStubs.getDashboardStatisticsWithFromDate(
moment().subtract(8, 'days').tz('Europe/London').startOf('day').format(),
moment().subtract(7, 'days').tz('Europe/London').startOf('day').format(),
{
paymentCount: 50,
paymentTotal: 70000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('dashboard-activity-controller', () => {
nock(LEDGER_URL)
.get('/v1/report/transactions-summary')
.query(obj => {
return obj.from_date === moment().tz('Europe/London').startOf('day').subtract(8, 'days').format()
return obj.from_date === moment().tz('Europe/London').startOf('day').subtract(7, 'days').format()
})
.reply(200, DASHBOARD_RESPONSE)

Expand Down Expand Up @@ -325,7 +325,7 @@ describe('dashboard-activity-controller', () => {

it('it should print the time period in the summary box', () => {
expect($('.dashboard-total-explainer').text())
.to.contain(moment().tz('Europe/London').startOf('day').subtract(8, 'days').format('D MMMM YYYY h:mm:ssa z'))
.to.contain(moment().tz('Europe/London').startOf('day').subtract(7, 'days').format('D MMMM YYYY h:mm:ssa z'))
})
})
describe('and the period is set to previous 30 days', () => {
Expand All @@ -344,7 +344,7 @@ describe('dashboard-activity-controller', () => {
nock(LEDGER_URL)
.get('/v1/report/transactions-summary')
.query(obj => {
return obj.from_date === moment().tz('Europe/London').startOf('day').subtract(31, 'days').format()
return obj.from_date === moment().tz('Europe/London').startOf('day').subtract(30, 'days').format()
})
.reply(200, DASHBOARD_RESPONSE)

Expand Down Expand Up @@ -378,7 +378,7 @@ describe('dashboard-activity-controller', () => {

it('it should print the time period in the summary box', () => {
expect($('.dashboard-total-explainer').text())
.to.contain(moment().tz('Europe/London').startOf('day').subtract(31, 'days').format('D MMMM YYYY h:mm:ssa z'))
.to.contain(moment().tz('Europe/London').startOf('day').subtract(30, 'days').format('D MMMM YYYY h:mm:ssa z'))
})
})
})
Expand Down
Loading