diff --git a/nx.json b/nx.json index 1f19cc94..cb9b163d 100644 --- a/nx.json +++ b/nx.json @@ -99,5 +99,6 @@ "projectChangelogs": true }, "projectsRelationship": "independent" - } + }, + "nxCloudId": "69008e1b106f8b44b91adf92" } diff --git a/packages/storages-base-nestjs-module/README.md b/packages/storages-base-nestjs-module/README.md new file mode 100644 index 00000000..da24eaa8 --- /dev/null +++ b/packages/storages-base-nestjs-module/README.md @@ -0,0 +1,98 @@ +
+ +[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 +[circleci-url]: https://circleci.com/gh/nestjs/nest + +A progressive Node.js framework for building efficient and scalable server-side applications.
+ + + +## Description + +[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. + +## Project setup + +```bash +$ yarn install +``` + +## Compile and run the project + +```bash +# development +$ yarn run start + +# watch mode +$ yarn run start:dev + +# production mode +$ yarn run start:prod +``` + +## Run tests + +```bash +# unit tests +$ yarn run test + +# e2e tests +$ yarn run test:e2e + +# test coverage +$ yarn run test:cov +``` + +## Deployment + +When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information. + +If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps: + +```bash +$ yarn install -g @nestjs/mau +$ mau deploy +``` + +With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure. + +## Resources + +Check out a few resources that may come in handy when working with NestJS: + +- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework. +- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy). +- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/). +- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks. +- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com). +- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com). +- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs). +- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com). + +## Support + +Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). + +## Stay in touch + +- Author - [Kamil MyĆliwiec](https://twitter.com/kammysliwiec) +- Website - [https://nestjs.com](https://nestjs.com/) +- Twitter - [@nestframework](https://twitter.com/nestframework) + +## License + +Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE). diff --git a/packages/storages-base-nestjs-module/__tests__/storages-base-module.spec.ts b/packages/storages-base-nestjs-module/__tests__/storages-base-module.spec.ts new file mode 100644 index 00000000..ffaa82bb --- /dev/null +++ b/packages/storages-base-nestjs-module/__tests__/storages-base-module.spec.ts @@ -0,0 +1,224 @@ +import { Injectable, Module, Type } from '@nestjs/common'; +import { Test, TestingModule } from '@nestjs/testing'; +import { StorageBaseModule } from '../src/storages-base.module'; +import { + IStorageAdapter, + StorageBaseModuleOptions, + StorageBaseModuleOptionsFactory, +} from '../src/typings/storage-base-module-options.interface'; +import { STORAGE_ADAPTER, STORAGE_MODULE_OPTIONS } from '../src/typings/storages-base-module-providers'; +import { StorageService } from '@rytass/storages-base-nestjs-module'; +import { StorageGCSService } from '@rytass/storages-adapter-gcs'; + +const mockInstance = { + url: jest.fn(), + write: jest.fn(), + batchWrite: jest.fn(), + remove: jest.fn(), + isExists: jest.fn(), +}; + +jest.mock('@rytass/storages-adapter-gcs', () => ({ + StorageGCSService: jest.fn(() => mockInstance), + GCSOptions: jest.fn(), +})); + +describe('Storages Base Nestjs Module', () => { + @Injectable() + class mockAdapter implements IStorageAdapter { + url = jest.fn(async (key: string, _expires?: number) => `http://mock-url.com/${key}`); + + write = jest.fn(); + batchWrite = jest.fn(); + remove = jest.fn(); + isExists = jest.fn(); + + constructor(_config: unknown) {} + } + + beforeEach(() => { + jest.clearAllMocks(); + }); + + const mockOptions = { + adapter: mockAdapter, + config: { test: true }, + commonOptions: { + formDataFieldName: 'files', + allowMultiple: true, + MaxFileSizeInBytes: 10 * 1024 * 1024, + defaultPublic: false, + }, + }; + + const mockCommonOptions = { + formDataFieldName: 'files', + allowMultiple: true, + MaxFileSizeInBytes: 10 * 1024 * 1024, + defaultPublic: false, + }; + + describe('forRoot', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('should throw Error if adapter is not provided', async () => { + await expect( + Test.createTestingModule({ + imports: [StorageBaseModule.forRoot({ adapter: undefined as unknown as Type