@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.
- package/package.json +1 -1
- package/src/cli.js +1 -1
- package/src/templates/infra/adapter.js +4 -7
- package/src/templates/infra/module.js +7 -10
- package/src/templates/infra/service.js +6 -9
- package/src/templates/libs/adapter.js +4 -7
- package/src/templates/libs/module.js +7 -10
- package/src/templates/libs/service.js +8 -11
- package/src/templates/module/controller.js +2 -5
- package/src/templates/module/module.js +4 -6
- package/src/templates/mongo/core/entity/entity.js +5 -8
- package/src/templates/mongo/core/repository/repository.js +5 -8
- package/src/templates/mongo/core/use-cases/__tests__/create.spec.js +19 -22
- package/src/templates/mongo/core/use-cases/__tests__/delete.spec.js +19 -22
- package/src/templates/mongo/core/use-cases/__tests__/get-by-id.spec.js +19 -22
- package/src/templates/mongo/core/use-cases/__tests__/list.spec.js +20 -23
- package/src/templates/mongo/core/use-cases/__tests__/update.spec.js +19 -22
- package/src/templates/mongo/core/use-cases/create.js +11 -14
- package/src/templates/mongo/core/use-cases/delete.js +11 -14
- package/src/templates/mongo/core/use-cases/get-by-id.js +11 -14
- package/src/templates/mongo/core/use-cases/list.js +11 -14
- package/src/templates/mongo/core/use-cases/update.js +14 -17
- package/src/templates/mongo/modules/adapter.js +16 -19
- package/src/templates/mongo/modules/controller.js +27 -30
- package/src/templates/mongo/modules/module.js +52 -54
- package/src/templates/mongo/modules/repository.js +7 -10
- package/src/templates/mongo/modules/swagger.js +16 -19
- package/src/templates/mongo/schemas/schema.js +9 -12
- package/src/templates/postgres/core/entity/entity.js +5 -8
- package/src/templates/postgres/core/repository/repository.js +5 -8
- package/src/templates/postgres/core/use-cases/__tests__/create.spec.js +19 -22
- package/src/templates/postgres/core/use-cases/__tests__/delete.spec.js +19 -22
- package/src/templates/postgres/core/use-cases/__tests__/get-by-id.spec.js +19 -22
- package/src/templates/postgres/core/use-cases/__tests__/list.spec.js +20 -23
- package/src/templates/postgres/core/use-cases/__tests__/update.spec.js +19 -22
- package/src/templates/postgres/core/use-cases/create.js +11 -14
- package/src/templates/postgres/core/use-cases/delete.js +11 -14
- package/src/templates/postgres/core/use-cases/get-by-id.js +12 -15
- package/src/templates/postgres/core/use-cases/list.js +10 -13
- package/src/templates/postgres/core/use-cases/update.js +14 -17
- package/src/templates/postgres/modules/adapter.js +16 -19
- package/src/templates/postgres/modules/controller.js +27 -30
- package/src/templates/postgres/modules/module.js +40 -43
- package/src/templates/postgres/modules/repository.js +10 -13
- package/src/templates/postgres/modules/swagger.js +16 -20
- package/src/templates/postgres/schemas/schema.js +2 -5
- package/src/textUtils.js +9 -0
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
+
const { dashToPascal } = require("../../textUtils")
|
|
1
2
|
|
|
2
|
-
|
|
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${
|
|
9
|
-
abstract get(input: ${
|
|
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${
|
|
9
|
-
import { ${
|
|
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${
|
|
16
|
-
useClass: ${
|
|
12
|
+
provide: I${dashToPascal(name)}Adapter,
|
|
13
|
+
useClass: ${dashToPascal(name)}Service
|
|
17
14
|
}
|
|
18
15
|
],
|
|
19
|
-
exports: [I${
|
|
16
|
+
exports: [I${dashToPascal(name)}Adapter]
|
|
20
17
|
})
|
|
21
|
-
export class ${
|
|
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${
|
|
5
|
+
import { I${dashToPascal(name)}Adapter } from './adapter';
|
|
9
6
|
|
|
10
|
-
export type ${
|
|
11
|
-
export type ${
|
|
7
|
+
export type ${dashToPascal(name)}GetInput = {};
|
|
8
|
+
export type ${dashToPascal(name)}GetOutput = {};
|
|
12
9
|
|
|
13
10
|
@Injectable()
|
|
14
|
-
export class ${
|
|
15
|
-
get(input: ${
|
|
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
|
-
|
|
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${
|
|
9
|
-
abstract get(input: ${
|
|
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${
|
|
9
|
-
import { ${
|
|
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${
|
|
16
|
-
useFactory: () => new ${
|
|
12
|
+
provide: I${dashToPascal(name)}Adapter,
|
|
13
|
+
useFactory: () => new ${dashToPascal(name)}Service()
|
|
17
14
|
}
|
|
18
15
|
],
|
|
19
|
-
exports: [I${
|
|
16
|
+
exports: [I${dashToPascal(name)}Adapter]
|
|
20
17
|
})
|
|
21
|
-
export class ${
|
|
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${
|
|
8
|
+
import { I${dashToPascal(name)}Adapter } from './adapter';
|
|
12
9
|
|
|
13
|
-
const ${
|
|
10
|
+
const ${dashToPascal(name)}Schema = z.object({ name: z.string().trim() });
|
|
14
11
|
|
|
15
|
-
export type ${
|
|
12
|
+
export type ${dashToPascal(name)}Input = z.infer<typeof ${dashToPascal(name)}Schema>;
|
|
16
13
|
|
|
17
|
-
export type ${
|
|
14
|
+
export type ${dashToPascal(name)}Output = string;
|
|
18
15
|
|
|
19
16
|
@Injectable()
|
|
20
|
-
export class ${
|
|
21
|
-
@ValidateSchema(${
|
|
22
|
-
get({ name }: ${
|
|
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 ${
|
|
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
|
-
|
|
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 { ${
|
|
5
|
+
import { ${dashToPascal(name)}Controller } from './controller';
|
|
8
6
|
|
|
9
7
|
@Module({
|
|
10
8
|
imports: [],
|
|
11
|
-
controllers: [${
|
|
9
|
+
controllers: [${dashToPascal(name)}Controller]
|
|
12
10
|
})
|
|
13
|
-
export class ${
|
|
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 ${
|
|
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 ${
|
|
21
|
+
type ${dashToPascal(name)} = z.infer<typeof ${dashToPascal(name)}EntitySchema>;
|
|
25
22
|
|
|
26
|
-
export class ${
|
|
23
|
+
export class ${dashToPascal(name)}Entity extends BaseEntity<${dashToPascal(name)}Entity>(${dashToPascal(name)}EntitySchema) {
|
|
27
24
|
name!: string;
|
|
28
25
|
|
|
29
|
-
constructor(entity: ${
|
|
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 { ${
|
|
9
|
-
import { ${
|
|
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${
|
|
12
|
-
abstract paginate(input: ${
|
|
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${
|
|
7
|
+
import { I${dashToPascal(name)}CreateAdapter } from '@/modules/${name}/adapter';
|
|
11
8
|
import { TestUtils } from '@/utils/tests';
|
|
12
9
|
|
|
13
|
-
import { ${
|
|
14
|
-
import { I${
|
|
15
|
-
import { ${
|
|
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(${
|
|
18
|
-
let usecase: I${
|
|
19
|
-
let repository: I${
|
|
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${
|
|
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${
|
|
36
|
-
useFactory: (${name}Repository: I${
|
|
37
|
-
return new ${
|
|
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${
|
|
36
|
+
inject: [I${dashToPascal(name)}Repository, ILoggerAdapter]
|
|
40
37
|
}
|
|
41
38
|
]
|
|
42
39
|
}).compile();
|
|
43
40
|
|
|
44
|
-
usecase = app.get(I${
|
|
45
|
-
repository = app.get(I${
|
|
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 ${
|
|
47
|
+
() => usecase.execute({} as ${dashToPascal(name)}CreateInput),
|
|
51
48
|
(issues: ZodIssue[]) => {
|
|
52
|
-
expect(issues).toEqual([{ message: 'Required', path: ${
|
|
49
|
+
expect(issues).toEqual([{ message: 'Required', path: ${dashToPascal(name)}Entity.nameOf('name') }]);
|
|
53
50
|
}
|
|
54
51
|
);
|
|
55
52
|
});
|
|
56
53
|
|
|
57
|
-
const input: ${
|
|
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: ${
|
|
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${
|
|
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 { ${
|
|
14
|
-
import { I${
|
|
15
|
-
import { ${
|
|
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(${
|
|
18
|
-
let usecase: I${
|
|
19
|
-
let repository: I${
|
|
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${
|
|
23
|
+
provide: I${dashToPascal(name)}Repository,
|
|
27
24
|
useValue: {}
|
|
28
25
|
},
|
|
29
26
|
{
|
|
30
|
-
provide: I${
|
|
31
|
-
useFactory: (${name}Repository: I${
|
|
32
|
-
return new ${
|
|
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${
|
|
31
|
+
inject: [I${dashToPascal(name)}Repository]
|
|
35
32
|
}
|
|
36
33
|
]
|
|
37
34
|
}).compile();
|
|
38
35
|
|
|
39
|
-
usecase = app.get(I${
|
|
40
|
-
repository = app.get(I${
|
|
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 ${
|
|
42
|
+
() => usecase.execute({} as ${dashToPascal(name)}DeleteInput),
|
|
46
43
|
(issues: ZodIssue[]) => {
|
|
47
|
-
expect(issues).toEqual([{ message: 'Required', path: ${
|
|
44
|
+
expect(issues).toEqual([{ message: 'Required', path: ${dashToPascal(name)}Entity.nameOf('id') }]);
|
|
48
45
|
}
|
|
49
46
|
);
|
|
50
47
|
});
|
|
51
48
|
|
|
52
|
-
const input: ${
|
|
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 ${
|
|
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${
|
|
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 { ${
|
|
14
|
-
import { I${
|
|
15
|
-
import { ${
|
|
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(${
|
|
18
|
-
let usecase: I${
|
|
19
|
-
let repository: I${
|
|
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${
|
|
23
|
+
provide: I${dashToPascal(name)}Repository,
|
|
27
24
|
useValue: {}
|
|
28
25
|
},
|
|
29
26
|
{
|
|
30
|
-
provide: I${
|
|
31
|
-
useFactory: (${name}Repository: I${
|
|
32
|
-
return new ${
|
|
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${
|
|
31
|
+
inject: [I${dashToPascal(name)}Repository]
|
|
35
32
|
}
|
|
36
33
|
]
|
|
37
34
|
}).compile();
|
|
38
35
|
|
|
39
|
-
usecase = app.get(I${
|
|
40
|
-
repository = app.get(I${
|
|
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 ${
|
|
42
|
+
() => usecase.execute({} as ${dashToPascal(name)}GetByIdInput),
|
|
46
43
|
(issues: ZodIssue[]) => {
|
|
47
|
-
expect(issues).toEqual([{ message: 'Required', path: ${
|
|
44
|
+
expect(issues).toEqual([{ message: 'Required', path: ${dashToPascal(name)}Entity.nameOf('id') }]);
|
|
48
45
|
}
|
|
49
46
|
);
|
|
50
47
|
});
|
|
51
48
|
|
|
52
|
-
const input: ${
|
|
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 ${
|
|
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${
|
|
8
|
+
import { I${dashToPascal(name)}ListAdapter } from '@/modules/${name}/adapter';
|
|
12
9
|
import { TestUtils } from '@/utils/tests';
|
|
13
10
|
|
|
14
|
-
import { ${
|
|
15
|
-
import { I${
|
|
16
|
-
import { ${
|
|
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(${
|
|
19
|
-
let usecase: I${
|
|
20
|
-
let repository: I${
|
|
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${
|
|
24
|
+
provide: I${dashToPascal(name)}Repository,
|
|
28
25
|
useValue: {}
|
|
29
26
|
},
|
|
30
27
|
{
|
|
31
|
-
provide: I${
|
|
32
|
-
useFactory: (${name}Repository: I${
|
|
33
|
-
return new ${
|
|
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${
|
|
32
|
+
inject: [I${dashToPascal(name)}Repository]
|
|
36
33
|
}
|
|
37
34
|
]
|
|
38
35
|
}).compile();
|
|
39
36
|
|
|
40
|
-
usecase = app.get(I${
|
|
41
|
-
repository = app.get(I${
|
|
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 ${
|
|
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: ${
|
|
53
|
+
const input: ${dashToPascal(name)}ListInput = { limit: 1, page: 1, search: {}, sort: { createdAt: -1 } };
|
|
57
54
|
|
|
58
|
-
const ${name} = new ${
|
|
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: ${
|
|
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: ${
|
|
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);
|