Skip to content

Commit cb0b099

Browse files
committed
ci: Setup e2e test
1 parent 73ce9d8 commit cb0b099

File tree

17 files changed

+218
-125
lines changed

17 files changed

+218
-125
lines changed

.e2e.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DB_HOST=localhost
2+
DB_LOGGING=0
3+
4+
DB_USERNAME="postgres"
5+
DB_PASSWORD="postgres"
6+
DB_NAME="json-api-db"
7+
DB_PORT=5432
8+
DB_TYPE=postgres

.env

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
DB_HOST=localhost
2+
DB_LOGGING=1
3+
4+
DB_USERNAME="postgres"
5+
DB_PASSWORD="postgres"
6+
DB_NAME="json-api-db"
7+
DB_PORT=5432
8+
DB_TYPE=postgres
9+
10+
#DB_USERNAME="root"
11+
#DB_PASSWORD="password"
12+
#DB_NAME="example_new"
13+
#DB_PORT=3306
14+
#DB_TYPE=mysql

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,32 @@ jobs:
2929
key: ${{ runner.os }}-npm-dependencies-${{ hashFiles('package-lock.json') }}
3030
# - run: npm nx affected -t e2e-ci --parallel=1
3131
# - run: npm nx affected -t deploy --no-agents
32+
run-e2e-test:
33+
runs-on: ubuntu-latest
34+
needs:
35+
- run-test
36+
services:
37+
# Label used to access the service container
38+
postgres:
39+
# Docker Hub image
40+
image: postgres
41+
# Provide the password for postgres
42+
env:
43+
POSTGRES_PASSWORD: postgres
44+
# Set health checks to wait until postgres has started
45+
options: >-
46+
--health-cmd pg_isready
47+
--health-interval 10s
48+
--health-timeout 5s
49+
--health-retries 5
50+
ports:
51+
# Maps tcp port 5432 on service container to the host
52+
- 5432:5432
53+
steps:
54+
- uses: actions/checkout@v4
55+
with:
56+
fetch-depth: 0
57+
- name: Npm install
58+
uses: ./.github/actions
59+
- run: git branch --track main origin/master
60+
- run: npm run typeorm migration:run

