@mikemajesty/microservice-crud 6.0.14 → 6.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +1 -1
  3. package/src/templates/infra/adapter.js +4 -7
  4. package/src/templates/infra/module.js +7 -10
  5. package/src/templates/infra/service.js +6 -9
  6. package/src/templates/libs/adapter.js +4 -7
  7. package/src/templates/libs/module.js +7 -10
  8. package/src/templates/libs/service.js +8 -11
  9. package/src/templates/module/controller.js +2 -5
  10. package/src/templates/module/module.js +4 -6
  11. package/src/templates/mongo/core/entity/entity.js +5 -8
  12. package/src/templates/mongo/core/repository/repository.js +5 -8
  13. package/src/templates/mongo/core/use-cases/__tests__/create.spec.js +19 -22
  14. package/src/templates/mongo/core/use-cases/__tests__/delete.spec.js +19 -22
  15. package/src/templates/mongo/core/use-cases/__tests__/get-by-id.spec.js +19 -22
  16. package/src/templates/mongo/core/use-cases/__tests__/list.spec.js +20 -23
  17. package/src/templates/mongo/core/use-cases/__tests__/update.spec.js +19 -22
  18. package/src/templates/mongo/core/use-cases/create.js +11 -14
  19. package/src/templates/mongo/core/use-cases/delete.js +11 -14
  20. package/src/templates/mongo/core/use-cases/get-by-id.js +11 -14
  21. package/src/templates/mongo/core/use-cases/list.js +11 -14
  22. package/src/templates/mongo/core/use-cases/update.js +14 -17
  23. package/src/templates/mongo/modules/adapter.js +16 -19
  24. package/src/templates/mongo/modules/controller.js +27 -30
  25. package/src/templates/mongo/modules/module.js +52 -54
  26. package/src/templates/mongo/modules/repository.js +7 -10
  27. package/src/templates/mongo/modules/swagger.js +16 -19
  28. package/src/templates/mongo/schemas/schema.js +9 -12
  29. package/src/templates/postgres/core/entity/entity.js +5 -8
  30. package/src/templates/postgres/core/repository/repository.js +5 -8
  31. package/src/templates/postgres/core/use-cases/__tests__/create.spec.js +19 -22
  32. package/src/templates/postgres/core/use-cases/__tests__/delete.spec.js +19 -22
  33. package/src/templates/postgres/core/use-cases/__tests__/get-by-id.spec.js +19 -22
  34. package/src/templates/postgres/core/use-cases/__tests__/list.spec.js +20 -23
  35. package/src/templates/postgres/core/use-cases/__tests__/update.spec.js +19 -22
  36. package/src/templates/postgres/core/use-cases/create.js +11 -14
  37. package/src/templates/postgres/core/use-cases/delete.js +11 -14
  38. package/src/templates/postgres/core/use-cases/get-by-id.js +12 -15
  39. package/src/templates/postgres/core/use-cases/list.js +10 -13
  40. package/src/templates/postgres/core/use-cases/update.js +14 -17
  41. package/src/templates/postgres/modules/adapter.js +16 -19
  42. package/src/templates/postgres/modules/controller.js +27 -30
  43. package/src/templates/postgres/modules/module.js +40 -43
  44. package/src/templates/postgres/modules/repository.js +10 -13
  45. package/src/templates/postgres/modules/swagger.js +16 -20
  46. package/src/templates/postgres/schemas/schema.js +2 -5
  47. package/src/textUtils.js +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikemajesty/microservice-crud",
3
- "version": "6.0.14",
3
+ "version": "6.0.16",
4
4
  "description": "Monorepo CLI",
5
5
  "main": "src/cli.js",
