Skip to content

Commit 8c4c3c3

Browse files
committed
fix integration tests due to jest 30 update
1 parent fb0204d commit 8c4c3c3

File tree

5 files changed

+73
-32
lines changed

5 files changed

+73
-32
lines changed

docker-compose.test.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "3.4"
21
services:
32
api:
43
build:
@@ -16,7 +15,6 @@ services:
1615
- mongodb
1716
- rabbitmq
1817
- keycloak
19-
# - accounting
2018
stdin_open: true
2119
tty: true
2220

@@ -65,7 +63,7 @@ services:
6563
retries: 5
6664

6765
keycloak:
68-
image: quay.io/keycloak/keycloak:23.0
66+
image: quay.io/keycloak/keycloak:22.0
6967
environment:
7068
- KEYCLOAK_ADMIN=admin
7169
- KEYCLOAK_ADMIN_PASSWORD=admin
@@ -74,18 +72,21 @@ services:
7472
- KC_HOSTNAME_STRICT_HTTPS=false
7573
- KC_HTTP_ENABLED=true
7674
- KC_HEALTH_ENABLED=true
75+
- JAVA_OPTS_APPEND=-Djava.io.tmpdir=/opt/keycloak/data/tmp
7776
ports:
7877
- 8180:8180
7978
command:
8079
- start-dev
8180
volumes:
8281
- keycloak-test-data:/opt/keycloak/data
83-
- ./test/integration/keycloak:/opt/keycloak/config
82+
tmpfs:
83+
- /tmp:size=128M
8484
healthcheck:
85-
test: ["CMD-SHELL", "exec 3<>/dev/tcp/127.0.0.1/8180;echo -e 'GET /health/ready HTTP/1.1\r\nhost: http://localhost\r\nConnection: close\r\n\r\n' >&3;if [ $? -eq 0 ]; then echo 'Healthcheck Successful';exit 0;else echo 'Healthcheck Failed';exit 1;fi;"]
85+
test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/8180 && echo -e 'GET /health/ready HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n' >&3 && cat <&3 | grep -q '200 OK'"]
8686
interval: 10s
87-
timeout: 5s
88-
retries: 10
87+
timeout: 10s
88+
retries: 15
89+
start_period: 60s
8990

9091
# accounting:
9192
# image: codexteamuser/codex-accounting:prod

test/integration/api.env

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,17 @@ UPLOAD_DIR=uploads
8888

8989
## Hawk Catcher token from hawk.so
9090
HAWK_CATCHER_TOKEN=
91+
92+
# Id of GitHub app
93+
GITHUB_APP_ID=2000000
94+
95+
# GitHub App slug/name. Used to generate installation URLs
96+
GITHUB_APP_SLUG=hawk-test-app
97+
98+
# Private key generated in GitHub app settings
99+
GITHUB_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
100+
MYKEY==
101+
-----END RSA PRIVATE KEY-----"
102+
103+
GITHUB_APP_CLIENT_ID=Ivvv3333vvv3333vv
104+
GITHUB_APP_CLIENT_SECRET=02da32efc3223defc32ede30192c03020d023d03e

test/integration/jestEnv.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const NodeEnvironment = require('jest-environment-node');
1+
const { TestEnvironment } = require('jest-environment-node');
22
const amqp = require('amqplib');
33
const mongodb = require('mongodb');
44
const { installRedisMock, uninstallRedisMock } = require('./redisMock');
55

66
/**
77
* Custom test environment for defining global connections
88
*/
9-
class CustomEnvironment extends NodeEnvironment {
9+
class CustomEnvironment extends TestEnvironment {
1010
/**
1111
* Setup environment
1212
* @return {Promise<void>}

test/integration/keycloak/setup.sh

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,44 @@ if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
4343
exit 1
4444
fi
4545

46-
# Get admin token
46+
# Additional wait for admin user to be fully initialized
47+
echo "⏳ Waiting for admin user to be ready..."
48+
sleep 3
49+
50+
# Get admin token with retries
4751
echo "🔑 Obtaining admin token..."
48-
TOKEN_RESPONSE=$(curl -s -X POST "$KEYCLOAK_URL/realms/master/protocol/openid-connect/token" \
49-
-H "Content-Type: application/x-www-form-urlencoded" \
50-
-d "username=$ADMIN_USER" \
51-
-d "password=$ADMIN_PASSWORD" \
52-
-d "grant_type=password" \
53-
-d "client_id=admin-cli")
52+
TOKEN_RETRIES=10
53+
TOKEN_RETRY_COUNT=0
54+
ACCESS_TOKEN=""
55+
56+
while [ $TOKEN_RETRY_COUNT -lt $TOKEN_RETRIES ]; do
57+
TOKEN_RESPONSE=$(curl -s -X POST "$KEYCLOAK_URL/realms/master/protocol/openid-connect/token" \
58+
-H "Content-Type: application/x-www-form-urlencoded" \
59+
-d "username=$ADMIN_USER" \
60+
-d "password=$ADMIN_PASSWORD" \
61+
-d "grant_type=password" \
62+
-d "client_id=admin-cli")
63+
64+
ACCESS_TOKEN=$(echo "$TOKEN_RESPONSE" | grep -o '"access_token":"[^"]*' | cut -d'"' -f4)
65+
66+
if [ -n "$ACCESS_TOKEN" ]; then
67+
echo "✓ Admin token obtained"
68+
break
69+
fi
5470

55-
ACCESS_TOKEN=$(echo "$TOKEN_RESPONSE" | grep -o '"access_token":"[^"]*' | cut -d'"' -f4)
71+
TOKEN_RETRY_COUNT=$((TOKEN_RETRY_COUNT + 1))
72+
if [ $TOKEN_RETRY_COUNT -lt $TOKEN_RETRIES ]; then
73+
echo "Retrying token request... ($TOKEN_RETRY_COUNT/$TOKEN_RETRIES)"
74+
sleep 2
75+
fi
76+
done
5677

5778
if [ -z "$ACCESS_TOKEN" ]; then
58-
echo "❌ Failed to obtain admin token"
79+
echo "❌ Failed to obtain admin token after $TOKEN_RETRIES attempts"
5980
echo "Response: $TOKEN_RESPONSE"
6081
exit 1
6182
fi
6283

63-
echo "✓ Admin token obtained"
64-
6584
# Check if realm already exists
6685
echo "🔍 Checking if realm '$REALM_NAME' exists..."
6786
REALM_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" "$KEYCLOAK_URL/admin/realms/$REALM_NAME" \

test/integration/types/global.d.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-var */
12
/* eslint-disable @typescript-eslint/no-unused-vars */
23
import type { MongoClient } from 'mongodb';
34
import { Channel } from 'amqplib';
@@ -6,17 +7,23 @@ import { Channel } from 'amqplib';
67
* Defines global variables for using in tests
78
*/
89
declare global {
9-
namespace NodeJS {
10-
interface Global {
11-
/**
12-
* MongoDB client instance
13-
*/
14-
mongoClient: MongoClient;
10+
/**
11+
* MongoDB client instance
12+
*/
13+
var mongoClient: MongoClient;
1514

16-
/**
17-
* RabbitMQ client instance
18-
*/
19-
rabbitChannel: Channel;
20-
}
21-
}
15+
/**
16+
* RabbitMQ channel instance
17+
*/
18+
var rabbitChannel: Channel;
19+
20+
/**
21+
* Redis client instance (mock)
22+
*/
23+
var redisClient: unknown;
24+
25+
/**
26+
* Performance API for MongoDB driver
27+
*/
28+
var performance: Performance;
2229
}

0 commit comments

Comments
 (0)