Skip to content

Commit

Permalink
fix: remove repetitive auditing
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinkrustev committed May 24, 2024
1 parent 73d3299 commit c36893a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/model/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ class QuotesModel {
// if we got here rules passed, so we can forward the quote on to the recipient dfsp
const childSpan = handleQuoteUpdateSpan.getChild('qs_quote_forwardQuoteUpdate')
try {
await childSpan.audit({ headers, params: { quoteId }, payload: quoteUpdateRequest }, EventSdk.AuditEventAction.start)
histTimer({ success: true, queryName: 'quote_handleQuoteUpdate' })
await this.forwardQuoteUpdate(headers, quoteId, quoteUpdateRequest, childSpan)
} catch (err) {
Expand Down Expand Up @@ -776,6 +775,7 @@ class QuotesModel {
// if we got here rules passed, so we can forward the quote on to the recipient dfsp
const childSpan = span.getChild('qs_quote_forwardQuoteUpdateResend')
try {
await childSpan.audit({ headers, params: { quoteId }, payload: quoteUpdate }, EventSdk.AuditEventAction.start)
histTimer({ success: true, queryName: 'quote_handleQuoteUpdateResend' })
await this.forwardQuoteUpdate(headers, quoteId, quoteUpdate, childSpan)
} catch (err) {
Expand Down
29 changes: 14 additions & 15 deletions test/unit/model/quotes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1415,9 +1415,8 @@ describe('QuotesModel', () => {
const refs = await quotesModel.handleQuoteUpdate(mockData.headers, mockData.quoteId, mockData.quoteUpdate, mockSpan)

expect(mockSpan.getChild.mock.calls.length).toBe(1)
let args = [{ headers: mockData.headers, params: { quoteId: mockData.quoteRequest.quoteId }, payload: mockData.quoteUpdate }, EventSdk.AuditEventAction.start]
expect(mockChildSpan.audit).toBeCalledWith(...args)
args = [mockData.headers, mockData.quoteId, mockData.quoteUpdate, mockChildSpan]
expect(mockChildSpan.audit).not.toBeCalled()
const args = [mockData.headers, mockData.quoteId, mockData.quoteUpdate, mockChildSpan]
expect(quotesModel.forwardQuoteUpdate).toBeCalledWith(...args)
expect(refs).toEqual({})
})
Expand All @@ -1432,9 +1431,8 @@ describe('QuotesModel', () => {
const refs = await quotesModel.handleQuoteUpdate(mockData.headers, mockData.quoteId, mockData.quoteUpdate, mockSpan)

expect(mockSpan.getChild.mock.calls.length).toBe(1)
let args = [{ headers: mockData.headers, params: { quoteId: mockData.quoteRequest.quoteId }, payload: mockData.quoteUpdate }, EventSdk.AuditEventAction.start]
expect(mockChildSpan.audit).toBeCalledWith(...args)
args = [mockData.headers, mockData.quoteId, mockData.quoteUpdate, mockChildSpan]
expect(mockChildSpan.audit).not.toBeCalled()
let args = [mockData.headers, mockData.quoteId, mockData.quoteUpdate, mockChildSpan]
expect(quotesModel.forwardQuoteUpdate).toBeCalledWith(...args)
args = [mockData.headers['fspiop-source'], mockData.quoteId, fspiopError, mockData.headers, mockChildSpan]
expect(quotesModel.handleException).toBeCalledWith(...args)
Expand Down Expand Up @@ -1509,10 +1507,9 @@ describe('QuotesModel', () => {
mockQuoteResponseId
)

let args = [{ headers: mockData.headers, params: { quoteId: mockData.quoteRequest.quoteId }, payload: localQuoteUpdate }, EventSdk.AuditEventAction.start]
expect(mockChildSpan.audit).toBeCalledWith(...args)
expect(mockChildSpan.audit).not.toBeCalled()

args = [mockData.headers, mockData.quoteId, localQuoteUpdate, mockChildSpan]
const args = [mockData.headers, mockData.quoteId, localQuoteUpdate, mockChildSpan]
expect(quotesModel.forwardQuoteUpdate).toBeCalledWith(...args)
expect(mockChildSpan.finish).not.toBeCalled()
expect(refs).toMatchObject(expected)
Expand Down Expand Up @@ -1540,9 +1537,8 @@ describe('QuotesModel', () => {
expect(mockTransaction.rollback.mock.calls.length).toBe(0)
expect(mockTransaction.commit.mock.calls.length).toBe(1)
expect(mockSpan.getChild.mock.calls.length).toBe(1)
let args = [{ headers: mockData.headers, params: { quoteId: mockData.quoteRequest.quoteId }, payload: mockData.quoteUpdate }, EventSdk.AuditEventAction.start]
expect(mockChildSpan.audit).toBeCalledWith(...args)
args = [mockData.headers, mockData.quoteId, mockData.quoteUpdate, mockChildSpan]
expect(mockChildSpan.audit).not.toBeCalled()
const args = [mockData.headers, mockData.quoteId, mockData.quoteUpdate, mockChildSpan]
expect(quotesModel.forwardQuoteUpdate).toBeCalledWith(...args)
expect(mockChildSpan.finish).not.toBeCalled()
expect(refs).toEqual(expected)
Expand Down Expand Up @@ -1716,7 +1712,7 @@ describe('QuotesModel', () => {
})

it('forward quote update', async () => {
expect.assertions(4)
expect.assertions(5)

mockChildSpan.isFinished = false

Expand All @@ -1725,12 +1721,13 @@ describe('QuotesModel', () => {
.toBe(undefined)

expect(mockSpan.getChild).toBeCalled()
expect(mockChildSpan.audit).toBeCalled()
const args = [mockData.headers, mockData.quoteId, mockData.quoteUpdate, mockChildSpan]
expect(quotesModel.forwardQuoteUpdate).toBeCalledWith(...args)
expect(mockChildSpan.finish).toBeCalled()
})
it('handle fspiopError when forward quote fails', async () => {
expect.assertions(3)
expect.assertions(4)

mockChildSpan.isFinished = true
const fspiopError = ErrorHandler.CreateFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_FSP_ERROR)
Expand All @@ -1740,12 +1737,13 @@ describe('QuotesModel', () => {
.resolves
.toBe(undefined)

expect(mockChildSpan.audit).toBeCalled()
const args = [mockData.headers['fspiop-source'], mockData.quoteId, fspiopError, mockData.headers, mockChildSpan]
expect(quotesModel.handleException).toBeCalledWith(...args)
expect(mockChildSpan.finish).not.toBeCalled()
})
it('handle custom error without stack when forward quote fails', async () => {
expect.assertions(3)
expect.assertions(4)

mockChildSpan.isFinished = true
const customErrorNoStack = new Error('Custom error')
Expand All @@ -1756,6 +1754,7 @@ describe('QuotesModel', () => {
.resolves
.toBe(undefined)

expect(mockChildSpan.audit).toBeCalled()
const args = [mockData.headers['fspiop-source'], mockData.quoteId, customErrorNoStack, mockData.headers, mockChildSpan]
expect(quotesModel.handleException).toBeCalledWith(...args)
expect(mockChildSpan.finish).not.toBeCalled()
Expand Down

0 comments on commit c36893a

Please sign in to comment.