-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add module asynchronous config using factory/existing/class (#65)
* feature(azure-storage) add azure storage options async and factory methods * test(azure-storage) adding unit tests for azure storage withConfigAsync * doc(azure-storage) update readme doc with new methods to configure Co-authored-by: Sivamuthu Kumar <[email protected]>
- Loading branch information
1 parent
b781d79
commit 58a8710
Showing
4 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { AZURE_STORAGE_MODULE_OPTIONS } from './azure-storage.constant'; | ||
import { AzureStorageModule } from './azure-nest-storage.module'; | ||
import { | ||
AzureStorageOptions, | ||
AzureStorageOptionsFactory, | ||
} from './azure-storage.service'; | ||
import { ValueProvider, FactoryProvider } from '@nestjs/common/interfaces'; | ||
|
||
describe('AzureStorageModule', () => { | ||
let options: AzureStorageOptions; | ||
|
||
beforeEach(() => { | ||
options = { | ||
accountName: 'test_account', | ||
containerName: 'test_container', | ||
sasKey: 'FAKE_SAS_KEY', | ||
}; | ||
}); | ||
|
||
it('should have storage options provider when options passed', async () => { | ||
const module = AzureStorageModule.withConfig(options); | ||
expect(module.providers.length).toBe(1); | ||
expect((module.providers[0] as ValueProvider<any>).provide).toBe( | ||
AZURE_STORAGE_MODULE_OPTIONS, | ||
); | ||
expect(await (module.providers[0] as ValueProvider<any>).useValue).toBe( | ||
options, | ||
); | ||
}); | ||
|
||
it('should have storage options provider when async options passed using factory', async () => { | ||
const factory = async () => options; | ||
const module = AzureStorageModule.withConfigAsync({ | ||
useFactory: factory, | ||
}); | ||
expect(module.providers.length).toBe(1); | ||
expect((module.providers[0] as FactoryProvider<any>).provide).toBe( | ||
AZURE_STORAGE_MODULE_OPTIONS, | ||
); | ||
expect( | ||
await (module.providers[0] as FactoryProvider<any>).useFactory(), | ||
).toBe(options); | ||
}); | ||
|
||
it('should have storage options provider when async options passed using existing factory', async () => { | ||
class TestAzStorageOptionsFactory implements AzureStorageOptionsFactory { | ||
createAzureStorageOptions(): | ||
| AzureStorageOptions | ||
| Promise<AzureStorageOptions> { | ||
return options; | ||
} | ||
} | ||
|
||
const module = AzureStorageModule.withConfigAsync({ | ||
useExisting: TestAzStorageOptionsFactory, | ||
}); | ||
expect(module.providers.length).toBe(1); | ||
expect((module.providers[0] as FactoryProvider<any>).provide).toBe( | ||
AZURE_STORAGE_MODULE_OPTIONS, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters