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

Dissociated unit tests from the actual contents of rules.json #92

Merged
merged 1 commit into from
Nov 29, 2019
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
69 changes: 69 additions & 0 deletions config/rules.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[
{
"conditions": {
"all": [
{
"fact": "json-path",
"params": {
"fact": "payload",
"path": "$.payload.extensionList[?(@.key == 'KYCPayerTier')].value"
},
"operator": "deepEqual",
"value": [ "1" ]
},
{
"fact": "payload",
"path": ".amount.currency",
"operator": "notIn",
"value": {
"fact": "json-path",
"params": {
"fact": "payee",
"path": "$.payee.accounts[?(@.ledgerAccountType == 'SETTLEMENT')].currency"
}
}
}
]
},
"event": {
"type": "INTERCEPT_QUOTE",
"params": {
"rerouteToFsp": "DFSPEUR"
}
}
},
{
"conditions": {
"all": [
{
"fact": "json-path",
"params": {
"fact": "payload",
"path": "$.payload.extensionList[?(@.key == 'KYCPayerTier')].value"
},
"operator": "notDeepEqual",
"value": [ "1" ]
},
{
"fact": "payload",
"path": ".amount.currency",
"operator": "notIn",
"value": {
"fact": "json-path",
"params": {
"fact": "payee",
"path": "$.payee.accounts[?(@.ledgerAccountType == 'SETTLEMENT')].currency"
}
}
}
]
},
"event": {
"type": "INVALID_QUOTE_REQUEST",
"params": {
"FSPIOPError": "PAYEE_UNSUPPORTED_CURRENCY",
"message": "The requested payee does not support the payment currency"
}
}
}
]
70 changes: 1 addition & 69 deletions config/rules.json
Original file line number Diff line number Diff line change
@@ -1,69 +1 @@
[
{
"conditions": {
"all": [
{
"fact": "json-path",
"params": {
"fact": "payload",
"path": "$.payload.extensionList[?(@.key == 'KYCPayerTier')].value"
},
"operator": "deepEqual",
"value": [ "1" ]
},
{
"fact": "payload",
"path": ".amount.currency",
"operator": "notIn",
"value": {
"fact": "json-path",
"params": {
"fact": "payee",
"path": "$.payee.accounts[?(@.ledgerAccountType == 'SETTLEMENT')].currency"
}
}
}
]
},
"event": {
"type": "INTERCEPT_QUOTE",
"params": {
"rerouteToFsp": "DFSPEUR"
}
}
},
{
"conditions": {
"all": [
{
"fact": "json-path",
"params": {
"fact": "payload",
"path": "$.payload.extensionList[?(@.key == 'KYCPayerTier')].value"
},
"operator": "notDeepEqual",
"value": [ "1" ]
},
{
"fact": "payload",
"path": ".amount.currency",
"operator": "notIn",
"value": {
"fact": "json-path",
"params": {
"fact": "payee",
"path": "$.payee.accounts[?(@.ledgerAccountType == 'SETTLEMENT')].currency"
}
}
}
]
},
"event": {
"type": "INVALID_QUOTE_REQUEST",
"params": {
"FSPIOPError": "PAYEE_UNSUPPORTED_CURRENCY",
"message": "The requested payee does not support the payment currency"
}
}
}
]
[]
33 changes: 19 additions & 14 deletions test/unit/model/quotes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
******/
'use strict'

// jest has a buggy system for mocking dependencies that can be overcome by mocking
// the target module before requiring it.
// more info on https://github.com/facebook/jest/issues/2582#issuecomment-321607875
const mockRules = [{}]
let mockConfig

jest.mock('../../../config/rules.json', () => mockRules)
jest.mock('axios')
jest.mock('@mojaloop/central-services-logger')
jest.mock('../../../src/data/database')
jest.mock('../../../src/model/rules')
jest.mock('../../../src/lib/config', () => {
return jest.fn().mockImplementation(() => mockConfig)
})

const axios = require('axios')

const clone = require('@mojaloop/central-services-shared').Util.clone
Expand All @@ -44,25 +59,15 @@ const QuotesModel = require('../../../src/model/quotes')
const rules = require('../../../config/rules')
const RulesEngine = require('../../../src/model/rules')

let mockConfig = new Config()

jest.mock('axios')
jest.mock('@mojaloop/central-services-logger')
jest.mock('../../../src/data/database')
jest.mock('../../../src/model/rules')
jest.mock('../../../src/lib/config', () => {
return jest.fn().mockImplementation(() => mockConfig)
})

describe('QuotesModel', () => {
const defaultRules = JSON.parse(JSON.stringify(rules))

let mockData
let mockTransaction
let mockChildSpan
let mockSpan
let quotesModel

mockConfig = new Config()

beforeEach(() => {
axios.request.mockImplementation((opts) => {
if (opts.url.search('http://invalid.com') === 0) {
Expand Down Expand Up @@ -288,8 +293,8 @@ describe('QuotesModel', () => {

// reset the rules values to their initials, but without changing the object's reference
// as we use the same object between the current unit tests file and the code's implementation
Object.keys(defaultRules).forEach(key => {
rules[key] = defaultRules[key]
Object.keys(mockData.rules).forEach(key => {
rules[key] = mockData.rules[key]
})
})

Expand Down
Loading