-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backend] Implement Karate tests for apartment_images table #85
Open
akintewe
wants to merge
6
commits into
safetrustcr:main
Choose a base branch
from
akintewe:feature/82-apartment-images-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
046eb2c
Backend] Implement Karate tests for apartment_images table
akintewe aa484d0
feat(migrations): add test data for apartment_images
akintewe d6d4756
made modification and removed duplicate migration
akintewe 538a8d1
made changes
akintewe b93a2de
removed migration
akintewe 279d538
moved to correct location
akintewe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,10 @@ | ||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | ||
|
||
CREATE TABLE apartment_images ( | ||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
apartment_id UUID NOT NULL REFERENCES apartments(id) ON DELETE CASCADE, | ||
image_url TEXT NOT NULL, | ||
uploaded_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE INDEX idx_apartment_images_apartment_id ON apartment_images(apartment_id); |
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,12 @@ | ||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | ||
|
||
CREATE TABLE apartments ( | ||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
name TEXT NOT NULL, | ||
description TEXT, | ||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
|
||
INSERT INTO apartments (id, name, description) VALUES | ||
('11111111-1111-1111-1111-111111111111', 'Modern Loft in Heredia', 'A beautiful modern loft'); |
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,8 @@ | ||
CREATE TABLE apartment_images ( | ||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
apartment_id UUID NOT NULL REFERENCES apartments(id) ON DELETE CASCADE, | ||
image_url TEXT NOT NULL, | ||
uploaded_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE INDEX idx_apartment_images_apartment_id ON apartment_images(apartment_id); |
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,2 @@ | ||
INSERT INTO apartment_images (id, apartment_id, image_url) VALUES | ||
('11111111-1111-1111-1111-111111111111', '11111111-1111-1111-1111-111111111111', 'https://example.com/test-image.jpg'); |
225 changes: 225 additions & 0 deletions
225
tests/karate/features/apartments/apartment_images.feature
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,225 @@ | ||
Feature: Apartment Images Management | ||
|
||
Background: | ||
* url baseUrl | ||
* print '=== Loading feature file ===' | ||
* print 'URL set to:', baseUrl | ||
* header x-hasura-admin-secret = adminSecret | ||
|
||
Scenario: Check GraphQL endpoint health | ||
Given path '/' | ||
And request { query: "query { __typename }" } | ||
When method POST | ||
Then status 200 | ||
And match response == { data: { __typename: 'query_root' } } | ||
|
||
Scenario: Check apartment_images schema | ||
Given path '/' | ||
And request | ||
""" | ||
{ | ||
"query": "query { __type(name: \"apartment_images\") { name fields { name type { name kind } } } }" | ||
} | ||
""" | ||
When method POST | ||
Then status 200 | ||
And match response.errors == '#notpresent' | ||
* print 'Schema:', response.data.__type | ||
|
||
Scenario: Create new apartment image | ||
Given path '/' | ||
And request | ||
""" | ||
{ | ||
"query": "mutation($apartment_id: uuid!, $image_url: String!) { insert_apartment_images_one(object: { apartment_id: $apartment_id, image_url: $image_url }) { id } }", | ||
"variables": { | ||
"apartment_id": "11111111-1111-1111-1111-111111111111", | ||
"image_url": "https://example.com/test-image.jpg" | ||
} | ||
} | ||
""" | ||
When method POST | ||
Then status 200 | ||
And match response.errors == '#notpresent' | ||
* def created_id = response.data.insert_apartment_images_one.id | ||
|
||
Scenario: Verify apartment_images schema exists | ||
Given path '/' | ||
And request | ||
""" | ||
{ | ||
"query": "query { | ||
__type(name: \"apartment_images\") { | ||
name | ||
fields { | ||
name | ||
type { | ||
name | ||
kind | ||
} | ||
} | ||
} | ||
}" | ||
} | ||
""" | ||
When method POST | ||
Then status 200 | ||
And match response.data.__type != null | ||
* print 'Schema:', response.data.__type | ||
|
||
Scenario: Verify mutations are available | ||
Given path '/' | ||
And request | ||
""" | ||
{ | ||
"query": "query { | ||
__schema { | ||
mutationType { | ||
fields { | ||
name | ||
} | ||
} | ||
} | ||
}" | ||
} | ||
""" | ||
When method POST | ||
Then status 200 | ||
And match response.data.__schema.mutationType != null | ||
* print 'Available mutations:', response.data.__schema.mutationType.fields | ||
|
||
Scenario: Verify query permissions | ||
Given path '/' | ||
And request | ||
""" | ||
{ | ||
"query": "query { | ||
__schema { | ||
queryType { | ||
fields { | ||
name | ||
description | ||
} | ||
} | ||
} | ||
}" | ||
} | ||
""" | ||
When method POST | ||
Then status 200 | ||
And match response.data.__schema.queryType != null | ||
* print 'Available queries:', response.data.__schema.queryType.fields | ||
|
||
Scenario: Verify apartment_images table exists | ||
Given path '/' | ||
And request | ||
""" | ||
{ | ||
"query": "query { | ||
__type(name: \"apartment_images\") { | ||
name | ||
fields { | ||
name | ||
type { | ||
name | ||
kind | ||
} | ||
} | ||
} | ||
}" | ||
} | ||
""" | ||
When method POST | ||
Then status 200 | ||
And match response.errors == '#notpresent' | ||
* print 'Schema:', response.data.__type | ||
|
||
Scenario: Query apartment image by ID | ||
Given path '/' | ||
And request | ||
""" | ||
{ | ||
"query": "query GetApartmentImage($id: uuid!) { | ||
apartment_images_by_pk(id: $id) { | ||
id | ||
image_url | ||
apartment_id | ||
uploaded_at | ||
} | ||
}", | ||
"variables": { | ||
"id": "11111111-1111-1111-1111-111111111111" | ||
} | ||
} | ||
""" | ||
When method POST | ||
Then status 200 | ||
And match response.errors == '#notpresent' | ||
And match response.data.apartment_images_by_pk != null | ||
|
||
Scenario: Update apartment image | ||
Given path '/' | ||
And request | ||
""" | ||
{ | ||
"query": "mutation UpdateApartmentImage($id: uuid!, $image_url: String!) { | ||
update_apartment_images_by_pk( | ||
pk_columns: {id: $id}, | ||
_set: {image_url: $image_url} | ||
) { | ||
id | ||
image_url | ||
uploaded_at | ||
} | ||
}", | ||
"variables": { | ||
"id": "11111111-1111-1111-1111-111111111111", | ||
"image_url": "https://example.com/updated-image.jpg" | ||
} | ||
} | ||
""" | ||
When method POST | ||
Then status 200 | ||
And match response.errors == '#notpresent' | ||
And match response.data.update_apartment_images_by_pk.image_url == 'https://example.com/updated-image.jpg' | ||
|
||
Scenario: List apartment images | ||
Given path '/' | ||
And request | ||
""" | ||
{ | ||
"query": "query ListApartmentImages { | ||
apartment_images(limit: 10, order_by: {uploaded_at: desc}) { | ||
id | ||
image_url | ||
apartment_id | ||
uploaded_at | ||
} | ||
}" | ||
} | ||
""" | ||
When method POST | ||
Then status 200 | ||
And match response.errors == '#notpresent' | ||
And match response.data.apartment_images != null | ||
And match response.data.apartment_images == '#[_ > 0]' | ||
|
||
Scenario: Delete apartment image | ||
Given path '/' | ||
And request | ||
""" | ||
{ | ||
"query": "mutation DeleteApartmentImage($id: uuid!) { | ||
delete_apartment_images_by_pk(id: $id) { | ||
id | ||
} | ||
}", | ||
"variables": { | ||
"id": "11111111-1111-1111-1111-111111111111" | ||
} | ||
} | ||
""" | ||
When method POST | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method in this Scenario could be Delete with the Status 204 |
||
Then status 200 | ||
And match response.errors == '#notpresent' | ||
And match response.data.delete_apartment_images_by_pk != null |
32 changes: 32 additions & 0 deletions
32
tests/metadata/databases/default/tables/public_apartment_images.yaml
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,32 @@ | ||
table: | ||
name: apartment_images | ||
schema: public | ||
|
||
object_relationships: | ||
- name: apartment | ||
using: | ||
foreign_key_constraint_on: apartment_id | ||
|
||
select_permissions: | ||
- role: admin | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
|
||
insert_permissions: | ||
- role: admin | ||
permission: | ||
check: {} | ||
columns: '*' | ||
|
||
update_permissions: | ||
- role: admin | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
check: {} | ||
|
||
delete_permissions: | ||
- role: admin | ||
permission: | ||
filter: {} |
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,51 @@ | ||
- table: | ||
schema: public | ||
name: apartments | ||
select_permissions: | ||
- role: admin | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
insert_permissions: | ||
- role: admin | ||
permission: | ||
check: {} | ||
columns: '*' | ||
update_permissions: | ||
- role: admin | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
check: {} | ||
delete_permissions: | ||
- role: admin | ||
permission: | ||
filter: {} | ||
|
||
- table: | ||
schema: public | ||
name: apartment_images | ||
object_relationships: | ||
- name: apartment | ||
using: | ||
foreign_key_constraint_on: apartment_id | ||
select_permissions: | ||
- role: admin | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
insert_permissions: | ||
- role: admin | ||
permission: | ||
check: {} | ||
columns: '*' | ||
update_permissions: | ||
- role: admin | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
check: {} | ||
delete_permissions: | ||
- role: admin | ||
permission: | ||
filter: {} |
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,9 @@ | ||
- table: | ||
name: apartments | ||
schema: public | ||
source: default | ||
|
||
- table: | ||
name: apartment_images | ||
schema: public | ||
source: default |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When creating a new resource or object (such as an apartment image), the HTTP status code should ideally be 201 Created instead of 200 OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright ill modify it