-
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.
test: configure karate test framework with docker
- Loading branch information
Showing
15 changed files
with
191 additions
and
361 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 |
---|---|---|
@@ -1,21 +1,14 @@ | ||
FROM node:18 | ||
FROM openjdk:17 | ||
|
||
WORKDIR /app | ||
|
||
# Install Java (required for Karate) | ||
RUN apt-get update && \ | ||
apt-get install -y openjdk-17-jdk && \ | ||
apt-get clean | ||
# Copy test files | ||
COPY tests /app/tests | ||
|
||
# Copy package files and install dependencies (if any) | ||
COPY package*.json ./ | ||
RUN npm install --only=production | ||
# 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 | ||
|
||
# Copy the Karate JAR file and test files | ||
COPY tests/karate.jar /app/tests/karate.jar | ||
COPY tests /app/tests/ | ||
RUN chmod -R 755 /app/tests | ||
|
||
|
||
# Set the entry point | ||
CMD ["npm", "test"] | ||
# 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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,23 +1,28 @@ | ||
Feature: User Authentication | ||
|
||
Background: | ||
* print '=== Loading feature file ===' | ||
* url baseUrl | ||
* def tokenHelper = read('../../helpers/generate-token.js') | ||
* print 'URL set to:', baseUrl | ||
* header x-hasura-admin-secret = adminSecret | ||
|
||
Scenario: User can login with valid credentials | ||
# Set up the test data | ||
* def validToken = tokenHelper({ uid: 'test-user', role: 'user' }) | ||
|
||
Given path '/v1/graphql' | ||
And header Authorization = 'Bearer ' + validToken | ||
And request { query: "query { me { id email } }" } | ||
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 | ||
And match response.errors == '#notpresent' | ||
And match response.data.me.id == 'test-user' | ||
* print 'Schema:', response.data | ||
|
||
Scenario: User cannot access without token | ||
Given path '/v1/graphql' | ||
And request { query: "query { me { id email } }" } | ||
When method POST | ||
Then status 401 | ||
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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
Feature: User Permissions | ||
Feature: Authorization Permissions | ||
|
||
Background: | ||
* url baseUrl | ||
* def tokenHelper = read('../../helpers/generate-token.js') | ||
* print '=== Loading feature file ===' | ||
* print 'URL set to:', baseUrl | ||
|
||
Scenario: User can only access their own data | ||
# Set up the test data | ||
* def validToken = tokenHelper({ uid: 'test-user', role: 'user' }) | ||
|
||
Given path '/v1/graphql' | ||
And header Authorization = 'Bearer ' + validToken | ||
And request { query: "query { users { id email } }" } | ||
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 | ||
And match response.errors == '#notpresent' | ||
And match response.data.users[*].id contains 'test-user' |
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 |
---|---|---|
@@ -1,18 +1,14 @@ | ||
Feature: User Creation | ||
Feature: Create User | ||
|
||
Background: | ||
* url baseUrl | ||
* def tokenHelper = read('../../helpers/generate-token.js') | ||
* print '=== Loading feature file ===' | ||
* print 'URL set to:', baseUrl | ||
|
||
Scenario: Admin can create a new user | ||
# Set up the test data | ||
* def adminToken = tokenHelper({ uid: 'admin-user', role: 'admin' }) | ||
* def newUser = { email: '[email protected]', password: 'password123' } | ||
|
||
Given path '/v1/graphql' | ||
And header Authorization = 'Bearer ' + adminToken | ||
And request { query: "mutation($user: UserInput!) { createUser(user: $user) { id email } }", variables: { user: '#(newUser)' } } | ||
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.errors == '#notpresent' | ||
And match response.data.createUser.email == newUser.email | ||
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 |
---|---|---|
@@ -1,27 +1,19 @@ | ||
Feature: User Queries | ||
Feature: Query Users | ||
|
||
Background: | ||
* url baseUrl | ||
* def tokenHelper = read('../../helpers/generate-token.js') | ||
* print '=== Loading feature file ===' | ||
* print 'URL set to:', baseUrl | ||
* header x-hasura-admin-secret = adminSecret | ||
|
||
Scenario: User can query their own profile | ||
# Set up the test data | ||
* def validToken = tokenHelper({ uid: 'test-user', role: 'user' }) | ||
|
||
Given path '/v1/graphql' | ||
And header Authorization = 'Bearer ' + validToken | ||
And request { query: "query { user(id: \"test-user\") { id email } }" } | ||
Scenario: Query existing user | ||
Given request { query: "{ __typename }" } | ||
When method POST | ||
Then status 200 | ||
And match response.errors == '#notpresent' | ||
And match response.data.user.id == 'test-user' | ||
And match response == { data: { __typename: 'query_root' } } | ||
|
||
Scenario: User cannot query other users' profiles | ||
* def validToken = tokenHelper({ uid: 'test-user', role: 'user' }) | ||
|
||
Given path '/v1/graphql' | ||
And header Authorization = 'Bearer ' + validToken | ||
And request { query: "query { user(id: \"other-user\") { id email } }" } | ||
Scenario: Query non-existing user | ||
Given request { query: "{ __typename }" } | ||
When method POST | ||
Then status 200 | ||
And match response.data.user == null | ||
And match response == { data: { __typename: 'query_root' } } |
Oops, something went wrong.