@koalarx/nest-cli 3.0.46 → 3.0.48

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest-cli",
3
- "version": "3.0.46",
3
+ "version": "3.0.48",
4
4
  "description": "CLI para criação de projetos utilizando Koala Nest",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -19,7 +19,7 @@ describe(`CRUD OF PERSON`, () => {
19
19
  name: 'John Doe',
20
20
  phones: [],
21
21
  address: {
22
- address: 'Streat 1',
22
+ address: 'Street 1',
23
23
  },
24
24
  })
25
25
 
@@ -46,7 +46,7 @@ describe(`CRUD OF PERSON`, () => {
46
46
  phones: [],
47
47
  address: {
48
48
  id: expect.any(Number),
49
- address: 'Streat 1',
49
+ address: 'Street 1',
50
50
  },
51
51
  active: true,
52
52
  })
@@ -66,7 +66,7 @@ describe(`CRUD OF PERSON`, () => {
66
66
  phones: [],
67
67
  address: {
68
68
  id: addressId,
69
- address: 'Streat 1',
69
+ address: 'Street 1',
70
70
  },
71
71
  active: true,
72
72
  },
@@ -101,7 +101,7 @@ describe(`CRUD OF PERSON`, () => {
101
101
  phones: [],
102
102
  address: {
103
103
  id: addressId,
104
- address: 'Streat 1',
104
+ address: 'Street 1',
105
105
  },
106
106
  active: true,
107
107
  },
@@ -118,7 +118,7 @@ describe(`CRUD OF PERSON`, () => {
118
118
  phones: [],
119
119
  address: {
120
120
  id: addressId,
121
- address: 'Streat 2',
121
+ address: 'Street 2',
122
122
  },
123
123
  active: true,
124
124
  })
@@ -135,7 +135,7 @@ describe(`CRUD OF PERSON`, () => {
135
135
  phones: [],
136
136
  address: {
137
137
  id: addressId,
138
- address: 'Streat 2',
138
+ address: 'Street 2',
139
139
  },
140
140
  active: true,
141
141
  })
@@ -5,13 +5,10 @@ import { KoalaAppTest } from '@koalarx/nest/test/koala-app-test'
5
5
  import { Test } from '@nestjs/testing'
6
6
  import { PrismaPg } from '@prisma/adapter-pg'
7
7
  import 'dotenv/config'
8
- import { Pool } from 'pg'
8
+ import { pgClient } from './setup-e2e'
9
9
 
10
10
  export async function createE2ETestApp() {
11
- const pool = new Pool({
12
- connectionString: process.env.DATABASE_URL,
13
- })
14
- const adapter = new PrismaPg(pool)
11
+ const adapter = new PrismaPg(pgClient.pool)
15
12
  setPrismaClientOptions({ adapter })
16
13
 
17
14
  return Test.createTestingModule({ imports: [AppModule] })
@@ -1,12 +1,69 @@
1
1
  import { createE2EDatabase } from '@koalarx/nest/test/utils/create-e2e-database'
2
- import { dropE2EDatabase } from '@koalarx/nest/test/utils/drop-e2e-database'
2
+ import { E2EDatabaseClient } from '@koalarx/nest/test/utils/e2e-database-client'
3
+ import { delay } from '@koalarx/utils'
4
+ import { Pool } from 'pg'
3
5
 
4
- let schemaId: string
6
+ export let pgClient: E2EPostgresClient
7
+
8
+ class E2EPostgresClient extends E2EDatabaseClient {
9
+ private baseUrl: URL
10
+
11
+ public pool: Pool
12
+
13
+ constructor(url: string, schemaName: string) {
14
+ super(url, schemaName)
15
+
16
+ this.baseUrl = new URL(this.url)
17
+ this.baseUrl.pathname = `/${this.schemaName}`
18
+
19
+ this.pool = this.createSession()
20
+ }
21
+
22
+ private createSession(idleTimeout?: number) {
23
+ return new Pool({
24
+ connectionString: this.baseUrl.toString(),
25
+ ...(idleTimeout ? { idleTimeoutMillis: idleTimeout } : {}),
26
+ })
27
+ }
28
+
29
+ async createDatabase(schemaName: string): Promise<void> {
30
+ this.baseUrl.pathname = `/postgres`
31
+
32
+ const pool = this.createSession()
33
+
34
+ await pool.query(`CREATE DATABASE "${schemaName}"`)
35
+ await pool.end()
36
+
37
+ this.baseUrl.pathname = `/${schemaName}`
38
+ }
39
+
40
+ async dropDatabase(): Promise<void> {
41
+ await this.pool.end()
42
+
43
+ await delay(1000)
44
+
45
+ this.baseUrl.pathname = '/postgres'
46
+ const pool = this.createSession(100)
47
+
48
+ await pool.query(`
49
+ SELECT pg_terminate_backend(pg_stat_activity.pid)
50
+ FROM pg_stat_activity
51
+ WHERE pg_stat_activity.datname = '${this.schemaName}'
52
+ AND pid <> pg_backend_pid()
53
+ `)
54
+
55
+ await delay(500)
56
+
57
+ await pool.query(`DROP DATABASE IF EXISTS "${this.schemaName}"`)
58
+ await pool.end()
59
+ }
60
+ }
5
61
 
6
62
  beforeAll(async () => {
7
- schemaId = await createE2EDatabase('bun')
63
+ const { client } = await createE2EDatabase('bun', E2EPostgresClient)
64
+ pgClient = client
8
65
  }, 60000)
9
66
 
10
67
  afterAll(async () => {
11
- await dropE2EDatabase(schemaId)
68
+ await pgClient.dropDatabase()
12
69
  })