adonisjs-paystack
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -0,1 +1,6 @@ | ||
<a name="0.1.8"></a> | ||
# 0.1.8 (2021-02-27) | ||
- Updated dependency **paystack-node** to v0.2.6 | ||
<a name="0.1.7"></a> | ||
@@ -2,0 +7,0 @@ # 0.1.7 (2020-12-01) |
{ | ||
"name": "adonisjs-paystack", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "An addon/plugin package to provide PayStack payment services in AdonisJS 4.1+", | ||
@@ -46,3 +46,3 @@ "main": "index.js", | ||
"@adonisjs/generic-exceptions": "^2.0.1", | ||
"paystack-node": "^0.2.5", | ||
"paystack-node": "^0.2.6", | ||
"debug": "^3.1.2" | ||
@@ -49,0 +49,0 @@ }, |
@@ -20,3 +20,3 @@ 'use strict' | ||
return paystack.agent | ||
return paystack | ||
}) | ||
@@ -23,0 +23,0 @@ |
@@ -99,2 +99,16 @@ # adonis-paystack | ||
## Creating fakes (for Unit Testing) | ||
>It's possible to fake the `PayStack` instance like so: | ||
```js | ||
const PayStack = use('PayStack') | ||
//start faking the provider instance | ||
PayStack.fake() | ||
//stop faking the provider instance | ||
PayStack.restore() | ||
``` | ||
## License | ||
@@ -101,0 +115,0 @@ |
'use strict' | ||
// const Event = use('Event') | ||
// add testing mock accessibility { paystack-node = v0.2.6+ } | ||
const MockDecorator = function decorator (context) { | ||
this.context = context | ||
this.set = function decorationSetter (target, prop, value) { | ||
if (!target[prop]) { | ||
this.context['_mock']['__' + prop] = value | ||
} | ||
} | ||
this.get = function decorationGetter (target, prop) { | ||
/** | ||
* if node is inspecting then stick to target properties | ||
*/ | ||
if (typeof (prop) === 'symbol' || prop === 'inspect') { | ||
return target[prop] | ||
} | ||
if (prop === 'fake' && typeof target[prop] !== 'function') { | ||
return this.context.constructor.engageMock.bind( | ||
this.context.constructor | ||
) | ||
} | ||
if (prop === 'withError' && typeof target[prop] !== 'function') { | ||
return this.context.constructor.respondWithError.bind( | ||
this.context.constructor | ||
) | ||
} | ||
if (prop === 'withOutError' && typeof target[prop] !== 'function') { | ||
return this.context.constructor.respondWithoutError.bind( | ||
this.context.constructor | ||
) | ||
} | ||
if (prop === 'macro' && typeof target[prop] !== 'function') { | ||
return this.context.constructor.mockMacro.bind( | ||
this.context.constructor | ||
) | ||
} | ||
if (prop === 'restore' && typeof target[prop] !== 'function') { | ||
return this.context.constructor.disengageMock.bind( | ||
this.context.constructor | ||
) | ||
} | ||
return this.context[prop] || target[prop] | ||
} | ||
} | ||
class PayStackAPIClient { | ||
constructor (Agent, Config, Env) { | ||
let environment = Env.get('NODE_ENV') | ||
let apiKey = (environment === 'development') ? Config.get('paystack.apiTestKey') : Config.get('paystack.apiLiveKey') | ||
let apiKey = (environment !== 'production') ? Config.get('paystack.apiTestKey') : Config.get('paystack.apiLiveKey') | ||
this.agent = new Agent( | ||
apiKey, | ||
environment | ||
const decorator = new MockDecorator( | ||
new Agent(apiKey, environment) | ||
) | ||
return new Proxy(this, decorator) | ||
} | ||
@@ -15,0 +64,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11269
133
159
Updatedpaystack-node@^0.2.6