-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from olisaagbafor/test/karate-setup
Test/karate setup
- Loading branch information
Showing
12 changed files
with
322 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,3 +64,7 @@ bower_components/ | |
# Test output | ||
test-output/ | ||
*.tap | ||
|
||
# Karate reports | ||
tests/target/ | ||
tests/results/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM openjdk:17 | ||
|
||
WORKDIR /app | ||
|
||
# Copy test files | ||
COPY tests /app/tests | ||
|
||
# Make sure karate-config.js is in the right place | ||
RUN mkdir -p /app/tests/karate/src/test/resources | ||
# Create directory for test results | ||
RUN mkdir -p /app/target/karate-reports | ||
|
||
# Set default command | ||
CMD ["java", "-jar", "/app/tests/karate.jar", "--configdir", "/app/tests/karate/src/test/resources", "/app/tests/karate/features"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
services: | ||
postgres_test: | ||
image: postgres:15 | ||
restart: always | ||
environment: | ||
POSTGRES_PASSWORD: postgrespassword | ||
ports: | ||
- "5432:5432" | ||
networks: | ||
- test-network | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready -U postgres"] | ||
interval: 5s | ||
timeout: 5s | ||
retries: 5 | ||
|
||
graphql-engine-test: | ||
image: hasura/graphql-engine:latest | ||
ports: | ||
- "8081:8080" | ||
depends_on: | ||
postgres_test: | ||
condition: service_healthy | ||
environment: | ||
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres_test:5432/postgres | ||
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" | ||
HASURA_GRAPHQL_DEV_MODE: "true" | ||
HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey | ||
HASURA_GRAPHQL_JWT_SECRET: '{"type":"HS256", "key": "12345678901234567890123456789012", "claims_format": "json", "claims_namespace": "https://hasura.io/jwt/claims"}' | ||
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: "anonymous" | ||
HASURA_GRAPHQL_LOG_LEVEL: "debug" | ||
HASURA_GRAPHQL_ENABLED_LOG_TYPES: "startup,http-log,webhook-log,websocket-log,query-log" | ||
ACTION_BASE_URL: http://action-handler:3000 | ||
volumes: | ||
- ./tests/metadata:/hasura-metadata | ||
networks: | ||
- test-network | ||
|
||
karate: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.test | ||
volumes: | ||
- ./tests/results:/app/target/karate-reports | ||
depends_on: | ||
graphql-engine-test: | ||
condition: service_started | ||
networks: | ||
- test-network | ||
|
||
networks: | ||
test-network: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Feature: User Authentication | ||
|
||
Background: | ||
* print '=== Loading feature file ===' | ||
* url baseUrl | ||
* print 'URL set to:', baseUrl | ||
* header x-hasura-admin-secret = adminSecret | ||
|
||
Scenario: Check test database connection | ||
* print 'Starting database check' | ||
Given path '/' | ||
And def query = | ||
""" | ||
{ | ||
"query": "query { __type(name: \"User\") { fields { name type { name kind } } } }" | ||
} | ||
""" | ||
And request query | ||
When method POST | ||
Then status 200 | ||
* print 'Schema:', response.data | ||
|
||
Scenario: Check test environment health | ||
* print 'Starting health check' | ||
Given url baseUrl.replace('/v1/graphql', '/healthz') | ||
When method GET | ||
Then status 200 | ||
* print 'Health response:', response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Feature: Authorization Permissions | ||
|
||
Background: | ||
* url baseUrl | ||
* print '=== Loading feature file ===' | ||
* print 'URL set to:', baseUrl | ||
|
||
Scenario: User can access their own data | ||
* def token = tokenHelper({ uid: 'test-user', role: 'user' }) | ||
* header Authorization = token | ||
* header x-hasura-admin-secret = adminSecret | ||
|
||
Given path '/' | ||
And request { query: "{ __type(name: \"User\") { fields { name } } }" } | ||
When method POST | ||
Then status 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Feature: Create User | ||
|
||
Background: | ||
* url baseUrl | ||
* print '=== Loading feature file ===' | ||
* print 'URL set to:', baseUrl | ||
|
||
Scenario: Check Hasura health | ||
Given path '' | ||
And header x-hasura-admin-secret = adminSecret | ||
And request { query: "query { __typename }" } | ||
When method POST | ||
Then status 200 | ||
And match response == { data: { __typename: 'query_root' } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Feature: Query Users | ||
|
||
Background: | ||
* url baseUrl | ||
* print '=== Loading feature file ===' | ||
* print 'URL set to:', baseUrl | ||
* header x-hasura-admin-secret = adminSecret | ||
|
||
Scenario: Query existing user | ||
Given request { query: "{ __typename }" } | ||
When method POST | ||
Then status 200 | ||
And match response == { data: { __typename: 'query_root' } } | ||
|
||
Scenario: Query non-existing user | ||
Given request { query: "{ __typename }" } | ||
When method POST | ||
Then status 200 | ||
And match response == { data: { __typename: 'query_root' } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Feature: User Wallets | ||
|
||
Background: | ||
* url baseUrl | ||
* print '=== Loading feature file ===' | ||
* print 'URL set to:', baseUrl | ||
|
||
Scenario: Get schema information | ||
Given header Authorization = tokenHelper({ role: 'admin' }) | ||
And header x-hasura-admin-secret = adminSecret | ||
And request | ||
""" | ||
{ | ||
"query": " | ||
query IntrospectionQuery { | ||
__schema { | ||
queryType { | ||
fields { | ||
name | ||
description | ||
} | ||
} | ||
} | ||
} | ||
" | ||
} | ||
""" | ||
When method POST | ||
Then status 200 | ||
And match response.errors == '#notpresent' | ||
* print 'Available queries:', response.data.__schema.queryType.fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
function fn() { | ||
karate.log("=== Starting karate-config.js ==="); | ||
|
||
// Configure pretty logging | ||
karate.configure("logPrettyRequest", true); | ||
karate.configure("logPrettyResponse", true); | ||
|
||
// Basic configuration | ||
var config = { | ||
baseUrl: "http://graphql-engine-test:8080/v1/graphql", | ||
adminSecret: "myadminsecretkey", | ||
}; | ||
|
||
// Token helper function | ||
config.tokenHelper = function (claims) { | ||
var Base64 = Java.type("java.util.Base64"); | ||
var defaultClaims = { | ||
"https://hasura.io/jwt/claims": { | ||
"x-hasura-allowed-roles": ["user"], | ||
"x-hasura-default-role": "user", | ||
"x-hasura-user-id": "00000000-0000-0000-0000-000000000000", | ||
}, | ||
}; | ||
|
||
if (claims && claims.role === "admin") { | ||
defaultClaims["https://hasura.io/jwt/claims"] = { | ||
"x-hasura-allowed-roles": ["user", "admin"], | ||
"x-hasura-default-role": "admin", | ||
"x-hasura-user-id": "admin-user", | ||
}; | ||
} | ||
|
||
var header = { alg: "HS256", typ: "JWT" }; | ||
|
||
// Properly encode each part | ||
var headerBase64 = Base64.getUrlEncoder().withoutPadding().encodeToString(JSON.stringify(header).getBytes("UTF-8")); | ||
var payloadBase64 = Base64.getUrlEncoder().withoutPadding().encodeToString(JSON.stringify(defaultClaims).getBytes("UTF-8")); | ||
|
||
return "Bearer " + headerBase64 + "." + payloadBase64 + ".your-secret-key"; | ||
}; | ||
|
||
// Set default headers | ||
config.headers = { | ||
"Content-Type": "application/json", | ||
"X-Hasura-Admin-Secret": config.adminSecret, | ||
}; | ||
|
||
karate.log("Config initialized:", config); | ||
return config; | ||
} |