6
6
  "scripts": {
package/src/cli.js CHANGED
@@ -327,7 +327,7 @@ export async function cli(args) {
327
327
  return
328
328
  }
329
329
 
330
- userInput.name = name
330
+ userInput.name = name.replace("_", "-").replace(" ", "-")
331
331
 
332
332
  const options = await parseArgumentsInoOptions(userInput)
333
333
 
@@ -1,12 +1,9 @@
1
+ const { dashToPascal } = require("../../textUtils")
1
2
 
2
- function capitalizeFirstLetter(string) {
3
- return string.charAt(0).toUpperCase() + string.slice(1);
4
- }
5
-
6
- const getAdapterInfra = (name) => `import { ${capitalizeFirstLetter(name)}GetInput, ${capitalizeFirstLetter(name)}GetOutput } from './service';
3
+ const getAdapterInfra = (name) => `import { ${dashToPascal(name)}GetInput, ${dashToPascal(name)}GetOutput } from './service';
7
4
 
8
- export abstract class I${capitalizeFirstLetter(name)}Adapter {
9
- abstract get(input: ${capitalizeFirstLetter(name)}GetInput): ${capitalizeFirstLetter(name)}GetOutput;
5
+ export abstract class I${dashToPascal(name)}Adapter {
6
+ abstract get(input: ${dashToPascal(name)}GetInput): ${dashToPascal(name)}GetOutput;
10
7
  }
11
8
  `
12
9
 
@@ -1,24 +1,21 @@
1
-
2
- function capitalizeFirstLetter(string) {
3
- return string.charAt(0).toUpperCase() + string.slice(1);
4
- }
1
+ const { dashToPascal } = require("../../textUtils")
5
2
 
6
3
  const getModuleInfa = (name) => `import { Module } from '@nestjs/common';
7
4
 
8
- import { I${capitalizeFirstLetter(name)}Adapter } from './adapter';
9
- import { ${capitalizeFirstLetter(name)}Service } from './service';
5
+ import { I${dashToPascal(name)}Adapter } from './adapter';
6
+ import { ${dashToPascal(name)}Service } from './service';
10
7
 
11
8
  @Module({
12
9
  imports: [],
13
10
  providers: [
14
11
  {
15
- provide: I${capitalizeFirstLetter(name)}Adapter,
16
- useClass: ${capitalizeFirstLetter(name)}Service
12
+ provide: I${dashToPascal(name)}Adapter,
13
+ useClass: ${dashToPascal(name)}Service
17
14
  }
18
15
  ],
19
- exports: [I${capitalizeFirstLetter(name)}Adapter]
16
+ exports: [I${dashToPascal(name)}Adapter]
20
17
  })
21
- export class ${capitalizeFirstLetter(name)}Module {}
18
+ export class ${dashToPascal(name)}Module {}
22
19
  `
23
20
 
24
21
  module.exports = {
@@ -1,18 +1,15 @@
1
-
2
- function capitalizeFirstLetter(string) {
3
- return string.charAt(0).toUpperCase() + string.slice(1);
4
- }
1
+ const { dashToPascal } = require("../../textUtils")
5
2
 
6
3
  const getServiceInfra = (name) => `import { Injectable } from '@nestjs/common';
7
4
 
8
- import { I${capitalizeFirstLetter(name)}Adapter } from './adapter';
5
+ import { I${dashToPascal(name)}Adapter } from './adapter';
9
6
 
10
- export type ${capitalizeFirstLetter(name)}GetInput = {};
11
- export type ${capitalizeFirstLetter(name)}GetOutput = {};
7
+ export type ${dashToPascal(name)}GetInput = {};
8
+ export type ${dashToPascal(name)}GetOutput = {};
12
9
 
13
10
  @Injectable()
14
- export class ${capitalizeFirstLetter(name)}Service implements I${capitalizeFirstLetter(name)}Adapter {
15
- get(input: ${capitalizeFirstLetter(name)}GetInput): ${capitalizeFirstLetter(name)}GetOutput {
11
+ export class ${dashToPascal(name)}Service implements I${dashToPascal(name)}Adapter {
12
+ get(input: ${dashToPascal(name)}GetInput): ${dashToPascal(name)}GetOutput {
16
13
  return input;
17
14
  }
18
15
  }
@@ -1,12 +1,9 @@
1
+ const { dashToPascal } = require("../../textUtils")
1
2
 
2
- function capitalizeFirstLetter(string) {
3
- return string.charAt(0).toUpperCase() + string.slice(1);
4
- }
5
-
6
- const getAdapterLib = (name) => `import { ${capitalizeFirstLetter(name)}Input, ${capitalizeFirstLetter(name)}Output } from './service';
3
+ const getAdapterLib = (name) => `import { ${dashToPascal(name)}Input, ${dashToPascal(name)}Output } from './service';
7
4
 
8
- export abstract class I${capitalizeFirstLetter(name)}Adapter {
9
- abstract get(input: ${capitalizeFirstLetter(name)}Input): ${capitalizeFirstLetter(name)}Output;
5
+ export abstract class I${dashToPascal(name)}Adapter {
6
+ abstract get(input: ${dashToPascal(name)}Input): ${dashToPascal(name)}Output;
10
7
  }
11
8
  `
12
9
 
@@ -1,24 +1,21 @@
1
-
2
- function capitalizeFirstLetter(string) {
3
- return string.charAt(0).toUpperCase() + string.slice(1);
4
- }
1
+ const { dashToPascal } = require("../../textUtils")
5
2
 
6
3
  const getModuleLib = (name) => `import { Module } from '@nestjs/common';
7
4
 
8
- import { I${capitalizeFirstLetter(name)}Adapter } from './adapter';
9
- import { ${capitalizeFirstLetter(name)}Service } from './service';
5
+ import { I${dashToPascal(name)}Adapter } from './adapter';
6
+ import { ${dashToPascal(name)}Service } from './service';
10
7
 
11
8
  @Module({
12
9
  imports: [],
13
10
  providers: [
14
11
  {
15
- provide: I${capitalizeFirstLetter(name)}Adapter,
16
- useFactory: () => new ${capitalizeFirstLetter(name)}Service()
12
+ provide: I${dashToPascal(name)}Adapter,
13
+ useFactory: () => new ${dashToPascal(name)}Service()
17
14
  }
18
15
  ],
19
- exports: [I${capitalizeFirstLetter(name)}Adapter]
16
+ exports: [I${dashToPascal(name)}Adapter]
20
17
  })
21
- export class ${capitalizeFirstLetter(name)}LibModule {}
18
+ export class ${dashToPascal(name)}LibModule {}
22
19
  `
23
20
 
24
21
  module.exports = {
@@ -1,25 +1,22 @@
1
-
2
- function capitalizeFirstLetter(string) {
3
- return string.charAt(0).toUpperCase() + string.slice(1);
4
- }
1
+ const { dashToPascal } = require("../../textUtils")
5
2
 
6
3
  const getServiceLib = (name) => `import { Injectable } from '@nestjs/common';
7
4
  import { z } from 'zod';
8
5
 
9
6
  import { ValidateSchema } from '@/utils/decorators';
10
7
 
11
- import { I${capitalizeFirstLetter(name)}Adapter } from './adapter';
8
+ import { I${dashToPascal(name)}Adapter } from './adapter';
12
9
 
13
- const ${capitalizeFirstLetter(name)}Schema = z.object({ name: z.string().trim() });
10
+ const ${dashToPascal(name)}Schema = z.object({ name: z.string().trim() });
14
11
 
15
- export type ${capitalizeFirstLetter(name)}Input = z.infer<typeof ${capitalizeFirstLetter(name)}Schema>;
12
+ export type ${dashToPascal(name)}Input = z.infer<typeof ${dashToPascal(name)}Schema>;
16
13
 
17
- export type ${capitalizeFirstLetter(name)}Output = string;
14
+ export type ${dashToPascal(name)}Output = string;
18
15
 
19
16
  @Injectable()
20
- export class ${capitalizeFirstLetter(name)}Service implements I${capitalizeFirstLetter(name)}Adapter {
21
- @ValidateSchema(${capitalizeFirstLetter(name)}Schema)
22
- get({ name }: ${capitalizeFirstLetter(name)}Input): ${capitalizeFirstLetter(name)}Output {
17
+ export class ${dashToPascal(name)}Service implements I${dashToPascal(name)}Adapter {
18
+ @ValidateSchema(${dashToPascal(name)}Schema)
19
+ get({ name }: ${dashToPascal(name)}Input): ${dashToPascal(name)}Output {
23
20
  return name;
24
21
  }
25
22
  }
@@ -1,9 +1,6 @@
1
1
 
2
2
  const pluralize = require('pluralize')
3
-
4
- function capitalizeFirstLetter(string) {
5
- return string.charAt(0).toUpperCase() + string.slice(1);
6
- }
3
+ const { dashToPascal } = require('../../textUtils')
7
4
 
8
5
  const getModuleControllerModule = (name) => `import { Controller, Get, Req } from '@nestjs/common';
9
6
  import { ApiResponse, ApiTags } from '@nestjs/swagger';
@@ -14,7 +11,7 @@ import { SwaggerResponse } from './swagger';
14
11
 
15
12
  @Controller('${pluralize(name)}')
16
13
  @ApiTags('${pluralize(name)}')
17
- export class ${capitalizeFirstLetter(name)}Controller {
14
+ export class ${dashToPascal(name)}Controller {
18
15
  @Get()
19
16
  @ApiResponse(SwaggerResponse.get[200])
20
17
  async get(@Req() {}: ApiRequest): Promise<string> {
@@ -1,16 +1,14 @@
1
- function capitalizeFirstLetter(string) {
2
- return string.charAt(0).toUpperCase() + string.slice(1);
3
- }
1
+ const { dashToPascal } = require("../../textUtils")
4
2
 
5
3
  const getModuleModule = (name) => `import { Module } from '@nestjs/common';
6
4
 
7
- import { ${capitalizeFirstLetter(name)}Controller } from './controller';
5
+ import { ${dashToPascal(name)}Controller } from './controller';
8
6
 
9
7
  @Module({
10
8
  imports: [],
11
- controllers: [${capitalizeFirstLetter(name)}Controller]
9
+ controllers: [${dashToPascal(name)}Controller]
12
10
  })
13
- export class ${capitalizeFirstLetter(name)}Module {}
11
+ export class ${dashToPascal(name)}Module {}
14
12
  `
15
13
 
16
14
  module.exports = {
@@ -1,7 +1,4 @@
1
-
2
- function capitalizeFirstLetter(string) {
3
- return string.charAt(0).toUpperCase() + string.slice(1);
4
- }
1
+ const { dashToPascal } = require("../../../../textUtils")
5
2
 
6
3
  const getCoreEntity = (name) => `import { z } from 'zod';
7
4
 
@@ -13,7 +10,7 @@ const CreatedAt = z.date().nullish();
13
10
  const UpdatedAt = z.date().nullish();
14
11
  const DeletedAt = z.date().nullish();
15
12
 
16
- export const ${capitalizeFirstLetter(name)}EntitySchema = z.object({
13
+ export const ${dashToPascal(name)}EntitySchema = z.object({
17
14
  id: ID,
18
15
  name: Name,
19
16
  createdAt: CreatedAt,
@@ -21,12 +18,12 @@ export const ${capitalizeFirstLetter(name)}EntitySchema = z.object({
21
18
  deletedAt: DeletedAt
22
19
  });
23
20
 
24
- type ${capitalizeFirstLetter(name)} = z.infer<typeof ${capitalizeFirstLetter(name)}EntitySchema>;
21
+ type ${dashToPascal(name)} = z.infer<typeof ${dashToPascal(name)}EntitySchema>;
25
22
 
26
- export class ${capitalizeFirstLetter(name)}Entity extends BaseEntity<${capitalizeFirstLetter(name)}Entity>(${capitalizeFirstLetter(name)}EntitySchema) {
23
+ export class ${dashToPascal(name)}Entity extends BaseEntity<${dashToPascal(name)}Entity>(${dashToPascal(name)}EntitySchema) {
27
24
  name!: string;
28
25
 
29
- constructor(entity: ${capitalizeFirstLetter(name)}) {
26
+ constructor(entity: ${dashToPascal(name)}) {
30
27
  super();
31
28
  Object.assign(this, this.validate(entity));
32
29
  }
@@ -1,15 +1,12 @@
1
-
2
- function capitalizeFirstLetter(string) {
3
- return string.charAt(0).toUpperCase() + string.slice(1);
4
- }
1
+ const { dashToPascal } = require("../../../../textUtils")
5
2
 
6
3
  const getCoreRepository = (name) => `import { IRepository } from '@/infra/repository';
7
4
 
8
- import { ${capitalizeFirstLetter(name)}Entity } from '../entity/${name}';
9
- import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '../use-cases/${name}-list';
5
+ import { ${dashToPascal(name)}Entity } from '../entity/${name}';
6
+ import { ${dashToPascal(name)}ListInput, ${dashToPascal(name)}ListOutput } from '../use-cases/${name}-list';
10
7
 
11
- export abstract class I${capitalizeFirstLetter(name)}Repository extends IRepository<${capitalizeFirstLetter(name)}Entity> {
12
- abstract paginate(input: ${capitalizeFirstLetter(name)}ListInput): Promise<${capitalizeFirstLetter(name)}ListOutput>;
8
+ export abstract class I${dashToPascal(name)}Repository extends IRepository<${dashToPascal(name)}Entity> {
9
+ abstract paginate(input: ${dashToPascal(name)}ListInput): Promise<${dashToPascal(name)}ListOutput>;
13
10
  }
14
11
  `
15
12
 
@@ -1,28 +1,25 @@
1
-
2
- function capitalizeFirstLetter(string) {
3
- return string.charAt(0).toUpperCase() + string.slice(1);
4
- }
1
+ const { dashToPascal } = require("../../../../../textUtils")
5
2
 
6
3
  const getCoreUsecaseCreateTest = (name) => `import { Test } from '@nestjs/testing';
7
4
  import { ZodIssue } from 'zod';
8
5
 
9
6
  import { ILoggerAdapter } from '@/infra/logger';
10
- import { I${capitalizeFirstLetter(name)}CreateAdapter } from '@/modules/${name}/adapter';
7
+ import { I${dashToPascal(name)}CreateAdapter } from '@/modules/${name}/adapter';
11
8
  import { TestUtils } from '@/utils/tests';
12
9
 
13
- import { ${capitalizeFirstLetter(name)}Entity } from '../../entity/${name}';
14
- import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
15
- import { ${capitalizeFirstLetter(name)}CreateInput, ${capitalizeFirstLetter(name)}CreateOutput, ${capitalizeFirstLetter(name)}CreateUsecase } from '../${name}-create';
10
+ import { ${dashToPascal(name)}Entity } from '../../entity/${name}';
11
+ import { I${dashToPascal(name)}Repository } from '../../repository/${name}';
12
+ import { ${dashToPascal(name)}CreateInput, ${dashToPascal(name)}CreateOutput, ${dashToPascal(name)}CreateUsecase } from '../${name}-create';
16
13
 
17
- describe(${capitalizeFirstLetter(name)}CreateUsecase.name, () => {
18
- let usecase: I${capitalizeFirstLetter(name)}CreateAdapter;
19
- let repository: I${capitalizeFirstLetter(name)}Repository;
14
+ describe(${dashToPascal(name)}CreateUsecase.name, () => {
15
+ let usecase: I${dashToPascal(name)}CreateAdapter;
16
+ let repository: I${dashToPascal(name)}Repository;
20
17
 
21
18
  beforeEach(async () => {
22
19
  const app = await Test.createTestingModule({
23
20
  providers: [
24
21
  {
25
- provide: I${capitalizeFirstLetter(name)}Repository,
22
+ provide: I${dashToPascal(name)}Repository,
26
23
  useValue: {}
27
24
  },
28
25
  {
@@ -32,34 +29,34 @@ describe(${capitalizeFirstLetter(name)}CreateUsecase.name, () => {
32
29
  }
33
30
  },
34
31
  {
35
- provide: I${capitalizeFirstLetter(name)}CreateAdapter,
36
- useFactory: (${name}Repository: I${capitalizeFirstLetter(name)}Repository, logger: ILoggerAdapter) => {
37
- return new ${capitalizeFirstLetter(name)}CreateUsecase(${name}Repository, logger);
32
+ provide: I${dashToPascal(name)}CreateAdapter,
33
+ useFactory: (${name}Repository: I${dashToPascal(name)}Repository, logger: ILoggerAdapter) => {
34
+ return new ${dashToPascal(name)}CreateUsecase(${name}Repository, logger);
38
35
  },
39
- inject: [I${capitalizeFirstLetter(name)}Repository, ILoggerAdapter]
36
+ inject: [I${dashToPascal(name)}Repository, ILoggerAdapter]
40
37
  }
41
38
  ]
42
39
  }).compile();
43
40
 
44
- usecase = app.get(I${capitalizeFirstLetter(name)}CreateAdapter);
45
- repository = app.get(I${capitalizeFirstLetter(name)}Repository);
41
+ usecase = app.get(I${dashToPascal(name)}CreateAdapter);
42
+ repository = app.get(I${dashToPascal(name)}Repository);
46
43
  });
47
44
 
48
45
  test('when no input is specified, should expect an error', async () => {
49
46
  await TestUtils.expectZodError(
50
- () => usecase.execute({} as ${capitalizeFirstLetter(name)}CreateInput),
47
+ () => usecase.execute({} as ${dashToPascal(name)}CreateInput),
51
48
  (issues: ZodIssue[]) => {
52
- expect(issues).toEqual([{ message: 'Required', path: ${capitalizeFirstLetter(name)}Entity.nameOf('name') }]);
49
+ expect(issues).toEqual([{ message: 'Required', path: ${dashToPascal(name)}Entity.nameOf('name') }]);
53
50
  }
54
51
  );
55
52
  });
56
53
 
57
- const input: ${capitalizeFirstLetter(name)}CreateInput = {
54
+ const input: ${dashToPascal(name)}CreateInput = {
58
55
  name: 'name'
59
56
  };
60
57
 
61
58
  test('when ${name} created successfully, should expect a ${name}', async () => {
62
- const output: ${capitalizeFirstLetter(name)}CreateOutput = { created: true, id: TestUtils.getMockUUID() };
59
+ const output: ${dashToPascal(name)}CreateOutput = { created: true, id: TestUtils.getMockUUID() };
63
60
  repository.findOne = jest.fn().mockResolvedValue(null);
64
61
  repository.create = jest.fn().mockResolvedValue(output);
65
62
 
@@ -1,55 +1,52 @@
1
-
2
- function capitalizeFirstLetter(string) {
3
- return string.charAt(0).toUpperCase() + string.slice(1);
4
- }
1
+ const { dashToPascal } = require("../../../../../textUtils")
5
2
 
6
3
  const getCoreUsecaseDeleteTest = (name) => `import { Test } from '@nestjs/testing';
7
4
  import { ZodIssue } from 'zod';
8
5
 
9
- import { I${capitalizeFirstLetter(name)}DeleteAdapter } from '@/modules/${name}/adapter';
6
+ import { I${dashToPascal(name)}DeleteAdapter } from '@/modules/${name}/adapter';
10
7
  import { ApiNotFoundException } from '@/utils/exception';
11
8
  import { TestUtils } from '@/utils/tests';
12
9
 
13
- import { ${capitalizeFirstLetter(name)}Entity } from '../../entity/${name}';
14
- import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
15
- import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}DeleteUsecase } from '../${name}-delete';
10
+ import { ${dashToPascal(name)}Entity } from '../../entity/${name}';
11
+ import { I${dashToPascal(name)}Repository } from '../../repository/${name}';
12
+ import { ${dashToPascal(name)}DeleteInput, ${dashToPascal(name)}DeleteUsecase } from '../${name}-delete';
16
13
 
17
- describe(${capitalizeFirstLetter(name)}DeleteUsecase.name, () => {
18
- let usecase: I${capitalizeFirstLetter(name)}DeleteAdapter;
19
- let repository: I${capitalizeFirstLetter(name)}Repository;
14
+ describe(${dashToPascal(name)}DeleteUsecase.name, () => {
15
+ let usecase: I${dashToPascal(name)}DeleteAdapter;
16
+ let repository: I${dashToPascal(name)}Repository;
20
17
 
21
18
  beforeEach(async () => {
22
19
  const app = await Test.createTestingModule({
23
20
  imports: [],
24
21
  providers: [
25
22
  {
26
- provide: I${capitalizeFirstLetter(name)}Repository,
23
+ provide: I${dashToPascal(name)}Repository,
27
24
  useValue: {}
28
25
  },
29
26
  {
30
- provide: I${capitalizeFirstLetter(name)}DeleteAdapter,
31
- useFactory: (${name}Repository: I${capitalizeFirstLetter(name)}Repository) => {
32
- return new ${capitalizeFirstLetter(name)}DeleteUsecase(${name}Repository);
27
+ provide: I${dashToPascal(name)}DeleteAdapter,
28
+ useFactory: (${name}Repository: I${dashToPascal(name)}Repository) => {
29
+ return new ${dashToPascal(name)}DeleteUsecase(${name}Repository);
33
30
  },
34
- inject: [I${capitalizeFirstLetter(name)}Repository]
31
+ inject: [I${dashToPascal(name)}Repository]
35
32
  }
36
33
  ]
37
34
  }).compile();
38
35
 
39
- usecase = app.get(I${capitalizeFirstLetter(name)}DeleteAdapter);
40
- repository = app.get(I${capitalizeFirstLetter(name)}Repository);
36
+ usecase = app.get(I${dashToPascal(name)}DeleteAdapter);
37
+ repository = app.get(I${dashToPascal(name)}Repository);
41
38
  });
42
39
 
43
40
  test('when no input is specified, should expect an error', async () => {
44
41
  await TestUtils.expectZodError(
45
- () => usecase.execute({} as ${capitalizeFirstLetter(name)}DeleteInput),
42
+ () => usecase.execute({} as ${dashToPascal(name)}DeleteInput),
46
43
  (issues: ZodIssue[]) => {
47
- expect(issues).toEqual([{ message: 'Required', path: ${capitalizeFirstLetter(name)}Entity.nameOf('id') }]);
44
+ expect(issues).toEqual([{ message: 'Required', path: ${dashToPascal(name)}Entity.nameOf('id') }]);
48
45
  }
49
46
  );
50
47
  });
51
48
 
52
- const input: ${capitalizeFirstLetter(name)}DeleteInput = {
49
+ const input: ${dashToPascal(name)}DeleteInput = {
53
50
  id: TestUtils.getMockUUID()
54
51
  };
55
52
 
@@ -59,7 +56,7 @@ describe(${capitalizeFirstLetter(name)}DeleteUsecase.name, () => {
59
56
  await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
60
57
  });
61
58
 
62
- const ${name} = new ${capitalizeFirstLetter(name)}Entity({
59
+ const ${name} = new ${dashToPascal(name)}Entity({
63
60
  id: TestUtils.getMockUUID(),
64
61
  name: 'dummy'
65
62
  });
@@ -1,55 +1,52 @@
1
-
2
- function capitalizeFirstLetter(string) {
3
- return string.charAt(0).toUpperCase() + string.slice(1);
4
- }
1
+ const { dashToPascal } = require("../../../../../textUtils")
5
2
 
6
3
  const getCoreUsecaseGetByIdTest = (name) => `import { Test } from '@nestjs/testing';
7
4
  import { ZodIssue } from 'zod';
8
5
 
9
- import { I${capitalizeFirstLetter(name)}GetByIdAdapter } from '@/modules/${name}/adapter';
6
+ import { I${dashToPascal(name)}GetByIdAdapter } from '@/modules/${name}/adapter';
10
7
  import { ApiNotFoundException } from '@/utils/exception';
11
8
  import { TestUtils } from '@/utils/tests';
12
9
 
13
- import { ${capitalizeFirstLetter(name)}Entity } from '../../entity/${name}';
14
- import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
15
- import { ${capitalizeFirstLetter(name)}GetByIdInput, ${capitalizeFirstLetter(name)}GetByIdUsecase } from '../${name}-get-by-id';
10
+ import { ${dashToPascal(name)}Entity } from '../../entity/${name}';
11
+ import { I${dashToPascal(name)}Repository } from '../../repository/${name}';
12
+ import { ${dashToPascal(name)}GetByIdInput, ${dashToPascal(name)}GetByIdUsecase } from '../${name}-get-by-id';
16
13
 
17
- describe(${capitalizeFirstLetter(name)}GetByIdUsecase.name, () => {
18
- let usecase: I${capitalizeFirstLetter(name)}GetByIdAdapter;
19
- let repository: I${capitalizeFirstLetter(name)}Repository;
14
+ describe(${dashToPascal(name)}GetByIdUsecase.name, () => {
15
+ let usecase: I${dashToPascal(name)}GetByIdAdapter;
16
+ let repository: I${dashToPascal(name)}Repository;
20
17
 
21
18
  beforeEach(async () => {
22
19
  const app = await Test.createTestingModule({
23
20
  imports: [],
24
21
  providers: [
25
22
  {
26
- provide: I${capitalizeFirstLetter(name)}Repository,
23
+ provide: I${dashToPascal(name)}Repository,
27
24
  useValue: {}
28
25
  },
29
26
  {
30
- provide: I${capitalizeFirstLetter(name)}GetByIdAdapter,
31
- useFactory: (${name}Repository: I${capitalizeFirstLetter(name)}Repository) => {
32
- return new ${capitalizeFirstLetter(name)}GetByIdUsecase(${name}Repository);
27
+ provide: I${dashToPascal(name)}GetByIdAdapter,
28
+ useFactory: (${name}Repository: I${dashToPascal(name)}Repository) => {
29
+ return new ${dashToPascal(name)}GetByIdUsecase(${name}Repository);
33
30
  },
34
- inject: [I${capitalizeFirstLetter(name)}Repository]
31
+ inject: [I${dashToPascal(name)}Repository]
35
32
  }
36
33
  ]
37
34
  }).compile();
38
35
 
39
- usecase = app.get(I${capitalizeFirstLetter(name)}GetByIdAdapter);
40
- repository = app.get(I${capitalizeFirstLetter(name)}Repository);
36
+ usecase = app.get(I${dashToPascal(name)}GetByIdAdapter);
37
+ repository = app.get(I${dashToPascal(name)}Repository);
41
38
  });
42
39
 
43
40
  test('when no input is specified, should expect an error', async () => {
44
41
  await TestUtils.expectZodError(
45
- () => usecase.execute({} as ${capitalizeFirstLetter(name)}GetByIdInput),
42
+ () => usecase.execute({} as ${dashToPascal(name)}GetByIdInput),
46
43
  (issues: ZodIssue[]) => {
47
- expect(issues).toEqual([{ message: 'Required', path: ${capitalizeFirstLetter(name)}Entity.nameOf('id') }]);
44
+ expect(issues).toEqual([{ message: 'Required', path: ${dashToPascal(name)}Entity.nameOf('id') }]);
48
45
  }
49
46
  );
50
47
  });
51
48
 
52
- const input: ${capitalizeFirstLetter(name)}GetByIdInput = {
49
+ const input: ${dashToPascal(name)}GetByIdInput = {
53
50
  id: TestUtils.getMockUUID()
54
51
  };
55
52
 
@@ -59,7 +56,7 @@ describe(${capitalizeFirstLetter(name)}GetByIdUsecase.name, () => {
59
56
  await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
60
57
  });
61
58
 
62
- const ${name} = new ${capitalizeFirstLetter(name)}Entity({
59
+ const ${name} = new ${dashToPascal(name)}Entity({
63
60
  id: '61cc35f3-03d9-4b7f-9c63-59f32b013ef5',
64
61
  name: 'dummy'
65
62
  });
@@ -1,49 +1,46 @@
1
1
 
2
2
  const pluralize = require('pluralize')
3
-
4
- function capitalizeFirstLetter(string) {
5
- return string.charAt(0).toUpperCase() + string.slice(1);
6
- }
3
+ const { dashToPascal } = require('../../../../../textUtils')
7
4
 
8
5
  const getCoreUsecaseListTest = (name) => `import { Test } from '@nestjs/testing';
9
6
  import { ZodIssue } from 'zod';
10
7
 
11
- import { I${capitalizeFirstLetter(name)}ListAdapter } from '@/modules/${name}/adapter';
8
+ import { I${dashToPascal(name)}ListAdapter } from '@/modules/${name}/adapter';
12
9
  import { TestUtils } from '@/utils/tests';
13
10
 
14
- import { ${capitalizeFirstLetter(name)}Entity } from '../../entity/${name}';
15
- import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
16
- import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput, ${capitalizeFirstLetter(name)}ListUsecase } from '../${name}-list';
11
+ import { ${dashToPascal(name)}Entity } from '../../entity/${name}';
12
+ import { I${dashToPascal(name)}Repository } from '../../repository/${name}';
13
+ import { ${dashToPascal(name)}ListInput, ${dashToPascal(name)}ListOutput, ${dashToPascal(name)}ListUsecase } from '../${name}-list';
17
14
 
18
- describe(${capitalizeFirstLetter(name)}ListUsecase.name, () => {
19
- let usecase: I${capitalizeFirstLetter(name)}ListAdapter;
20
- let repository: I${capitalizeFirstLetter(name)}Repository;
15
+ describe(${dashToPascal(name)}ListUsecase.name, () => {
16
+ let usecase: I${dashToPascal(name)}ListAdapter;
17
+ let repository: I${dashToPascal(name)}Repository;
21
18
 
22
19
  beforeEach(async () => {
23
20
  const app = await Test.createTestingModule({
24
21
  imports: [],
25
22
  providers: [
26
23
  {
27
- provide: I${capitalizeFirstLetter(name)}Repository,
24
+ provide: I${dashToPascal(name)}Repository,
28
25
  useValue: {}
29
26
  },
30
27
  {
31
- provide: I${capitalizeFirstLetter(name)}ListAdapter,
32
- useFactory: (${name}Repository: I${capitalizeFirstLetter(name)}Repository) => {
33
- return new ${capitalizeFirstLetter(name)}ListUsecase(${name}Repository);
28
+ provide: I${dashToPascal(name)}ListAdapter,
29
+ useFactory: (${name}Repository: I${dashToPascal(name)}Repository) => {
30
+ return new ${dashToPascal(name)}ListUsecase(${name}Repository);
34
31
  },
35
- inject: [I${capitalizeFirstLetter(name)}Repository]
32
+ inject: [I${dashToPascal(name)}Repository]
36
33
  }
37
34
  ]
38
35
  }).compile();
39
36
 
40
- usecase = app.get(I${capitalizeFirstLetter(name)}ListAdapter);
41
- repository = app.get(I${capitalizeFirstLetter(name)}Repository);
37
+ usecase = app.get(I${dashToPascal(name)}ListAdapter);
38
+ repository = app.get(I${dashToPascal(name)}Repository);
42
39
  });
43
40
 
44
41
  test('when sort input is specified, should expect an error', async () => {
45
42
  await TestUtils.expectZodError(
46
- () => usecase.execute({} as ${capitalizeFirstLetter(name)}ListInput),
43
+ () => usecase.execute({} as ${dashToPascal(name)}ListInput),
47
44
  (issues: ZodIssue[]) => {
48
45
  expect(issues).toEqual([
49
46
  { message: 'Required', path: 'sort' },
@@ -53,9 +50,9 @@ describe(${capitalizeFirstLetter(name)}ListUsecase.name, () => {
53
50
  );
54
51
  });
55
52
 
56
- const input: ${capitalizeFirstLetter(name)}ListInput = { limit: 1, page: 1, search: {}, sort: { createdAt: -1 } };
53
+ const input: ${dashToPascal(name)}ListInput = { limit: 1, page: 1, search: {}, sort: { createdAt: -1 } };
57
54
 
58
- const ${name} = new ${capitalizeFirstLetter(name)}Entity({
55
+ const ${name} = new ${dashToPascal(name)}Entity({
59
56
  id: TestUtils.getMockUUID(),
60
57
  name: 'dummy',
61
58
  createdAt: new Date(),
@@ -65,7 +62,7 @@ describe(${capitalizeFirstLetter(name)}ListUsecase.name, () => {
65
62
  const ${pluralize(name)} = [${name}];
66
63
 
67
64
  test('when ${name} are found, should expect an ${name} list', async () => {
68
- const output: ${capitalizeFirstLetter(name)}ListOutput = { docs: ${pluralize(name)}, page: 1, limit: 1, total: 1 };
65
+ const output: ${dashToPascal(name)}ListOutput = { docs: ${pluralize(name)}, page: 1, limit: 1, total: 1 };
69
66
  repository.paginate = jest.fn().mockResolvedValue(output);
70
67
 
71
68
  await expect(usecase.execute(input)).resolves.toEqual({
@@ -77,7 +74,7 @@ describe(${capitalizeFirstLetter(name)}ListUsecase.name, () => {
77
74
  });
78
75
 
79
76
  test('when ${name} not found, should expect an empty list', async () => {
80
- const output: ${capitalizeFirstLetter(name)}ListOutput = { docs: [], page: 1, limit: 1, total: 1 };
77
+ const output: ${dashToPascal(name)}ListOutput = { docs: [], page: 1, limit: 1, total: 1 };
81
78
  repository.paginate = jest.fn().mockResolvedValue(output);
82
79
 
83
80
  await expect(usecase.execute(input)).resolves.toEqual(output);