Skip to content

Commit

Permalink
Estabilizes tests and also tracks untracked tables
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalenciano committed Feb 20, 2025
1 parent bf9f633 commit 99f9959
Show file tree
Hide file tree
Showing 18 changed files with 232 additions and 268 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ test-output/
*.tap

# Karate reports
tests/target/
target/
tests/results/
24 changes: 10 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# Use a lightweight Linux base image
FROM debian:bullseye-slim
FROM debian:buster-slim

# Set environment variables for non-interactive installations
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && apt-get install -y curl socat
# RUN curl -L -o /usr/local/bin/hasura
RUN curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash
RUN chmod +x /usr/local/bin/hasura

# Install necessary dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app

# Download and install Hasura CLI
RUN curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash
COPY . .

RUN chmod +x ./start.sh

# Set the default command to show Hasura CLI help
CMD ["hasura", "console"]
CMD "./start.sh"
35 changes: 6 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,11 @@ Ensures funds are automatically released based on the terms of the agreement, wi
### **Prerequisites**

0. Install Docker and Docker Compose
1. Download the Hasura global binary. See steps [here](https://hasura.io/docs/2.0/hasura-cli/install-hasura-cli/)
2. Run

```shell

docker compose up -d
```

3. Connect with database. For this run `hasura console` and follow this [guide](https://hasura.io/docs/2.0/databases/quickstart/#on-hasura-deployed-via-docker)

Connect using an environment variable and just type `PG_DATABASE_URL`

Name your database as `safetrust` (instead of default) when prompted to do so.

Now, run the migrations.

```shell
hasura migrate apply --admin-secret myadminsecretkey
bin/dc_prep
bin/dc_console
```

4. Adding migrations.
Expand All @@ -76,18 +63,16 @@ hasura migrate create [enable_postgis] --admin-secret myadminsecretkey

where `enable_postgis` is the name of the migration. Please make sure to use descriptive names with verbs about what the migration is doing!

Then to apply them:

```shell
hasura migrate apply --admin-secret myadminsecretkey
```
Then to apply them, stop the `bin/dc_worker` running with CTRL + C and re-start it again. Migrations are applied when the console runs in docker-compose.

If you wanna use the hasura web console and access it on `http://localhost:9695/`:

```shell
hasura console --admin-secret myadminsecretkey
```

Don't forget to apply the metadata. Migrations and metadata are applied each time you stop the `bin/dc_console` command and run it again.

And you should be good to go to start and work on this.

## 📋 **Known Issues**
Expand Down Expand Up @@ -147,7 +132,7 @@ backend/
To run all tests:

```bash
docker compose -f docker-compose-test.yml up --build --abort-on-container-exit
docker compose -f docker-compose-test.yml run --rm --build karate
```

This command will:
Expand Down Expand Up @@ -179,14 +164,6 @@ After running the tests, you can find the HTML reports at:
- Database config: `docker-compose-test.yml`
- Test environment: `Dockerfile.test`

## Troubleshooting

If tests fail with connection errors:

1. Ensure all containers are running: `docker compose -f docker-compose-test.yml ps`
2. Check container logs: `docker compose -f docker-compose-test.yml logs`
3. Verify network connectivity: `docker network inspect backend_test-network`

## Seeds 🌱

Seeds are files that allow you to create test data in an automated way
Expand Down
4 changes: 4 additions & 0 deletions bin/dc_console
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#!/bin/bash

docker compose up console --build
3 changes: 3 additions & 0 deletions bin/dc_prep
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker compose up -d graphql-engine
4 changes: 2 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: 3
endpoint: http://localhost:8080
endpoint: http://host.docker.internal:8080
admin_secret: myadminsecretkey
metadata_directory: metadata
migrations_directory: migrations
seeds_directory: seeds
actions:
kind: synchronous
handler_webhook_baseurl: http://localhost:3000
handler_webhook_baseurl: http://host.docker.internal:3000
25 changes: 14 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ services:
condition: service_healthy
data-connector-agent:
condition: service_healthy
healthcheck:
test: nc -z localhost 8080
interval: 5s
timeout: 5s
start_period: 10s

data-connector-agent:
image: hasura/graphql-data-connector:v2.42.0
Expand All @@ -47,25 +52,23 @@ services:
timeout: 10s
retries: 5
start_period: 5s

hasura-cli:
console:
build:
context: .
dockerfile: Dockerfile
tty: true
volumes:
- .:/app # Mount your Hasura project directory
environment:
HASURA_GRAPHQL_ENDPOINT: http://graphql-engine:8080
PG_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
working_dir: /app
command: hasura console --address 0.0.0.0 --console-port 9695
ports:
- "9693:9693"
- "9695:9695"
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/app
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET}
HASURA_GRAPHQL_ENDPOINT: http://127.0.0.1:8080
HASURA_RUN_CONSOLE: "true"
volumes:
- .:/usr/src/hasura
depends_on:
graphql-engine:
condition: service_healthy


volumes:
db_data:
14 changes: 14 additions & 0 deletions metadata/databases/safetrust/tables/public_apartments.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
table:
name: apartments
schema: public
configuration:
custom_root_fields: {}
custom_column_names: {}
array_relationships:
- name: users
using:
foreign_key_constraint_on:
column: owner_id
table:
schema: public
name: users
14 changes: 14 additions & 0 deletions metadata/databases/safetrust/tables/public_bid_requests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
table:
schema: public
name: bid_requests
configuration:
custom_root_fields: {}
custom_column_names: {}
array_relationships:
- name: status_histories
using:
foreign_key_constraint_on:
column: bid_request_id
table:
schema: public
name: bid_status_histories
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
table:
schema: public
name: bid_status_histories
object_relationships:
- name: bid_request
using:
foreign_key_constraint_on: bid_request_id
25 changes: 0 additions & 25 deletions metadata/databases/safetrust/tables/public_bid_tables.yaml

This file was deleted.

24 changes: 13 additions & 11 deletions metadata/databases/safetrust/tables/tables.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
- "!include public_geography_columns.yaml"
- "!include public_geometry_columns.yaml"
- "!include public_spatial_ref_sys.yaml"
- "!include public_user_wallets.yaml"
- "!include public_users.yaml"
- "!include escrow_api_calls.yaml"
- "!include escrow_transactions.yaml"
- "!include escrow_xdr_transactions.yaml"
- "!include public_apartments.yaml"
- "!include public_apartment_images.yaml"
- "!include public_bid_tables.yaml"
- '!include public_geography_columns.yaml'
- '!include public_geometry_columns.yaml'
- '!include public_spatial_ref_sys.yaml'
- '!include public_user_wallets.yaml'
- '!include public_users.yaml'
- '!include escrow_api_calls.yaml'
- '!include escrow_transactions.yaml'
- '!include escrow_xdr_transactions.yaml'
- '!include public_apartments.yaml'
- '!include public_apartment_images.yaml'
- '!include public_bid_requests.yaml'
- '!include public_bid_status_histories.yaml'

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ CREATE TRIGGER update_bid_requests_updated_at
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();

-- Función para verificar ofertas activas
CREATE OR REPLACE FUNCTION check_active_bids()
RETURNS TRIGGER AS $$
BEGIN
Expand Down
28 changes: 28 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

HASURA_FOLDER=/app
cd $HASURA_FOLDER || {
echo "Hasura folder '$HASURA_FOLDER' not found"
exit 1
}

# Workaround for https://github.com/hasura/graphql-engine/issues/2824#issuecomment-801293056
socat TCP-LISTEN:8080,fork TCP:graphql-engine:8080 &
socat TCP-LISTEN:9695,fork,reuseaddr,bind=console TCP:127.0.0.1:9695 &
socat TCP-LISTEN:9693,fork,reuseaddr,bind=console TCP:127.0.0.1:9693 &
{
# Apply migrations
hasura migrate apply --database-name=safetrust || exit 1

# Apply metadata changes
hasura metadata apply || exit 1

# Run console if specified
if [[ -v HASURA_RUN_CONSOLE ]]; then
echo "Starting console..."
hasura console --log-level DEBUG --address "127.0.0.1" --no-browser || exit 1
else
echo "Started without console"
tail -f /dev/null
fi
}
Loading

0 comments on commit 99f9959

Please sign in to comment.