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

Migrate OMIS reconciliation CollectionList to React Router #6541

Merged
merged 2 commits into from
Feb 21, 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
41 changes: 0 additions & 41 deletions src/apps/__test__/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,47 +267,6 @@ describe('Apps middleware', () => {
})
})

describe('setDefaultQuery()', () => {
beforeEach(() => {
this.resMock = {
redirect: sinon.spy(),
}
})

it('should redirect to default query if initial query is empty', () => {
const reqMock = {
query: {},
originalUrl: '/sub-app',
}
this.middleware.setDefaultQuery({
filter: 'apple',
sortby: 'sweetness',
})(reqMock, this.resMock, this.nextSpy)

expect(this.nextSpy).to.not.have.been.called
expect(this.resMock.redirect).to.be.calledWith(
'?filter=apple&sortby=sweetness'
)
})

it('should not redirect if query contains properties', () => {
const reqMock = {
query: {
filter: 'pear',
},
originalUrl: '/sub-app',
}

this.middleware.setDefaultQuery({
filter: 'apple',
sortby: 'sweetness',
})(reqMock, this.resMock, this.nextSpy)

expect(this.nextSpy).to.have.been.called
expect(this.resMock.redirect).to.not.have.been.called
})
})

describe('handleRoutePermissions()', () => {
const mockUrl = '/mock-url'

Expand Down
18 changes: 1 addition & 17 deletions src/apps/middleware.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { get, isEmpty, assign, intersection, isUndefined } = require('lodash')
const { get, assign, intersection, isUndefined } = require('lodash')
const queryString = require('qs')
const { parse } = require('url')
const path = require('path')
Expand All @@ -22,11 +22,6 @@ function setHomeBreadcrumb(text) {
}
}

function removeBreadcrumb(req, res, next) {
res.removeBreadcrumb()
next()
}

function isPermittedRoute(pathname, routes, userPermissions) {
const routePermissions = get(
routes.find((route) => {
Expand Down Expand Up @@ -77,15 +72,6 @@ function setLocalNav(items = [], appendBaseUrl = true) {
}
}

function setDefaultQuery(query = {}) {
return function handleDefaultRedirect(req, res, next) {
if (isEmpty(req.query)) {
return res.redirect(`?${queryString.stringify(query)}`)
}
next()
}
}

function redirectToFirstNavItem(req, res) {
return res.redirect(res.locals.localNavItems[0].url)
}
Expand All @@ -99,10 +85,8 @@ function redirectWithQueryString(req, res, relativeUrl) {

module.exports = {
setHomeBreadcrumb,
removeBreadcrumb,
setLocalNav,
redirectToFirstNavItem,
setDefaultQuery,
handleRoutePermissions,
isPermittedRoute,
redirectWithQueryString,
Expand Down
29 changes: 0 additions & 29 deletions src/apps/omis/__test__/transformers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,33 +150,4 @@ describe('OMIS list transformers', () => {
})
})
})

describe('#transformOrderToTableItem', () => {
const simpleOrder = require('../../../../test/unit/data/omis/simple-order.json')

context('when given an unqualified result', () => {
it('should return undefined', () => {
expect(this.transformers.transformOrderToTableItem()).to.be.undefined
expect(this.transformers.transformOrderToTableItem({ a: 'b' })).to.be
.undefined
expect(this.transformers.transformOrderToTableItem({ id: 'abcd' })).to
.be.undefined
expect(
this.transformers.transformOrderToTableItem({ reference: 'Z123/SD' })
).to.be.undefined
})
})

context('when given a qualified result', () => {
it('should return a transformed object', () => {
const actual = this.transformers.transformOrderToTableItem(simpleOrder)

expect(actual).to.have.property('id').a('string')
expect(actual).to.have.property('reference').a('string')
expect(actual).to.have.property('subtotal_cost').a('number')
expect(actual).to.have.property('total_cost').a('number')
expect(actual).to.have.property('company').a('string')
})
})
})
})
7 changes: 0 additions & 7 deletions src/apps/omis/apps/reconciliation/controllers.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/apps/omis/apps/reconciliation/index.js

This file was deleted.

28 changes: 0 additions & 28 deletions src/apps/omis/apps/reconciliation/router.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/apps/omis/apps/reconciliation/views/list-reconciliation.njk

This file was deleted.

54 changes: 0 additions & 54 deletions src/apps/omis/fields.js

This file was deleted.

13 changes: 1 addition & 12 deletions src/apps/omis/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,15 @@ const router = require('express').Router()

const { APP_PERMISSIONS } = require('./constants')

const {
setHomeBreadcrumb,
removeBreadcrumb,
handleRoutePermissions,
} = require('../middleware')
const { handleRoutePermissions } = require('../middleware')
const { setOrder } = require('./middleware')

const viewApp = require('./apps/view')
const listApp = require('./apps/list')
const reconciliationApp = require('./apps/reconciliation')

router.use(handleRoutePermissions(APP_PERMISSIONS))

router.param('orderId', setOrder)
router.use(listApp.mountpath, listApp.router)
router.use(
reconciliationApp.mountpath,
removeBreadcrumb,
setHomeBreadcrumb(reconciliationApp.displayName),
reconciliationApp.router
)
router.use(viewApp.mountpath, viewApp.router)
module.exports = router
23 changes: 0 additions & 23 deletions src/apps/omis/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,6 @@ function transformOrderToListItem({
return item
}

function transformOrderToTableItem({
id,
reference,
payment_due_date,
company,
subtotal_cost,
total_cost,
} = {}) {
if (!id || !reference) {
return
}

return {
id,
reference,
payment_due_date,
company: get(company, 'name'),
subtotal_cost: parseInt(subtotal_cost) / 100,
total_cost: parseInt(total_cost) / 100,
}
}

module.exports = {
transformOrderToListItem,
transformOrderToTableItem,
}
1 change: 1 addition & 0 deletions src/apps/routers.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const reactRoutes = [
'/companies/:companyId/exports/history',
'/companies/:companyId/exports/history/:countryId',
'/omis/:orderId/quote',
'/omis/reconciliation',
]

reactRoutes.forEach((path) => {
Expand Down
4 changes: 0 additions & 4 deletions src/client/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import ContactLocalHeader from './components/ContactLocalHeader'
import ContactDetails from './modules/Contacts/ContactDetails/ContactDetails'
import ContactAuditHistory from './modules/Contacts/ContactAuditHistory/ContactAuditHistory'
import InteractionDetails from './modules/Interactions/InteractionDetails'
import OrdersReconciliationCollection from './modules/Omis/CollectionList/OrdersReconciliationCollection'
import PropositionDetails from './modules/Investments/Projects/Propositions/PropositionDetails'
import CompanyHierarchy from './modules/Companies/CompanyHierarchy'

Expand Down Expand Up @@ -228,9 +227,6 @@ function App() {
<Mount selector="#interaction-details">
{(props) => <InteractionDetails {...props} />}
</Mount>
<Mount selector="#orders-reconciliation-collection">
{(props) => <OrdersReconciliationCollection {...props} />}
</Mount>
<Mount selector="#proposition-details">
{(props) => <PropositionDetails {...props} />}
</Mount>
Expand Down
Loading
Loading