nest-knexjs 0.0.14 → 0.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/.github/workflows/nodejs-environment.yml +30 -1
- package/dist/common/knex.utils.d.ts +1 -1
- package/dist/common/knex.utils.js +2 -2
- package/package.json +21 -24
- package/tests/docker-compose.yml +13 -0
- package/tests/{user.e2e-spec.ts → e2e/knex-app-user.spec.ts} +23 -39
- package/tests/e2e/knex-async-class.spec.ts +35 -0
- package/tests/e2e/knex-async-existing.spec.ts +35 -0
- package/tests/e2e/knex-async.spec.ts +35 -0
- package/tests/e2e/knex.spec.ts +35 -0
- package/tests/jest-e2e.json +2 -2
- package/tests/src/app-async.module.ts +8 -0
- package/tests/src/app.module.ts +28 -0
- package/tests/{app-knex → src/apps/app-knex}/app/app.module.ts +2 -2
- package/tests/{app-knex → src/apps/app-knex}/app/users/users.service.ts +1 -1
- package/tests/{app-knex → src/apps/app-knex}/docker-compose.yml +1 -1
- package/tests/{app-multi-database → src/apps/app-multi-database}/app/users/users.service.ts +1 -1
- package/tests/src/async-class-options.module.ts +54 -0
- package/tests/src/async-existing-options.module.ts +62 -0
- package/tests/src/database.module.ts +58 -0
- package/tags +0 -19
- package/tests/app-knex/app/users/users.service.spec.ts +0 -18
- package/tests/app-multi-database/app/post/post.service.spec.ts +0 -18
- package/tests/app-multi-database/app/users/users.service.spec.ts +0 -18
- package/tests/posts.e2e-spec.ts +0 -130
- package/tests/users.e2e-spec.ts +0 -128
- /package/tests/{app-knex → src/apps/app-knex}/app/main.ts +0 -0
- /package/tests/{app-knex → src/apps/app-knex}/app/users/dto/create-user.dto.ts +0 -0
- /package/tests/{app-knex → src/apps/app-knex}/app/users/dto/update-user.dto.ts +0 -0
- /package/tests/{app-knex → src/apps/app-knex}/app/users/entities/user.entity.ts +0 -0
- /package/tests/{app-knex → src/apps/app-knex}/app/users/users.controller.ts +0 -0
- /package/tests/{app-knex → src/apps/app-knex}/app/users/users.module.ts +0 -0
- /package/tests/{app-knex → src/apps/app-knex}/knexfile.js +0 -0
- /package/tests/{app-knex → src/apps/app-knex}/migrations/20210223224919_api.js +0 -0
- /package/tests/{app-knex → src/apps/app-knex}/seeds/users.js +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/app.module.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/main.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/post/dto/create-post.dto.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/post/dto/update-post.dto.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/post/entities/post.entity.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/post/post.controller.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/post/post.module.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/post/post.service.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/users/dto/create-user.dto.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/users/dto/update-user.dto.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/users/entities/user.entity.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/users/users.controller.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/app/users/users.module.ts +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/docker-compose.yml +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/knexfile.js +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/migrations/posts/20210902093735_posts.js +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/migrations/users/20210808150144_users.js +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/seeds/posts.js +0 -0
- /package/tests/{app-multi-database → src/apps/app-multi-database}/seeds/users.js +0 -0
|
@@ -13,7 +13,7 @@ jobs:
|
|
|
13
13
|
|
|
14
14
|
strategy:
|
|
15
15
|
matrix:
|
|
16
|
-
node-version: [
|
|
16
|
+
node-version: [16.x, 18.x]
|
|
17
17
|
|
|
18
18
|
steps:
|
|
19
19
|
- uses: actions/checkout@v3
|
|
@@ -23,3 +23,32 @@ jobs:
|
|
|
23
23
|
node-version: ${{ matrix.node-version }}
|
|
24
24
|
- run: npm ci
|
|
25
25
|
- run: npm run build --if-present
|
|
26
|
+
|
|
27
|
+
integration-test:
|
|
28
|
+
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
|
|
31
|
+
strategy:
|
|
32
|
+
matrix:
|
|
33
|
+
node-version: [16.x, 18.x]
|
|
34
|
+
needs: [build]
|
|
35
|
+
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v3
|
|
38
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
39
|
+
uses: actions/setup-node@v3
|
|
40
|
+
with:
|
|
41
|
+
node-version: ${{ matrix.node-version }}
|
|
42
|
+
- name: Start Docker-Compose
|
|
43
|
+
run: cd tests && docker-compose up -d
|
|
44
|
+
- name: Install npm
|
|
45
|
+
uses: actions/setup-node@v3
|
|
46
|
+
with:
|
|
47
|
+
node-version: ${{ matrix.node-version }}
|
|
48
|
+
- run: npm install
|
|
49
|
+
- name: Run migrations for test
|
|
50
|
+
run: cd tests/src/apps/app-knex && npx knex migrate:up
|
|
51
|
+
- name: Run tests e2e
|
|
52
|
+
run: npm run test:e2e
|
|
53
|
+
- name: Stop Docker-Compose
|
|
54
|
+
run: cd tests && docker-compose down
|
|
@@ -17,4 +17,4 @@ export declare function getConnectionToken(connection?: KnexModuleOptions | stri
|
|
|
17
17
|
export declare function getConnectionPrefix(connection?: KnexModuleOptions | string): string;
|
|
18
18
|
export declare function handleRetry(retryAttempts?: number, retryDelay?: number): <T>(source: Observable<T>) => Observable<T>;
|
|
19
19
|
export declare function getConnectionName(options: KnexModuleOptions): string;
|
|
20
|
-
export declare const generateString: () =>
|
|
20
|
+
export declare const generateString: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateString = exports.getConnectionName = exports.handleRetry = exports.getConnectionPrefix = exports.getConnectionToken = exports.getModelToken = void 0;
|
|
4
4
|
const knex_constants_1 = require("../knex.constants");
|
|
5
5
|
const operators_1 = require("rxjs/operators");
|
|
6
|
-
const
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
7
|
const common_1 = require("@nestjs/common");
|
|
8
8
|
const circular_dependency_exception_1 = require("../exceptions/circular-dependency.exception");
|
|
9
9
|
const logger = new common_1.Logger('KnexModule');
|
|
@@ -61,5 +61,5 @@ function getConnectionName(options) {
|
|
|
61
61
|
return options && options.name ? options.name : knex_constants_1.DEFAULT_CONNECTION_NAME;
|
|
62
62
|
}
|
|
63
63
|
exports.getConnectionName = getConnectionName;
|
|
64
|
-
const generateString = () => (0,
|
|
64
|
+
const generateString = () => (0, node_crypto_1.randomUUID)();
|
|
65
65
|
exports.generateString = generateString;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nest-knexjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "Knexjs module for Nest framework (node.js) 😻",
|
|
5
5
|
"author": "Tony133",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,41 +12,41 @@
|
|
|
12
12
|
"publish:npm": "npm publish --access public",
|
|
13
13
|
"prepublish:next": "npm run build",
|
|
14
14
|
"publish:next": "npm publish --access public --tag next",
|
|
15
|
-
"test:e2e": "jest --config ./tests/jest-e2e.json --
|
|
15
|
+
"test:e2e": "jest --config ./tests/jest-e2e.json --detectOpenHandles --forceExit",
|
|
16
16
|
"test:e2e:dev": "jest --config ./tests/jest-e2e.json --runInBand --watch",
|
|
17
17
|
"prerelease": "npm run build",
|
|
18
18
|
"release": "release-it",
|
|
19
19
|
"prepare": "husky install"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@commitlint/cli": "17.
|
|
23
|
-
"@commitlint/config-angular": "17.
|
|
24
|
-
"@nestjs/common": "9.
|
|
25
|
-
"@nestjs/core": "9.
|
|
26
|
-
"@nestjs/platform-express": "9.
|
|
27
|
-
"@nestjs/testing": "9.
|
|
22
|
+
"@commitlint/cli": "17.6.3",
|
|
23
|
+
"@commitlint/config-angular": "17.6.3",
|
|
24
|
+
"@nestjs/common": "9.4.2",
|
|
25
|
+
"@nestjs/core": "9.4.2",
|
|
26
|
+
"@nestjs/platform-express": "9.4.2",
|
|
27
|
+
"@nestjs/testing": "9.4.2",
|
|
28
28
|
"@types/express": "4.17.17",
|
|
29
|
-
"@types/jest": "29.
|
|
30
|
-
"@types/node": "
|
|
29
|
+
"@types/jest": "29.5.1",
|
|
30
|
+
"@types/node": "20.2.5",
|
|
31
31
|
"@types/supertest": "2.0.12",
|
|
32
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
33
|
-
"@typescript-eslint/parser": "5.
|
|
34
|
-
"eslint": "8.
|
|
35
|
-
"eslint-config-prettier": "8.
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "5.59.7",
|
|
33
|
+
"@typescript-eslint/parser": "5.59.7",
|
|
34
|
+
"eslint": "8.41.0",
|
|
35
|
+
"eslint-config-prettier": "8.8.0",
|
|
36
36
|
"eslint-plugin-import": "2.27.5",
|
|
37
37
|
"husky": "8.0.3",
|
|
38
|
-
"jest": "29.
|
|
38
|
+
"jest": "29.5.0",
|
|
39
39
|
"knex": "2.4.2",
|
|
40
40
|
"mysql": "2.18.1",
|
|
41
|
-
"prettier": "2.8.
|
|
41
|
+
"prettier": "2.8.8",
|
|
42
42
|
"reflect-metadata": "0.1.13",
|
|
43
|
-
"release-it": "15.
|
|
44
|
-
"rxjs": "7.8.
|
|
43
|
+
"release-it": "15.10.3",
|
|
44
|
+
"rxjs": "7.8.1",
|
|
45
45
|
"supertest": "6.3.3",
|
|
46
|
-
"ts-jest": "29.0
|
|
46
|
+
"ts-jest": "29.1.0",
|
|
47
47
|
"ts-node": "10.9.1",
|
|
48
|
-
"tsconfig-paths": "4.
|
|
49
|
-
"typescript": "
|
|
48
|
+
"tsconfig-paths": "4.2.0",
|
|
49
|
+
"typescript": "5.0.4"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0",
|
|
@@ -61,8 +61,5 @@
|
|
|
61
61
|
"repository": {
|
|
62
62
|
"type": "git",
|
|
63
63
|
"url": "https://github.com/tony133/nestjs-knexjs"
|
|
64
|
-
},
|
|
65
|
-
"dependencies": {
|
|
66
|
-
"uuid": "9.0.0"
|
|
67
64
|
}
|
|
68
65
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { INestApplication, HttpStatus } from '@nestjs/common';
|
|
2
2
|
import { TestingModule, Test } from '@nestjs/testing';
|
|
3
|
-
import { UsersModule } from '
|
|
4
|
-
import { KnexModule } from '
|
|
3
|
+
import { UsersModule } from '../src/apps/app-knex/app/users/users.module';
|
|
4
|
+
import { KnexModule } from '../../lib';
|
|
5
5
|
import * as request from 'supertest';
|
|
6
6
|
|
|
7
|
-
describe('[Feature]
|
|
7
|
+
describe('[Feature] Users - /users', () => {
|
|
8
8
|
let app: INestApplication;
|
|
9
9
|
|
|
10
10
|
beforeAll(async () => {
|
|
@@ -19,7 +19,7 @@ describe('[Feature] User - /user', () => {
|
|
|
19
19
|
connection: {
|
|
20
20
|
host: '127.0.0.1',
|
|
21
21
|
user: 'root',
|
|
22
|
-
port:
|
|
22
|
+
port: 3306,
|
|
23
23
|
password: 'root',
|
|
24
24
|
database: 'test',
|
|
25
25
|
},
|
|
@@ -32,44 +32,29 @@ describe('[Feature] User - /user', () => {
|
|
|
32
32
|
await app.init();
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
it('
|
|
35
|
+
it('should create a new user [POST /users]', () => {
|
|
36
36
|
return request(app.getHttpServer())
|
|
37
|
-
.post('/
|
|
37
|
+
.post('/users')
|
|
38
38
|
.expect(HttpStatus.CREATED)
|
|
39
39
|
.set('Accept', 'application/json')
|
|
40
40
|
.send({
|
|
41
41
|
firstName: 'firstName',
|
|
42
42
|
lastName: 'lastName',
|
|
43
43
|
})
|
|
44
|
-
.then((
|
|
45
|
-
|
|
44
|
+
.then(({ body }) => {
|
|
45
|
+
expect(body).toEqual({ users: [1] });
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
it('
|
|
49
|
+
it('should get all users [GET /users]', () => {
|
|
50
50
|
return request(app.getHttpServer())
|
|
51
|
-
.get('/
|
|
51
|
+
.get('/users')
|
|
52
52
|
.expect(HttpStatus.OK)
|
|
53
53
|
.set('Accept', 'application/json')
|
|
54
54
|
.then(({ body }) => {
|
|
55
55
|
expect(body['users']).toEqual([
|
|
56
56
|
{
|
|
57
57
|
id: 1,
|
|
58
|
-
firstName: 'firstName #1',
|
|
59
|
-
lastName: 'lastName #1',
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
id: 2,
|
|
63
|
-
firstName: 'firstName #1',
|
|
64
|
-
lastName: 'lastName #1',
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
id: 3,
|
|
68
|
-
firstName: 'firstName #1',
|
|
69
|
-
lastName: 'lastName #1',
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
id: 4,
|
|
73
58
|
firstName: 'firstName',
|
|
74
59
|
lastName: 'lastName',
|
|
75
60
|
},
|
|
@@ -77,39 +62,38 @@ describe('[Feature] User - /user', () => {
|
|
|
77
62
|
});
|
|
78
63
|
});
|
|
79
64
|
|
|
80
|
-
it('
|
|
65
|
+
it('should get a user by id [GET /users/:id]', () => {
|
|
81
66
|
return request(app.getHttpServer())
|
|
82
|
-
.get('/
|
|
67
|
+
.get('/users/1')
|
|
83
68
|
.expect(HttpStatus.OK)
|
|
84
69
|
.set('Accept', 'application/json')
|
|
85
70
|
.then(({ body }) => {
|
|
86
71
|
expect(body['users']).toEqual([
|
|
87
72
|
{
|
|
88
|
-
id:
|
|
89
|
-
firstName: 'firstName
|
|
90
|
-
lastName: 'lastName
|
|
73
|
+
id: 1,
|
|
74
|
+
firstName: 'firstName',
|
|
75
|
+
lastName: 'lastName',
|
|
91
76
|
},
|
|
92
77
|
]);
|
|
93
78
|
});
|
|
94
79
|
});
|
|
95
80
|
|
|
96
|
-
it('
|
|
81
|
+
it('should update a user by id [PUT /users/:id]', () => {
|
|
97
82
|
return request(app.getHttpServer())
|
|
98
|
-
.put('/
|
|
83
|
+
.put('/users/1')
|
|
99
84
|
.expect(HttpStatus.OK)
|
|
100
85
|
.send({
|
|
101
|
-
firstName: 'firstName
|
|
102
|
-
lastName: 'lastName
|
|
86
|
+
firstName: 'firstName',
|
|
87
|
+
lastName: 'lastName',
|
|
103
88
|
})
|
|
104
|
-
.then((
|
|
105
|
-
|
|
89
|
+
.then(({ body }) => {
|
|
90
|
+
expect(body).toEqual({ users: 1 });
|
|
106
91
|
});
|
|
107
92
|
});
|
|
108
93
|
|
|
109
|
-
it('
|
|
94
|
+
it('should delete a user by id [DELETE /users/:id]', () => {
|
|
110
95
|
return request(app.getHttpServer())
|
|
111
|
-
.delete('/
|
|
112
|
-
.set('Accept', 'application/json')
|
|
96
|
+
.delete('/users/1')
|
|
113
97
|
.expect(HttpStatus.OK);
|
|
114
98
|
});
|
|
115
99
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { HttpStatus, INestApplication } from '@nestjs/common';
|
|
2
|
+
import { Test } from '@nestjs/testing';
|
|
3
|
+
import { AsyncOptionsClassModule } from '../src/async-class-options.module';
|
|
4
|
+
import * as request from 'supertest';
|
|
5
|
+
|
|
6
|
+
describe('Knex (async configuration)', () => {
|
|
7
|
+
let app: INestApplication;
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
const module = await Test.createTestingModule({
|
|
11
|
+
imports: [AsyncOptionsClassModule],
|
|
12
|
+
}).compile();
|
|
13
|
+
|
|
14
|
+
app = module.createNestApplication();
|
|
15
|
+
await app.init();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it(`should return created entity`, () => {
|
|
19
|
+
return request(app.getHttpServer())
|
|
20
|
+
.post('/users')
|
|
21
|
+
.expect(HttpStatus.CREATED)
|
|
22
|
+
.set('Accept', 'application/json')
|
|
23
|
+
.send({
|
|
24
|
+
firstName: 'firstName',
|
|
25
|
+
lastName: 'lastName',
|
|
26
|
+
})
|
|
27
|
+
.expect(({ body }) => {
|
|
28
|
+
expect(body).toEqual({ users: [body.users[0]] });
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterAll(async () => {
|
|
33
|
+
await app.close();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { HttpStatus, INestApplication } from '@nestjs/common';
|
|
2
|
+
import { Test } from '@nestjs/testing';
|
|
3
|
+
import { AsyncOptionsExistingModule } from '../src/async-existing-options.module';
|
|
4
|
+
import * as request from 'supertest';
|
|
5
|
+
|
|
6
|
+
describe('Knex (async configuration)', () => {
|
|
7
|
+
let app: INestApplication;
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
const module = await Test.createTestingModule({
|
|
11
|
+
imports: [AsyncOptionsExistingModule],
|
|
12
|
+
}).compile();
|
|
13
|
+
|
|
14
|
+
app = module.createNestApplication();
|
|
15
|
+
await app.init();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it(`should return created entity`, () => {
|
|
19
|
+
return request(app.getHttpServer())
|
|
20
|
+
.post('/users')
|
|
21
|
+
.expect(HttpStatus.CREATED)
|
|
22
|
+
.set('Accept', 'application/json')
|
|
23
|
+
.send({
|
|
24
|
+
firstName: 'firstName',
|
|
25
|
+
lastName: 'lastName',
|
|
26
|
+
})
|
|
27
|
+
.expect(({ body }) => {
|
|
28
|
+
expect(body).toEqual({ users: [body.users[0]] });
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterAll(async () => {
|
|
33
|
+
await app.close();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { HttpStatus, INestApplication } from '@nestjs/common';
|
|
2
|
+
import { Test } from '@nestjs/testing';
|
|
3
|
+
import { AsyncApplicationModule } from '../src/app-async.module';
|
|
4
|
+
import * as request from 'supertest';
|
|
5
|
+
|
|
6
|
+
describe('Knex (async configuration)', () => {
|
|
7
|
+
let app: INestApplication;
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
const module = await Test.createTestingModule({
|
|
11
|
+
imports: [AsyncApplicationModule],
|
|
12
|
+
}).compile();
|
|
13
|
+
|
|
14
|
+
app = module.createNestApplication();
|
|
15
|
+
await app.init();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it(`should return created entity`, () => {
|
|
19
|
+
return request(app.getHttpServer())
|
|
20
|
+
.post('/users')
|
|
21
|
+
.expect(HttpStatus.CREATED)
|
|
22
|
+
.set('Accept', 'application/json')
|
|
23
|
+
.send({
|
|
24
|
+
firstName: 'firstName',
|
|
25
|
+
lastName: 'lastName',
|
|
26
|
+
})
|
|
27
|
+
.expect(({ body }) => {
|
|
28
|
+
expect(body).toEqual({ users: [body.users[0]] });
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterAll(async () => {
|
|
33
|
+
await app.close();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { INestApplication } from '@nestjs/common';
|
|
2
|
+
import { Test } from '@nestjs/testing';
|
|
3
|
+
import { ApplicationModule } from '../src/app.module';
|
|
4
|
+
import * as request from 'supertest';
|
|
5
|
+
|
|
6
|
+
describe('Knex', () => {
|
|
7
|
+
let app: INestApplication;
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
const module = await Test.createTestingModule({
|
|
11
|
+
imports: [ApplicationModule],
|
|
12
|
+
}).compile();
|
|
13
|
+
|
|
14
|
+
app = module.createNestApplication();
|
|
15
|
+
await app.init();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it(`should return created entity`, () => {
|
|
19
|
+
return request(app.getHttpServer())
|
|
20
|
+
.post('/users')
|
|
21
|
+
.expect(201)
|
|
22
|
+
.set('Accept', 'application/json')
|
|
23
|
+
.send({
|
|
24
|
+
firstName: 'firstName',
|
|
25
|
+
lastName: 'lastName',
|
|
26
|
+
})
|
|
27
|
+
.expect(({ body }) => {
|
|
28
|
+
expect(body).toEqual({ users: [body.users[0]] });
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterAll(async () => {
|
|
33
|
+
await app.close();
|
|
34
|
+
});
|
|
35
|
+
});
|
package/tests/jest-e2e.json
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { AppModule } from './apps/app-knex/app/app.module';
|
|
3
|
+
import { DatabaseModule } from './database.module';
|
|
4
|
+
|
|
5
|
+
@Module({
|
|
6
|
+
imports: [DatabaseModule.forRoot(), AppModule],
|
|
7
|
+
})
|
|
8
|
+
export class AsyncApplicationModule {}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { KnexModule } from '../../lib';
|
|
3
|
+
import { UsersModule } from './apps/app-knex/app/users/users.module';
|
|
4
|
+
|
|
5
|
+
@Module({
|
|
6
|
+
imports: [
|
|
7
|
+
KnexModule.forRoot({
|
|
8
|
+
config: {
|
|
9
|
+
client: 'mysql',
|
|
10
|
+
version: '5.7',
|
|
11
|
+
useNullAsDefault: true,
|
|
12
|
+
connection: {
|
|
13
|
+
host: '127.0.0.1',
|
|
14
|
+
user: 'root',
|
|
15
|
+
port: 3306,
|
|
16
|
+
password: 'root',
|
|
17
|
+
database: 'test',
|
|
18
|
+
},
|
|
19
|
+
pool: {
|
|
20
|
+
min: 2,
|
|
21
|
+
max: 10,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
UsersModule,
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
export class ApplicationModule {}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Module } from '@nestjs/common';
|
|
2
|
-
import { KnexModule } from '
|
|
2
|
+
import { KnexModule } from '../../../../../lib';
|
|
3
3
|
import { UsersModule } from './users/users.module';
|
|
4
4
|
|
|
5
5
|
@Module({
|
|
@@ -11,7 +11,7 @@ import { UsersModule } from './users/users.module';
|
|
|
11
11
|
useNullAsDefault: true,
|
|
12
12
|
connection: {
|
|
13
13
|
host: '127.0.0.1',
|
|
14
|
-
port:
|
|
14
|
+
port: 3306,
|
|
15
15
|
user: 'root',
|
|
16
16
|
password: 'root',
|
|
17
17
|
database: 'test',
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
NotFoundException,
|
|
6
6
|
} from '@nestjs/common';
|
|
7
7
|
import { Knex } from 'knex';
|
|
8
|
-
import { InjectModel } from '
|
|
8
|
+
import { InjectModel } from '../../../../../../lib';
|
|
9
9
|
import { CreateUserDto } from './dto/create-user.dto';
|
|
10
10
|
import { UpdateUserDto } from './dto/update-user.dto';
|
|
11
11
|
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
NotFoundException,
|
|
6
6
|
} from '@nestjs/common';
|
|
7
7
|
import { Knex } from 'knex';
|
|
8
|
-
import { InjectConnection } from '
|
|
8
|
+
import { InjectConnection } from '../../../../../../lib';
|
|
9
9
|
import { CreateUserDto } from './dto/create-user.dto';
|
|
10
10
|
import { UpdateUserDto } from './dto/update-user.dto';
|
|
11
11
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { KnexOptionsFactory, KnexModuleOptions, KnexModule } from '../../lib';
|
|
3
|
+
import { UsersModule } from './apps/app-knex/app/users/users.module';
|
|
4
|
+
|
|
5
|
+
class ConfigService implements KnexOptionsFactory {
|
|
6
|
+
createKnexOptions(): KnexModuleOptions {
|
|
7
|
+
return {
|
|
8
|
+
config: {
|
|
9
|
+
client: 'mysql',
|
|
10
|
+
version: '5.7',
|
|
11
|
+
useNullAsDefault: true,
|
|
12
|
+
connection: {
|
|
13
|
+
host: '127.0.0.1',
|
|
14
|
+
user: 'root',
|
|
15
|
+
port: 3306,
|
|
16
|
+
password: 'root',
|
|
17
|
+
database: 'test',
|
|
18
|
+
},
|
|
19
|
+
pool: {
|
|
20
|
+
min: 2,
|
|
21
|
+
max: 10,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Module({
|
|
29
|
+
imports: [
|
|
30
|
+
KnexModule.forRootAsync({
|
|
31
|
+
useClass: ConfigService,
|
|
32
|
+
}),
|
|
33
|
+
KnexModule.forRoot({
|
|
34
|
+
config: {
|
|
35
|
+
client: 'mysql',
|
|
36
|
+
version: '5.7',
|
|
37
|
+
useNullAsDefault: true,
|
|
38
|
+
connection: {
|
|
39
|
+
host: '127.0.0.1',
|
|
40
|
+
user: 'root',
|
|
41
|
+
port: 3306,
|
|
42
|
+
password: 'root',
|
|
43
|
+
database: 'test',
|
|
44
|
+
},
|
|
45
|
+
pool: {
|
|
46
|
+
min: 2,
|
|
47
|
+
max: 10,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
UsersModule,
|
|
52
|
+
],
|
|
53
|
+
})
|
|
54
|
+
export class AsyncOptionsClassModule {}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { UsersModule } from '../src/apps/app-knex/app/users/users.module';
|
|
3
|
+
import { KnexModule } from '../../lib/knex.module';
|
|
4
|
+
import { KnexModuleOptions, KnexOptionsFactory } from '../../lib';
|
|
5
|
+
|
|
6
|
+
class ConfigService implements KnexOptionsFactory {
|
|
7
|
+
createKnexOptions(): KnexModuleOptions {
|
|
8
|
+
return {
|
|
9
|
+
config: {
|
|
10
|
+
client: 'mysql',
|
|
11
|
+
version: '5.7',
|
|
12
|
+
useNullAsDefault: true,
|
|
13
|
+
connection: {
|
|
14
|
+
host: '127.0.0.1',
|
|
15
|
+
user: 'root',
|
|
16
|
+
port: 3306,
|
|
17
|
+
password: 'root',
|
|
18
|
+
database: 'test',
|
|
19
|
+
},
|
|
20
|
+
pool: {
|
|
21
|
+
min: 2,
|
|
22
|
+
max: 10,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Module({
|
|
30
|
+
providers: [ConfigService],
|
|
31
|
+
exports: [ConfigService],
|
|
32
|
+
})
|
|
33
|
+
class ConfigModule {}
|
|
34
|
+
|
|
35
|
+
@Module({
|
|
36
|
+
imports: [
|
|
37
|
+
KnexModule.forRootAsync({
|
|
38
|
+
imports: [ConfigModule],
|
|
39
|
+
useExisting: ConfigService,
|
|
40
|
+
}),
|
|
41
|
+
KnexModule.forRoot({
|
|
42
|
+
config: {
|
|
43
|
+
client: 'mysql',
|
|
44
|
+
version: '5.7',
|
|
45
|
+
useNullAsDefault: true,
|
|
46
|
+
connection: {
|
|
47
|
+
host: '127.0.0.1',
|
|
48
|
+
user: 'root',
|
|
49
|
+
port: 3306,
|
|
50
|
+
password: 'root',
|
|
51
|
+
database: 'test',
|
|
52
|
+
},
|
|
53
|
+
pool: {
|
|
54
|
+
min: 2,
|
|
55
|
+
max: 10,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
UsersModule,
|
|
60
|
+
],
|
|
61
|
+
})
|
|
62
|
+
export class AsyncOptionsExistingModule {}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DynamicModule, Module } from '@nestjs/common';
|
|
2
|
+
import { KnexModule } from '../../lib';
|
|
3
|
+
|
|
4
|
+
@Module({})
|
|
5
|
+
export class DatabaseModule {
|
|
6
|
+
static async forRoot(): Promise<DynamicModule> {
|
|
7
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
8
|
+
return {
|
|
9
|
+
module: DatabaseModule,
|
|
10
|
+
imports: [
|
|
11
|
+
KnexModule.forRoot(
|
|
12
|
+
{
|
|
13
|
+
name: 'db1Connection',
|
|
14
|
+
config: {
|
|
15
|
+
client: 'mysql',
|
|
16
|
+
version: '5.7',
|
|
17
|
+
useNullAsDefault: true,
|
|
18
|
+
connection: {
|
|
19
|
+
host: '127.0.0.1',
|
|
20
|
+
user: 'root',
|
|
21
|
+
port: 3306,
|
|
22
|
+
password: 'root',
|
|
23
|
+
database: 'test',
|
|
24
|
+
},
|
|
25
|
+
pool: {
|
|
26
|
+
min: 2,
|
|
27
|
+
max: 10,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
'db1Connection',
|
|
32
|
+
),
|
|
33
|
+
KnexModule.forRoot(
|
|
34
|
+
{
|
|
35
|
+
name: 'db2Connection',
|
|
36
|
+
config: {
|
|
37
|
+
client: 'mysql',
|
|
38
|
+
version: '5.7',
|
|
39
|
+
useNullAsDefault: true,
|
|
40
|
+
connection: {
|
|
41
|
+
host: '127.0.0.1',
|
|
42
|
+
user: 'root',
|
|
43
|
+
port: 3306,
|
|
44
|
+
password: 'root',
|
|
45
|
+
database: 'test',
|
|
46
|
+
},
|
|
47
|
+
pool: {
|
|
48
|
+
min: 2,
|
|
49
|
+
max: 10,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
'db2Connection',
|
|
54
|
+
),
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
package/tags
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
|
|
2
|
-
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
|
|
3
|
-
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
|
|
4
|
-
!_TAG_PROGRAM_NAME Exuberant Ctags //
|
|
5
|
-
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
|
|
6
|
-
!_TAG_PROGRAM_VERSION 5.8 //
|
|
7
|
-
exports.down tests/app-knex/migrations/20210223224919_api.js /^exports.down = function (knex) {$/;" f
|
|
8
|
-
exports.down tests/app-multi-database/migrations/posts/20210902093735_posts.js /^exports.down = function (knex) {$/;" f
|
|
9
|
-
exports.down tests/app-multi-database/migrations/users/20210808150144_users.js /^exports.down = function (knex) {$/;" f
|
|
10
|
-
exports.seed tests/app-knex/seeds/users.js /^exports.seed = function (knex) {$/;" f
|
|
11
|
-
exports.seed tests/app-multi-database/seeds/posts.js /^exports.seed = function (knex) {$/;" f
|
|
12
|
-
exports.seed tests/app-multi-database/seeds/users.js /^exports.seed = function (knex) {$/;" f
|
|
13
|
-
exports.up tests/app-knex/migrations/20210223224919_api.js /^exports.up = function (knex) {$/;" f
|
|
14
|
-
exports.up tests/app-multi-database/migrations/posts/20210902093735_posts.js /^exports.up = function (knex) {$/;" f
|
|
15
|
-
exports.up tests/app-multi-database/migrations/users/20210808150144_users.js /^exports.up = function (knex) {$/;" f
|
|
16
|
-
module.exports.development tests/app-knex/knexfile.js /^ development: {$/;" p
|
|
17
|
-
module.exports.development tests/app-multi-database/knexfile.js /^ development: {$/;" p
|
|
18
|
-
module.exports.parser .eslintrc.js /^ parser: '@typescript-eslint\/parser',$/;" p
|
|
19
|
-
module.exports.parserOptions .eslintrc.js /^ parserOptions: {$/;" p
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
-
import { UsersService } from './users.service';
|
|
3
|
-
|
|
4
|
-
describe('UsersService', () => {
|
|
5
|
-
let service: UsersService;
|
|
6
|
-
|
|
7
|
-
beforeEach(async () => {
|
|
8
|
-
const module: TestingModule = await Test.createTestingModule({
|
|
9
|
-
providers: [UsersService],
|
|
10
|
-
}).compile();
|
|
11
|
-
|
|
12
|
-
service = module.get<UsersService>(UsersService);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should be defined', () => {
|
|
16
|
-
expect(service).toBeDefined();
|
|
17
|
-
});
|
|
18
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
-
import { PostService } from './post.service';
|
|
3
|
-
|
|
4
|
-
describe('PostService', () => {
|
|
5
|
-
let service: PostService;
|
|
6
|
-
|
|
7
|
-
beforeEach(async () => {
|
|
8
|
-
const module: TestingModule = await Test.createTestingModule({
|
|
9
|
-
providers: [PostService],
|
|
10
|
-
}).compile();
|
|
11
|
-
|
|
12
|
-
service = module.get<PostService>(PostService);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should be defined', () => {
|
|
16
|
-
expect(service).toBeDefined();
|
|
17
|
-
});
|
|
18
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
-
import { UsersService } from './users.service';
|
|
3
|
-
|
|
4
|
-
describe('UsersService', () => {
|
|
5
|
-
let service: UsersService;
|
|
6
|
-
|
|
7
|
-
beforeEach(async () => {
|
|
8
|
-
const module: TestingModule = await Test.createTestingModule({
|
|
9
|
-
providers: [UsersService],
|
|
10
|
-
}).compile();
|
|
11
|
-
|
|
12
|
-
service = module.get<UsersService>(UsersService);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should be defined', () => {
|
|
16
|
-
expect(service).toBeDefined();
|
|
17
|
-
});
|
|
18
|
-
});
|
package/tests/posts.e2e-spec.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { INestApplication, HttpStatus } from '@nestjs/common';
|
|
2
|
-
import { TestingModule, Test } from '@nestjs/testing';
|
|
3
|
-
import { UsersModule } from './app-multi-database/app/users/users.module';
|
|
4
|
-
import { KnexModule } from '../lib';
|
|
5
|
-
import * as request from 'supertest';
|
|
6
|
-
import { PostModule } from './app-multi-database/app/post/post.module';
|
|
7
|
-
|
|
8
|
-
describe('[Feature] Posts - /posts', () => {
|
|
9
|
-
let app: INestApplication;
|
|
10
|
-
|
|
11
|
-
beforeAll(async () => {
|
|
12
|
-
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
13
|
-
imports: [
|
|
14
|
-
KnexModule.forRootAsync(
|
|
15
|
-
{
|
|
16
|
-
useFactory: () => ({
|
|
17
|
-
config: {
|
|
18
|
-
client: 'mysql',
|
|
19
|
-
version: '5.7',
|
|
20
|
-
useNullAsDefault: true,
|
|
21
|
-
connection: {
|
|
22
|
-
host: '127.0.0.1',
|
|
23
|
-
user: 'root',
|
|
24
|
-
port: 3307,
|
|
25
|
-
password: 'root',
|
|
26
|
-
database: 'test2',
|
|
27
|
-
},
|
|
28
|
-
pool: {
|
|
29
|
-
min: 2,
|
|
30
|
-
max: 10,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
}),
|
|
34
|
-
},
|
|
35
|
-
'db2Connection',
|
|
36
|
-
),
|
|
37
|
-
UsersModule,
|
|
38
|
-
PostModule,
|
|
39
|
-
],
|
|
40
|
-
}).compile();
|
|
41
|
-
|
|
42
|
-
app = moduleFixture.createNestApplication();
|
|
43
|
-
await app.init();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('Create [POST /]', () => {
|
|
47
|
-
return request(app.getHttpServer())
|
|
48
|
-
.post('/posts')
|
|
49
|
-
.expect(HttpStatus.CREATED)
|
|
50
|
-
.set('Accept', 'application/json')
|
|
51
|
-
.send({
|
|
52
|
-
title: 'title #1',
|
|
53
|
-
description: 'description #1',
|
|
54
|
-
})
|
|
55
|
-
.then((res) => {
|
|
56
|
-
res.body;
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('Get all [GET /]', () => {
|
|
61
|
-
return request(app.getHttpServer())
|
|
62
|
-
.get('/posts')
|
|
63
|
-
.expect(HttpStatus.OK)
|
|
64
|
-
.set('Accept', 'application/json')
|
|
65
|
-
.then(({ body }) => {
|
|
66
|
-
expect(body['users']).toEqual([
|
|
67
|
-
{
|
|
68
|
-
id: 1,
|
|
69
|
-
title: 'title #1',
|
|
70
|
-
description: 'description #1',
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
id: 2,
|
|
74
|
-
title: 'title #1',
|
|
75
|
-
description: 'description #1',
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
id: 3,
|
|
79
|
-
title: 'title #1',
|
|
80
|
-
description: 'description #1',
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
id: 4,
|
|
84
|
-
title: 'title #1',
|
|
85
|
-
description: 'description #1',
|
|
86
|
-
},
|
|
87
|
-
]);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('Get one [GET /:id]', () => {
|
|
92
|
-
return request(app.getHttpServer())
|
|
93
|
-
.get('/posts/2')
|
|
94
|
-
.expect(HttpStatus.OK)
|
|
95
|
-
.set('Accept', 'application/json')
|
|
96
|
-
.then(({ body }) => {
|
|
97
|
-
expect(body['users']).toEqual([
|
|
98
|
-
{
|
|
99
|
-
id: 2,
|
|
100
|
-
title: 'title #1',
|
|
101
|
-
description: 'description #1',
|
|
102
|
-
},
|
|
103
|
-
]);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('Update one [PUT /:id]', () => {
|
|
108
|
-
return request(app.getHttpServer())
|
|
109
|
-
.put('/posts/2')
|
|
110
|
-
.expect(HttpStatus.OK)
|
|
111
|
-
.send({
|
|
112
|
-
title: 'title update',
|
|
113
|
-
description: 'description update',
|
|
114
|
-
})
|
|
115
|
-
.then((res) => {
|
|
116
|
-
res.body;
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('Delete one [DELETE /:id]', () => {
|
|
121
|
-
return request(app.getHttpServer())
|
|
122
|
-
.delete('/posts/1')
|
|
123
|
-
.set('Accept', 'application/json')
|
|
124
|
-
.expect(HttpStatus.OK);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
afterAll(async () => {
|
|
128
|
-
await app.close();
|
|
129
|
-
});
|
|
130
|
-
});
|
package/tests/users.e2e-spec.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { INestApplication, HttpStatus } from '@nestjs/common';
|
|
2
|
-
import { TestingModule, Test } from '@nestjs/testing';
|
|
3
|
-
import { UsersModule } from './app-multi-database/app/users/users.module';
|
|
4
|
-
import { KnexModule } from '../lib';
|
|
5
|
-
import * as request from 'supertest';
|
|
6
|
-
|
|
7
|
-
describe('[Feature] Users - /users', () => {
|
|
8
|
-
let app: INestApplication;
|
|
9
|
-
|
|
10
|
-
beforeAll(async () => {
|
|
11
|
-
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
12
|
-
imports: [
|
|
13
|
-
UsersModule,
|
|
14
|
-
KnexModule.forRootAsync(
|
|
15
|
-
{
|
|
16
|
-
useFactory: () => ({
|
|
17
|
-
config: {
|
|
18
|
-
client: 'mysql',
|
|
19
|
-
version: '5.7',
|
|
20
|
-
useNullAsDefault: true,
|
|
21
|
-
connection: {
|
|
22
|
-
host: '127.0.0.1',
|
|
23
|
-
user: 'root',
|
|
24
|
-
port: 3306,
|
|
25
|
-
password: 'root',
|
|
26
|
-
database: 'test1',
|
|
27
|
-
},
|
|
28
|
-
pool: {
|
|
29
|
-
min: 2,
|
|
30
|
-
max: 10,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
}),
|
|
34
|
-
},
|
|
35
|
-
'db1Connection',
|
|
36
|
-
),
|
|
37
|
-
],
|
|
38
|
-
}).compile();
|
|
39
|
-
|
|
40
|
-
app = moduleFixture.createNestApplication();
|
|
41
|
-
await app.init();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('Create [POST /]', () => {
|
|
45
|
-
return request(app.getHttpServer())
|
|
46
|
-
.post('/users')
|
|
47
|
-
.expect(HttpStatus.CREATED)
|
|
48
|
-
.set('Accept', 'application/json')
|
|
49
|
-
.send({
|
|
50
|
-
firstName: 'firstName',
|
|
51
|
-
lastName: 'lastName',
|
|
52
|
-
})
|
|
53
|
-
.then((res) => {
|
|
54
|
-
res.body;
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('Get all [GET /]', () => {
|
|
59
|
-
return request(app.getHttpServer())
|
|
60
|
-
.get('/users')
|
|
61
|
-
.expect(HttpStatus.OK)
|
|
62
|
-
.set('Accept', 'application/json')
|
|
63
|
-
.then(({ body }) => {
|
|
64
|
-
expect(body['users']).toEqual([
|
|
65
|
-
{
|
|
66
|
-
id: 1,
|
|
67
|
-
firstName: 'firstName #1',
|
|
68
|
-
lastName: 'lastName #1',
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
id: 2,
|
|
72
|
-
firstName: 'firstName #1',
|
|
73
|
-
lastName: 'lastName #1',
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
id: 3,
|
|
77
|
-
firstName: 'firstName #1',
|
|
78
|
-
lastName: 'lastName #1',
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
id: 4,
|
|
82
|
-
firstName: 'firstName',
|
|
83
|
-
lastName: 'lastName',
|
|
84
|
-
},
|
|
85
|
-
]);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('Get one [GET /:id]', () => {
|
|
90
|
-
return request(app.getHttpServer())
|
|
91
|
-
.get('/users/2')
|
|
92
|
-
.expect(HttpStatus.OK)
|
|
93
|
-
.set('Accept', 'application/json')
|
|
94
|
-
.then(({ body }) => {
|
|
95
|
-
expect(body['users']).toEqual([
|
|
96
|
-
{
|
|
97
|
-
id: 2,
|
|
98
|
-
firstName: 'firstName #1',
|
|
99
|
-
lastName: 'lastName #1',
|
|
100
|
-
},
|
|
101
|
-
]);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('Update one [PUT /:id]', () => {
|
|
106
|
-
return request(app.getHttpServer())
|
|
107
|
-
.put('/users/2')
|
|
108
|
-
.expect(HttpStatus.OK)
|
|
109
|
-
.send({
|
|
110
|
-
firstName: 'firstName update',
|
|
111
|
-
lastName: 'lastName update',
|
|
112
|
-
})
|
|
113
|
-
.then((res) => {
|
|
114
|
-
res.body;
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('Delete one [DELETE /:id]', () => {
|
|
119
|
-
return request(app.getHttpServer())
|
|
120
|
-
.delete('/users/1')
|
|
121
|
-
.set('Accept', 'application/json')
|
|
122
|
-
.expect(HttpStatus.OK);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
afterAll(async () => {
|
|
126
|
-
await app.close();
|
|
127
|
-
});
|
|
128
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/tests/{app-multi-database → src/apps/app-multi-database}/app/post/dto/create-post.dto.ts
RENAMED
|
File without changes
|
/package/tests/{app-multi-database → src/apps/app-multi-database}/app/post/dto/update-post.dto.ts
RENAMED
|
File without changes
|
/package/tests/{app-multi-database → src/apps/app-multi-database}/app/post/entities/post.entity.ts
RENAMED
|
File without changes
|
/package/tests/{app-multi-database → src/apps/app-multi-database}/app/post/post.controller.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/tests/{app-multi-database → src/apps/app-multi-database}/app/users/dto/create-user.dto.ts
RENAMED
|
File without changes
|
/package/tests/{app-multi-database → src/apps/app-multi-database}/app/users/dto/update-user.dto.ts
RENAMED
|
File without changes
|
/package/tests/{app-multi-database → src/apps/app-multi-database}/app/users/entities/user.entity.ts
RENAMED
|
File without changes
|
/package/tests/{app-multi-database → src/apps/app-multi-database}/app/users/users.controller.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|