apps/json-api-server-e2e/jest.config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ export default {
66
globalTeardown: '<rootDir>/src/support/global-teardown.ts',
77
setupFiles: ['<rootDir>/src/support/test-setup.ts'],
88
testEnvironment: 'node',
9+
maxWorkers: 1,
910
transform: {
10-
'^.+\\.[tj]s$': ['ts-jest', {
11-
tsconfig: '<rootDir>/tsconfig.spec.json',
12-
}],
11+
'^.+\\.[tj]s$': [
12+
'ts-jest',
13+
{
14+
tsconfig: '<rootDir>/tsconfig.spec.json',
15+
},
16+
],
1317
},
1418
moduleFileExtensions: ['ts', 'js', 'html'],
1519
coverageDirectory: '../../coverage/json-api-server-e2e',

apps/json-api-server-e2e/src/json-api/json-api-sdk/atomic-sdk.spec.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import {
2-
adapterForAxios,
3-
FilterOperand,
4-
JsonApiJs,
5-
JsonSdkPromise,
6-
} from 'json-api-nestjs-sdk';
7-
import axios from 'axios';
1+
import { INestApplication } from '@nestjs/common';
2+
import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk';
83
import { Addresses, CommentKind, Comments, Roles, Users } from 'database';
94
import { faker } from '@faker-js/faker';
105
import { getUser } from '../utils/data-utils';
6+
import { run, creatSdk } from '../utils/run-ppplication';
7+
8+
let app: INestApplication;
9+
10+
beforeAll(async () => {
11+
app = await run();
12+
});
13+
14+
afterAll(async () => {
15+
await app.close();
16+
});
1117

1218
describe('Atomic method:', () => {
1319
let jsonSdk: JsonSdkPromise;
@@ -16,18 +22,7 @@ describe('Atomic method:', () => {
1622
let commentsArray: Comments[];
1723
let usersId: number[];
1824
beforeEach(async () => {
19-
const axiosAdapter = adapterForAxios(axios);
20-
21-
jsonSdk = JsonApiJs(
22-
{
23-
adapter: axiosAdapter,
24-
apiHost: 'http://localhost:3000',
25-
apiPrefix: 'api',
26-
dateFields: ['createdAt', 'updatedAt'],
27-
operationUrl: 'operation',
28-
},
29-
true
30-
);
25+
jsonSdk = creatSdk();
3126

3227
const addressesPromise = Array.from(new Array(2)).map(() => {
3328
const address = new Addresses();

apps/json-api-server-e2e/src/json-api/json-api-sdk/check-common-decorator.spec.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
import {
2-
adapterForAxios,
3-
FilterOperand,
4-
JsonApiJs,
5-
JsonSdkPromise,
6-
} from 'json-api-nestjs-sdk';
7-
import axios, { AxiosError } from 'axios';
1+
import { INestApplication } from '@nestjs/common';
2+
import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk';
3+
import { AxiosError } from 'axios';
84
import { Users } from 'database';
95

6+
import { run, creatSdk } from '../utils/run-ppplication';
7+
8+
let app: INestApplication;
9+
10+
beforeAll(async () => {
11+
app = await run();
12+
});
13+
14+
afterAll(async () => {
15+
await app.close();
16+
});
17+
1018
describe('Check common decorator', () => {
1119
let jsonSdk: JsonSdkPromise;
12-
const axiosAdapter = adapterForAxios(axios);
1320
beforeEach(async () => {
14-
jsonSdk = JsonApiJs(
15-
{
16-
adapter: axiosAdapter,
17-
apiHost: 'http://localhost:3000',
18-
apiPrefix: 'api',
19-
dateFields: ['createdAt', 'updatedAt'],
20-
operationUrl: 'operation',
21-
idIsNumber: false,
22-
},
23-
true
24-
);
21+
jsonSdk = creatSdk();
2522
});
2623

2724
afterEach(async () => {});

apps/json-api-server-e2e/src/json-api/json-api-sdk/check-othe-call.spec.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
import {
2-
adapterForAxios,
3-
FilterOperand,
4-
JsonApiJs,
5-
JsonSdkPromise,
6-
} from 'json-api-nestjs-sdk';
1+
import { INestApplication } from '@nestjs/common';
2+
import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk';
73
import { BookList, Users } from 'database';
8-
import axios, { AxiosError } from 'axios';
4+
import { AxiosError } from 'axios';
95
import { faker } from '@faker-js/faker';
106
import { lastValueFrom } from 'rxjs';
7+
import { creatSdk, run, axiosAdapter } from '../utils/run-ppplication';
8+
9+
let app: INestApplication;
10+
11+
beforeAll(async () => {
12+
app = await run();
13+
});
14+
15+
afterAll(async () => {
16+
await app.close();
17+
});
1118

1219
describe('Other call type:', () => {
1320
let jsonSdk: JsonSdkPromise;
14-
const axiosAdapter = adapterForAxios(axios);
21+
1522
beforeEach(async () => {
16-
jsonSdk = JsonApiJs(
17-
{
18-
adapter: axiosAdapter,
19-
apiHost: 'http://localhost:3000',
20-
apiPrefix: 'api',
21-
dateFields: ['createdAt', 'updatedAt'],
22-
operationUrl: 'operation',
23-
idIsNumber: false,
24-
},
25-
true
26-
);
23+
jsonSdk = creatSdk({
24+
idIsNumber: false,
25+
});
2726
});
2827

2928
afterEach(async () => {});
@@ -52,7 +51,6 @@ describe('Other call type:', () => {
5251
jsonSdk.jsonApiUtilsService.convertResponseData(newBookSource);
5352

5453
expect(newBook.id).toBeDefined();
55-
5654
const bookResultSource = await lastValueFrom(
5755
axiosAdapter.get<BookList>(`${url}/${newBook.id}`)
5856
);

apps/json-api-server-e2e/src/json-api/json-api-sdk/get-method.spec.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
import { INestApplication } from '@nestjs/common';
12
import { Addresses, CommentKind, Comments, Roles, Users } from 'database';
23
import { faker } from '@faker-js/faker';
34

4-
import {
5-
adapterForAxios,
6-
FilterOperand,
7-
JsonApiJs,
8-
JsonSdkPromise,
9-
} from 'json-api-nestjs-sdk';
10-
import axios from 'axios';
5+
import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk';
116
import { getUser } from '../utils/data-utils';
7+
import { creatSdk, run } from '../utils/run-ppplication';
8+
9+
let app: INestApplication;
10+
11+
beforeAll(async () => {
12+
app = await run();
13+
});
14+
15+
afterAll(async () => {
16+
await app.close();
17+
});
1218

1319
describe('GET method:', () => {
1420
let jsonSdk: JsonSdkPromise;
@@ -18,17 +24,7 @@ describe('GET method:', () => {
1824
let commentsArray: Comments[];
1925

2026
beforeAll(async () => {
21-
const axiosAdapter = adapterForAxios(axios);
22-
23-
jsonSdk = JsonApiJs(
24-
{
25-
adapter: axiosAdapter,
26-
apiHost: 'http://localhost:3000',
27-
apiPrefix: 'api',
28-
dateFields: ['createdAt', 'updatedAt'],
29-
},
30-
true
31-
);
27+
jsonSdk = creatSdk();
3228

3329
const addressesPromise = Array.from(new Array(2)).map(() => {
3430
const address = new Addresses();

apps/json-api-server-e2e/src/json-api/json-api-sdk/patch-methode.spec.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
import { INestApplication } from '@nestjs/common';
12
import { Addresses, CommentKind, Comments, Users } from 'database';
23
import { faker } from '@faker-js/faker';
3-
import {
4-
adapterForAxios,
5-
JsonApiJs,
6-
JsonSdkPromise,
7-
} from 'json-api-nestjs-sdk';
8-
import axios from 'axios';
4+
import { JsonSdkPromise } from 'json-api-nestjs-sdk';
5+
6+
import { creatSdk, run } from '../utils/run-ppplication';
7+
8+
let app: INestApplication;
9+
10+
beforeAll(async () => {
11+
app = await run();
12+
});
13+
14+
afterAll(async () => {
15+
await app.close();
16+
});
917

1018
describe('PATCH method:', () => {
1119
let jsonSdk: JsonSdkPromise;
@@ -19,17 +27,7 @@ describe('PATCH method:', () => {
1927
let newCommentsAfterSave: Comments;
2028

2129
beforeEach(async () => {
22-
const axiosAdapter = adapterForAxios(axios);
23-
24-
jsonSdk = JsonApiJs(
25-
{
26-
adapter: axiosAdapter,
27-
apiHost: 'http://localhost:3000',
28-
apiPrefix: 'api',
29-
dateFields: ['createdAt', 'updatedAt'],
30-
},
31-
true
32-
);
30+
jsonSdk = creatSdk();
3331

3432
address = new Addresses();
3533
address.city = faker.string.alpha(50);

apps/json-api-server-e2e/src/json-api/json-api-sdk/post-method.spec.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { Addresses, BookList, CommentKind, Comments, Users } from 'database';
22
import { faker } from '@faker-js/faker';
3-
import {
4-
adapterForAxios,
5-
JsonApiJs,
6-
JsonSdkPromise,
7-
} from 'json-api-nestjs-sdk';
8-
import axios from 'axios';
3+
import { JsonSdkPromise } from 'json-api-nestjs-sdk';
4+
5+
import { creatSdk, run } from '../utils/run-ppplication';
6+
import { INestApplication } from '@nestjs/common';
7+
let app: INestApplication;
8+
9+
beforeAll(async () => {
10+
app = await run();
11+
});
12+
13+
afterAll(async () => {
14+
await app.close();
15+
});
916

1017
describe('POST method:', () => {
1118
let jsonSdk: JsonSdkPromise;
@@ -18,17 +25,7 @@ describe('POST method:', () => {
1825
let commentsAfterSave: Comments;
1926

2027
beforeEach(() => {
21-
const axiosAdapter = adapterForAxios(axios);
22-
23-
jsonSdk = JsonApiJs(
24-
{
25-
adapter: axiosAdapter,
26-
apiHost: 'http://localhost:3000',
27-
apiPrefix: 'api',
28-
dateFields: ['createdAt', 'updatedAt'],
29-
},
30-
true
31-
);
28+
jsonSdk = creatSdk();
3229

3330
address = new Addresses();
3431
address.city = faker.string.alpha(50);

0 commit comments

Comments
 (0)