-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PP-12100 Allow user to apply filters after all services search timeout
- Add new error for a ledger timeout on all services transactions search - Link from the error page to the all services transaction search page, without the automatic search, to avoid a perpetual timeout - Refactor to share the code that populates the model - Update unit tests - Update cypress tests
- Loading branch information
1 parent
9ca24f5
commit 69cf850
Showing
19 changed files
with
486 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...controllers/all-service-transactions/all-service-transactions-no-autosearch.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
|
||
const { response } = require('../../utils/response') | ||
const { populateModel } = require('./populateModel') | ||
const { getFilters } = require('../../utils/filters') | ||
const permissions = require('../../utils/permissions') | ||
|
||
module.exports = async function getTransactionsForAllServicesNoSearch (req, res, next) { | ||
const filters = getFilters(req) | ||
const { statusFilter } = req.params | ||
const filterLiveAccounts = statusFilter !== 'test' | ||
const userPermittedAccountsSummary = await permissions.getGatewayAccountsFor(req.user, filterLiveAccounts, 'transactions:read') | ||
const model = await populateModel(req, { results: [] }, filters, null, filterLiveAccounts, userPermittedAccountsSummary); | ||
model.allServicesTimeout = true | ||
try { | ||
return response(req, res, 'transactions/index', model) | ||
} catch (err) { | ||
next(new Error('Unable to fetch transaction information')) | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...ollers/all-service-transactions/all-service-transactions-no-autosearch.controller.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const sinon = require('sinon') | ||
const proxyquire = require('proxyquire') | ||
const User = require('../../models/User.class') | ||
const userFixtures = require('../../../test/fixtures/user.fixtures') | ||
const gatewayAccountFixture = require('../../../test/fixtures/gateway-account.fixtures') | ||
const Service = require('../../models/Service.class') | ||
const serviceFixtures = require('../../../test/fixtures/service.fixtures') | ||
|
||
describe('All service transactions no autosearch - GET', () => { | ||
let req, res, next | ||
const user = new User(userFixtures.validUserResponse()) | ||
const service = new Service(serviceFixtures.validServiceResponse({})) | ||
let userPermittedAccountsSummary = { | ||
gatewayAccountIds: [31], | ||
headers: { shouldGetStripeHeaders: true, shouldGetMotoHeaders: true }, | ||
hasLiveAccounts: false, | ||
hasStripeAccount: true, | ||
hasTestStripeAccount: false | ||
} | ||
const modelMock = sinon.spy(() => ({ | ||
isStripeAccount: true, | ||
filterLiveAccounts: true | ||
})) | ||
const responseMock = sinon.spy(() => null) | ||
const filterMock = sinon.spy(() => ['a-filter']) | ||
|
||
beforeEach(() => { | ||
req = { | ||
account: gatewayAccountFixture.validGatewayAccount({ 'payment_provider': 'stripe' }), | ||
flash: sinon.spy(), | ||
service: service, | ||
user: user, | ||
params: {}, | ||
url: 'http://selfservice/all-servce-transactions', | ||
session: {}, | ||
headers: { | ||
'x-request-id': 'correlation-id' | ||
} | ||
} | ||
res = { | ||
render: sinon.spy() | ||
} | ||
next = sinon.spy() | ||
}) | ||
|
||
describe('Stripe account', () => { | ||
it('should return a response with a model with `allServicesTimeout: true`', async () => { | ||
await getController()(req, res, next) | ||
|
||
sinon.assert.calledWith(filterMock, req) | ||
sinon.assert.calledWith(modelMock, req, { results: [] }, ['a-filter'], null, true, userPermittedAccountsSummary) | ||
|
||
sinon.assert.calledWith(responseMock, req, res, 'transactions/index', { | ||
isStripeAccount: true, | ||
filterLiveAccounts: true, | ||
allServicesTimeout: true | ||
}) | ||
}) | ||
}) | ||
|
||
function getController () { | ||
return proxyquire('./all-service-transactions-no-autosearch.controller', { | ||
'../../utils/permissions': { | ||
getGatewayAccountsFor: sinon.spy(() => Promise.resolve(userPermittedAccountsSummary)) | ||
}, | ||
'./populateModel': { | ||
populateModel: modelMock | ||
}, | ||
'../../utils/response': { | ||
response: responseMock | ||
}, | ||
'../../utils/filters.js': { | ||
getFilters: filterMock | ||
} | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const { buildPaymentList } = require('../../utils/transaction-view') | ||
const paths = require('../../paths') | ||
const { describeFilters } = require('../../utils/filters') | ||
const states = require('../../utils/states') | ||
const _ = require('lodash') | ||
const { ConnectorClient } = require('../../services/clients/connector.client') | ||
const client = new ConnectorClient(process.env.CONNECTOR_URL) | ||
|
||
async function populateModel (req, searchResultOutput, filters, downloadRoute, filterLiveAccounts, userPermittedAccountsSummary) { | ||
const cardTypes = await client.getAllCardTypes() | ||
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) | ||
model.eventStates = states.allDisplayStateSelectorObjects(userPermittedAccountsSummary.hasStripeAccount) | ||
.map(state => { | ||
return { | ||
value: state.key, | ||
text: state.name, | ||
selected: filters.result.selectedStates && filters.result.selectedStates.includes(state.name) | ||
} | ||
}) | ||
model.eventStates.unshift({ value: '', text: 'Any', selected: false }) | ||
|
||
model.stateFiltersFriendly = model.eventStates | ||
.filter(state => state.selected) | ||
.map(state => state.text) | ||
.join(', ') | ||
|
||
if (_.has(filters.result, 'brand')) { | ||
model.cardBrands.forEach(brand => { | ||
brand.selected = filters.result.brand.includes(brand.value) | ||
}) | ||
} | ||
|
||
model.clearRedirect = model.search_path | ||
model.isStripeAccount = userPermittedAccountsSummary.headers.shouldGetStripeHeaders | ||
model.allServiceTransactions = true | ||
model.filterLiveAccounts = filterLiveAccounts | ||
model.hasLiveAccounts = userPermittedAccountsSummary.hasLiveAccounts | ||
model.recurringEnabled = userPermittedAccountsSummary.hasRecurringAccount | ||
model.isExperimentalFeaturesEnabled = req.user.serviceRoles.some(serviceRole => serviceRole.service.experimentalFeaturesEnabled) | ||
|
||
return model | ||
} | ||
|
||
module.exports = { populateModel } |
Oops, something went wrong.