nestjs-stripe
Advanced tools
Comparing version
@@ -7,3 +7,4 @@ import { ModuleMetadata, Type } from '@nestjs/common/interfaces'; | ||
useClass?: Type<StripeOptionsFactory>; | ||
useExisting?: Type<StripeOptionsFactory>; | ||
useFactory?: (...args: any[]) => Promise<StripeOptions> | StripeOptions; | ||
} |
@@ -37,3 +37,3 @@ "use strict"; | ||
static createAsyncProviders(options) { | ||
if (options.useFactory) { | ||
if (options.useExisting || options.useFactory) { | ||
return [this.createAsyncOptionsProvider(options)]; | ||
@@ -58,3 +58,3 @@ } | ||
return { | ||
inject: [options.useClass], | ||
inject: [options.useExisting || options.useClass], | ||
provide: constants_1.stripeModuleOptions, | ||
@@ -61,0 +61,0 @@ useFactory: (optionsFactory) => optionsFactory.createStripeOptions(), |
{ | ||
"name": "nestjs-stripe", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "Provides an injectable Stripe client to nestjs modules", | ||
@@ -25,8 +25,8 @@ "repository": "https://github.com/dhaspden/nestjs-stripe", | ||
"devDependencies": { | ||
"@nestjs/common": "6.5.2", | ||
"@nestjs/core": "6.5.2", | ||
"@nestjs/testing": "6.5.2", | ||
"@types/jest": "24.0.15", | ||
"@types/node": "12.6.2", | ||
"@types/stripe": "6.31.3", | ||
"@nestjs/common": "6.5.3", | ||
"@nestjs/core": "6.6.7", | ||
"@nestjs/testing": "6.6.7", | ||
"@types/jest": "24.0.18", | ||
"@types/node": "12.7.4", | ||
"@types/stripe": "6.31.27", | ||
"codecov": "3.5.0", | ||
@@ -36,5 +36,5 @@ "jest": "24.8.0", | ||
"reflect-metadata": "0.1.13", | ||
"rimraf": "2.6.3", | ||
"rimraf": "2.7.0", | ||
"rxjs": "6.5.2", | ||
"stripe": "7.5.0", | ||
"stripe": "7.8.0", | ||
"ts-jest": "24.0.2", | ||
@@ -45,6 +45,6 @@ "typescript": "3.5.3" | ||
"@nestjs/common": "^6.0.0", | ||
"@nestjs/core": "^6.0.0", | ||
"@nestjs/core": "^6.6.7", | ||
"reflect-metadata": "^0.1.12", | ||
"rxjs": "^6.0.0", | ||
"stripe": "^7.0.0" | ||
"stripe": "^7.8.0" | ||
}, | ||
@@ -51,0 +51,0 @@ "keywords": [ |
@@ -15,2 +15,5 @@ <p align="center"> | ||
</a> | ||
<a href="https://greenkeeper.io/"> | ||
<img src="https://badges.greenkeeper.io/dhaspden/nestjs-stripe.svg"> | ||
</a> | ||
</p> | ||
@@ -65,2 +68,3 @@ </p> | ||
import { InjectStripe } from 'nestjs-stripe'; | ||
import * as Stripe from 'stripe'; | ||
@@ -67,0 +71,0 @@ @Injectable() |
@@ -9,3 +9,4 @@ import { ModuleMetadata, Type } from '@nestjs/common/interfaces'; | ||
useClass?: Type<StripeOptionsFactory>; | ||
useExisting?: Type<StripeOptionsFactory>; | ||
useFactory?: (...args: any[]) => Promise<StripeOptions> | StripeOptions; | ||
} |
@@ -42,3 +42,3 @@ import { DynamicModule, Global, Module, Provider } from '@nestjs/common'; | ||
private static createAsyncProviders(options: StripeAsyncOptions): Provider[] { | ||
if (options.useFactory) { | ||
if (options.useExisting || options.useFactory) { | ||
return [this.createAsyncOptionsProvider(options)]; | ||
@@ -68,3 +68,3 @@ } | ||
return { | ||
inject: [options.useClass], | ||
inject: [options.useExisting || options.useClass], | ||
provide: stripeModuleOptions, | ||
@@ -71,0 +71,0 @@ useFactory: (optionsFactory: StripeOptionsFactory) => |
@@ -0,1 +1,2 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
@@ -19,2 +20,8 @@ import * as Stripe from 'stripe'; | ||
@Module({ | ||
exports: [TestService], | ||
providers: [TestService], | ||
}) | ||
class TestModule {} | ||
describe('forRoot', () => { | ||
@@ -49,2 +56,19 @@ it('should provide the stripe client', async () => { | ||
describe('when the `useExisting` option is used', () => { | ||
it('should provide the stripe client', async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [ | ||
StripeModule.forRootAsync({ | ||
imports: [TestModule], | ||
useExisting: TestService, | ||
}), | ||
], | ||
}).compile(); | ||
const stripeClient = module.get<Stripe>(stripeToken); | ||
expect(stripeClient).toBeDefined(); | ||
expect(stripeClient).toBeInstanceOf(Stripe); | ||
}); | ||
}); | ||
describe('when the `useClass` option is used', () => { | ||
@@ -51,0 +75,0 @@ it('should provide the stripe client', async () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
77
4.05%639
4.93%127
3.25%441868
-1.84%