File tree Expand file tree Collapse file tree 6 files changed +98
-9
lines changed
src/__tests__/integration Expand file tree Collapse file tree 6 files changed +98
-9
lines changed Original file line number Diff line number Diff line change
1
+ name : CI
2
+
3
+ on :
4
+ push :
5
+ branches :
6
+ - main
7
+ - development
8
+ - stage
9
+ - production
10
+ pull_request :
11
+ branches :
12
+ - main
13
+ - development
14
+ - stage
15
+ - production
16
+
17
+ jobs :
18
+ test :
19
+ runs-on : ubuntu-latest
20
+
21
+ services :
22
+ postgres :
23
+ image : postgres:latest
24
+ env :
25
+ POSTGRES_USER : postgres
26
+ POSTGRES_PASSWORD : postgres
27
+ POSTGRES_DB : postgres
28
+ ports :
29
+ - 5432:5432
30
+ options : >-
31
+ --health-cmd "pg_isready -U postgres"
32
+ --health-interval 10s
33
+ --health-timeout 5s
34
+ --health-retries 5
35
+
36
+ env :
37
+ DATABASE_URL : postgres://postgres:postgres@localhost:5432/testdb
38
+ PGPASSFILE : /home/runner/.pgpass
39
+
40
+ steps :
41
+ - name : Checkout code
42
+ uses : actions/checkout@v2
43
+
44
+ - name : Set up Node.js
45
+ uses : actions/setup-node@v2
46
+ with :
47
+ node-version : ' 22'
48
+
49
+ - name : Create .pgpass file
50
+ run : |
51
+ echo "localhost:5432:postgres:postgres:postgres" > ~/.pgpass &&
52
+ echo "localhost:5432:testdb:postgres:postgres:postgres" >> ~/.pgpass &&
53
+ chmod 0600 ~/.pgpass
54
+
55
+ - name : Create test database
56
+ run : |
57
+ sudo apt-get install -y postgresql-client &&
58
+ psql -h localhost -U postgres -c "CREATE DATABASE testdb;"
59
+
60
+ - name : Install dependencies for backend
61
+ working-directory : ./backend
62
+ run : npm install
63
+
64
+ - name : Run backend tests
65
+ working-directory : ./backend
66
+ run : npm test
67
+
68
+ - name : Install dependencies for frontend
69
+ working-directory : ./frontend
70
+ run : npm install
71
+
72
+ - name : Run frontend tests
73
+ working-directory : ./frontend
74
+ run : npm test
75
+
Original file line number Diff line number Diff line change @@ -8,23 +8,22 @@ export async function seed(knex: Knex): Promise<void> {
8
8
// Deletes ALL existing entries
9
9
await knex ( 'products' ) . del ( ) ;
10
10
11
- const products : Product [ ] = [
11
+ await knex . raw ( 'ALTER SEQUENCE products_id_seq RESTART WITH 1' ) ;
12
+
13
+ const products : Omit < Product , "id" > [ ] = [
12
14
{
13
- id : 1 ,
14
15
name : 'Product 1' ,
15
16
description : 'product 1 description' ,
16
17
price : 100 ,
17
18
status : ProductStatus . AVAILABLE ,
18
19
} ,
19
20
{
20
- id : 2 ,
21
21
name : 'Product 2' ,
22
22
description : 'product 2 description' ,
23
23
price : 200 ,
24
24
status : ProductStatus . AVAILABLE ,
25
25
} ,
26
26
{
27
- id : 3 ,
28
27
name : 'Product 3' ,
29
28
description : 'product 3 description' ,
30
29
price : 300 ,
Original file line number Diff line number Diff line change @@ -5,23 +5,22 @@ export async function seed(knex: Knex): Promise<void> {
5
5
// Deletes ALL existing entries
6
6
await knex ( 'users' ) . del ( ) ;
7
7
8
- const users : User [ ] = [
8
+ await knex . raw ( 'ALTER SEQUENCE users_id_seq RESTART WITH 1' ) ;
9
+
10
+ const users : Omit < User , "id" > [ ] = [
9
11
{
10
- id : 1 ,
11
12
email : 'user1@xyz.com' ,
12
13
first_name : 'User' ,
13
14
last_name : 'One' ,
14
15
status : UserStatus . ACTIVE ,
15
16
} ,
16
17
{
17
- id : 2 ,
18
18
email : 'user2@xyz.com' ,
19
19
first_name : 'User' ,
20
20
last_name : 'Two' ,
21
21
status : UserStatus . ACTIVE ,
22
22
} ,
23
23
{
24
- id : 3 ,
25
24
email : 'user3@xyz.com' ,
26
25
first_name : 'User' ,
27
26
last_name : 'Three' ,
Original file line number Diff line number Diff line change @@ -26,6 +26,14 @@ afterAll(async () => {
26
26
await db . destroy ( ) ;
27
27
} ) ;
28
28
29
+ beforeEach ( async ( ) => {
30
+ await db . raw ( 'BEGIN' )
31
+ } ) ;
32
+
33
+ afterEach ( async ( ) => {
34
+ await db . raw ( 'ROLLBACK' )
35
+ } ) ;
36
+
29
37
describe ( 'GET /products' , ( ) => {
30
38
it ( 'should return a list of products' , async ( ) => {
31
39
const response = await request ( app ) . get ( '/products' ) ;
Original file line number Diff line number Diff line change @@ -23,6 +23,14 @@ afterAll(async () => {
23
23
await db . destroy ( ) ;
24
24
} ) ;
25
25
26
+ beforeEach ( async ( ) => {
27
+ await db . raw ( 'BEGIN' )
28
+ } ) ;
29
+
30
+ afterEach ( async ( ) => {
31
+ await db . raw ( 'ROLLBACK' )
32
+ } ) ;
33
+
26
34
describe ( 'GET /users' , ( ) => {
27
35
it ( 'should return a list of users' , async ( ) => {
28
36
const response = await request ( app ) . get ( '/users' ) ;
Original file line number Diff line number Diff line change 6
6
"start" : " ng serve --host 0.0.0.0 --port 4200" ,
7
7
"build" : " ng build" ,
8
8
"watch" : " ng build --watch --configuration development" ,
9
- "test" : " ng test"
9
+ "test" : " ng test --no-watch "
10
10
},
11
11
"private" : true ,
12
12
"dependencies" : {
You can’t perform that action at this time.
0 commit comments