@apso/cli 0.7.1 → 0.7.3

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.
@@ -56,6 +56,10 @@ export class <%= it.name %> {
56
56
  @Column({ type: 'uuid' })
57
57
  @PrimaryColumn()
58
58
  id: string;
59
+ <% } else if (it.primaryKeyType === 'text') { %>
60
+ @Column({ type: 'text' })
61
+ @PrimaryColumn()
62
+ id: string;
59
63
  <% } else { %>
60
64
  @PrimaryGeneratedColumn()
61
65
  id!: number;
@@ -7,6 +7,10 @@ import * as enums from '../../enums';
7
7
  <% } %>
8
8
 
9
9
  export class <%= it.entityName %>Create {
10
+ <% if (it.addDefaultPKProperty && (it.primaryKeyType === 'uuid' || it.primaryKeyType === 'text')) { %>
11
+ @ApiProperty()
12
+ id: string;
13
+ <% } %>
10
14
  <% it.columns.forEach((field) => { %>
11
15
  @ApiProperty()
12
16
  <%if (field.dataType.includes("Enum")) {%>
@@ -36,7 +40,7 @@ export class <%= it.entityName %>Create {
36
40
  export class <%= it.entityName %> {
37
41
  <% if (it.addDefaultPKProperty) { %>
38
42
  @ApiProperty()
39
- id: <%= it.primaryKeyType === 'uuid' ? 'string' : 'number' %>;
43
+ id: <%= (it.primaryKeyType === 'uuid' || it.primaryKeyType === 'text') ? 'string' : 'number' %>;
40
44
  <% } %>
41
45
  <% it.columns.forEach((field) => { %>
42
46
  @ApiProperty()
@@ -1,39 +1,78 @@
1
1
  <%~ includeFile('./header.eta') %>
2
2
 
3
3
  import { Test, TestingModule } from '@nestjs/testing';
4
+ import { getRepositoryToken } from '@nestjs/typeorm';
4
5
  import { <%= it.svcName %> } from './<%= it.entityName %>.service';
5
- import { TypeOrmModule } from '@nestjs/typeorm';
6
6
  import { <%= it.entityName %> } from './<%= it.entityName %>.entity';
7
- <% it.allRelatedEntities.forEach(function(entity) { if (entity !== it.entityName) { %>
8
- import { <%= entity %> } from '../<%= entity %>/<%= entity %>.entity';
9
- <% }}); %>
10
-
11
- // All related entities (including the main entity) are included below to ensure TypeORM can resolve relationships for this service's entity and its graph.
12
7
 
13
8
  describe('<%= it.svcName %>', () => {
14
9
  let service: <%= it.svcName %>;
15
10
  let mockRepository: any;
16
11
 
17
12
  beforeEach(async () => {
13
+ // Mock query builder chain
14
+ const mockQueryBuilder = {
15
+ where: jest.fn().mockReturnThis(),
16
+ andWhere: jest.fn().mockReturnThis(),
17
+ orWhere: jest.fn().mockReturnThis(),
18
+ orderBy: jest.fn().mockReturnThis(),
19
+ addOrderBy: jest.fn().mockReturnThis(),
20
+ skip: jest.fn().mockReturnThis(),
21
+ take: jest.fn().mockReturnThis(),
22
+ select: jest.fn().mockReturnThis(),
23
+ addSelect: jest.fn().mockReturnThis(),
24
+ leftJoin: jest.fn().mockReturnThis(),
25
+ leftJoinAndSelect: jest.fn().mockReturnThis(),
26
+ innerJoin: jest.fn().mockReturnThis(),
27
+ innerJoinAndSelect: jest.fn().mockReturnThis(),
28
+ getMany: jest.fn().mockResolvedValue([]),
29
+ getOne: jest.fn().mockResolvedValue(null),
30
+ getManyAndCount: jest.fn().mockResolvedValue([[], 0]),
31
+ getCount: jest.fn().mockResolvedValue(0),
32
+ getRawMany: jest.fn().mockResolvedValue([]),
33
+ getRawOne: jest.fn().mockResolvedValue(null),
34
+ };
35
+
36
+ // Mock repository with manager.connection for TypeOrmCrudService
18
37
  mockRepository = {
19
38
  find: jest.fn().mockResolvedValue([]),
20
- findOne: jest.fn().mockResolvedValue({}),
21
- save: jest.fn().mockResolvedValue({}),
22
- create: jest.fn().mockReturnValue({}),
23
- update: jest.fn().mockResolvedValue({}),
24
- delete: jest.fn().mockResolvedValue({}),
39
+ findOne: jest.fn().mockResolvedValue(null),
40
+ findOneBy: jest.fn().mockResolvedValue(null),
41
+ save: jest.fn().mockImplementation((entity) => Promise.resolve({ id: 'mock-id', ...entity })),
42
+ create: jest.fn().mockImplementation((dto) => dto),
43
+ update: jest.fn().mockResolvedValue({ affected: 1 }),
44
+ delete: jest.fn().mockResolvedValue({ affected: 1 }),
45
+ remove: jest.fn().mockResolvedValue({}),
46
+ count: jest.fn().mockResolvedValue(0),
47
+ createQueryBuilder: jest.fn(() => mockQueryBuilder),
48
+ target: <%= it.entityName %>,
49
+ metadata: {
50
+ columns: [],
51
+ relations: [],
52
+ primaryColumns: [{ propertyName: 'id' }],
53
+ connection: { options: { type: 'postgres' } },
54
+ },
55
+ manager: {
56
+ connection: {
57
+ options: { type: 'postgres' },
58
+ getMetadata: jest.fn().mockReturnValue({
59
+ columns: [],
60
+ relations: [],
61
+ primaryColumns: [{ propertyName: 'id' }],
62
+ }),
63
+ },
64
+ transaction: jest.fn().mockImplementation((cb) => cb(mockRepository.manager)),
65
+ },
25
66
  };
26
67
 
27
68
  const module: TestingModule = await Test.createTestingModule({
28
- imports: [
29
- TypeOrmModule.forRoot({
30
- // ...database config (provide your test DB config here)
31
- entities: [<%= [it.entityName, ...it.allRelatedEntities.filter(e => e !== it.entityName)].join(', ') %>],
32
- synchronize: true,
33
- }),
34
- TypeOrmModule.forFeature([<%= it.entityName %>]),
69
+ providers: [
70
+ <%= it.svcName %>,
71
+ {
72
+ provide: getRepositoryToken(<%= it.entityName %>),
73
+ useValue: mockRepository,
74
+ },
35
75
  ],
36
- providers: [<%= it.svcName %>],
37
76
  }).compile();
38
77
 
39
78
  service = module.get<<%= it.svcName %>>(<%= it.svcName %>);
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.1",
2
+ "version": "0.7.3",
3
3
  "commands": {
4
4
  "server:new": {
5
5
  "id": "server:new",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apso/cli",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Apso CLI",
5
5
  "author": "Apso by Mavric - @mavric",
6
6
  "bin": {