Skip to content

Commit

Permalink
Merge pull request #2 from vbarzokas/bugfix/update-unit-tests
Browse files Browse the repository at this point in the history
Clean & update
  • Loading branch information
partiallyordered authored Nov 11, 2019
2 parents bc17ba5 + c967661 commit 75b879f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/model/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ class QuotesModel {
// supply a rules file containing an empty array.
const events = await this.executeRules(headers, quoteRequest)

const { terminate, quoteRequest: sendRequest, headers: sendHeaders } =
await this.handleRuleEvents(events, headers, quoteRequest)
if (terminate) {
const handledRuleEvents = await this.handleRuleEvents(events, headers, quoteRequest)

if (handledRuleEvents.terminate) {
return
}

Expand Down Expand Up @@ -212,7 +212,8 @@ class QuotesModel {
if (dupe.isResend && dupe.isDuplicateId) {
// this is a resend
// See section 3.2.5.1 in "API Definition v1.0.docx" API specification document.
return this.handleQuoteRequestResend(sendHeaders, sendRequest, span)
return this.handleQuoteRequestResend(handledRuleEvents.headers,
handledRuleEvents.quoteRequest, span)
}

// todo: validation
Expand Down Expand Up @@ -289,10 +290,10 @@ class QuotesModel {
try {
if (envConfig.simpleRoutingMode) {
await childSpan.audit({ headers, payload: quoteRequest }, EventSdk.AuditEventAction.start)
await this.forwardQuoteRequest(sendHeaders, quoteRequest.quoteId, sendRequest, childSpan)
await this.forwardQuoteRequest(handledRuleEvents.headers, quoteRequest.quoteId, handledRuleEvents.quoteRequest, childSpan)
} else {
await childSpan.audit({ headers, payload: refs }, EventSdk.AuditEventAction.start)
await this.forwardQuoteRequest(sendHeaders, refs.quoteId, sendRequest, childSpan)
await this.forwardQuoteRequest(handledRuleEvents.headers, refs.quoteId, handledRuleEvents.quoteRequest, childSpan)
}
} catch (err) {
// any-error
Expand Down
17 changes: 10 additions & 7 deletions test/unit/model/quotes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ describe('quotesModel', () => {
db: new Db(),
requestId: 'test1234'
})
quotesModel.handleRuleEvents = (events, headers, quoteRequest) => ({
quoteRequest,
headers,
terminate: false
})
Db.mockClear()
mockTransaction.commit.mockClear()
mockTransaction.rollback.mockClear()
Expand Down Expand Up @@ -429,7 +424,11 @@ describe('quotesModel', () => {
expect(mockSpan.getChild.mock.calls.length).toBe(1)
args = [{ headers, payload: refs }, EventSdk.AuditEventAction.start]
expect(mockChildSpan.audit).toBeCalledWith(...args)
args = [headers, refs.quoteId, quoteRequest, mockChildSpan]
const forwardedHeaders = {
'fspiop-source': 'dfsp1',
'fspiop-destination': rules[0].event.params.rerouteToFsp
}
args = [forwardedHeaders, refs.quoteId, quoteRequest, mockChildSpan]
expect(quotesModel.forwardQuoteRequest).toBeCalledWith(...args)
expect(mockChildSpan.finish).not.toBeCalled()
expect(refs).toMatchObject(expected)
Expand Down Expand Up @@ -461,7 +460,11 @@ describe('quotesModel', () => {
expect(mockSpan.getChild.mock.calls.length).toBe(1)
args = [{ headers, payload: refs }, EventSdk.AuditEventAction.start]
expect(mockChildSpan.audit).toBeCalledWith(...args)
args = [headers, refs.quoteId, localQuoteRequest, mockChildSpan]
const forwardedHeaders = {
'fspiop-source': 'dfsp1',
'fspiop-destination': rules[0].event.params.rerouteToFsp
}
args = [forwardedHeaders, refs.quoteId, localQuoteRequest, mockChildSpan]
expect(quotesModel.forwardQuoteRequest).toBeCalledWith(...args)
expect(mockChildSpan.finish).not.toBeCalled()
expect(refs).toEqual({})
Expand Down

0 comments on commit 75b879f

Please sign in to comment.