-
Notifications
You must be signed in to change notification settings - Fork 21
Assignment-1,2,3 Fetch all the posts and comments with specific User id #3
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
Open
Kanishk4617
wants to merge
9
commits into
znsio:main
Choose a base branch
from
Kanishk4617:main
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 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
abb5601
get posts and comments w.r.t. user id
61c5fb7
Merge branch 'main' of https://github.com/Kanishk4617/getting-started…
b4831b1
incorporated PR comments
61655b1
incorporated some PR changes
2c8c8c2
made change in some gherkin statements
b8d17f6
workflow added for create and update post
7ec55eb
api test added for comments api
d058c30
some fixes done in getpostapi
3f01b2d
incorporated pr changes
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 hidden or 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,36 @@ | ||
| @UserPosts @prod | ||
| Feature: Fetch User Posts and Albums | ||
|
|
||
| Background: | ||
| * def userId = 1 | ||
| * def testData = read('classpath:com/znsio/templates/userData.json') | ||
|
|
||
| @getPosts | ||
| Scenario: Get posts with specific User id | ||
| * def fetchPosts = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getPost', {"userId": userId, expectedStatus: 200}) | ||
| * karate.log('response : ',fetchPosts.response) | ||
| * match each fetchPosts.response[*].userId == userId | ||
| * match fetchPosts.response.userId == '#number' | ||
| * match fetchPosts.response.id == '#number' | ||
| * match fetchPosts.response.title == '#string' | ||
| * match fetchPosts.response.body == '#string' | ||
|
|
||
|
|
||
| @getPosts | ||
| Scenario: Get posts with user id that doesn't exist | ||
| * def fetchPosts = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getPost', {"userId": 100, expectedStatus: 200}) | ||
| * karate.log('response : ',fetchPosts.response) | ||
| * assert fetchPosts.response.arr == null | ||
|
|
||
| @getComments | ||
| Scenario: Get albums with specific User id | ||
| * def fetchAlbums = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getAlbums', {"userId": userId, expectedStatus: 200}) | ||
| * karate.log('response : ',fetchAlbums.response) | ||
| * match each fetchAlbums.response[*].userId == userId | ||
| * match each fetchAlbums.response == testData.expectedAlbumResponse | ||
|
|
||
| @getComments | ||
| Scenario: Get albums with User id that doesn't exist | ||
| * def fetchAlbums = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getAlbums', {"userId": 100, expectedStatus: 200}) | ||
| * karate.log('response : ',fetchAlbums.response) | ||
| * assert fetchAlbums.response.arr == null | ||
Kanishk4617 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
36 changes: 36 additions & 0 deletions
36
src/test/java/com/znsio/templates/fetchPostAndAlbums.feature
This file contains hidden or 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,36 @@ | ||
| @template | ||
| Feature: Template for User Posts and Comments | ||
|
|
||
| Background: | ||
| * url env.jsonPlaceholderUrl | ||
|
|
||
| @t_getPost | ||
| Scenario: Get User posts | ||
| Given path '/posts/' + userId | ||
| When method GET | ||
| Then match responseStatus == expectedStatus | ||
| * print "response", response | ||
Kanishk4617 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @t_getAlbums | ||
| Scenario: Get User albums | ||
| Given path '/albums' | ||
| * param userId = userId | ||
| When method GET | ||
| Then match responseStatus == expectedStatus | ||
| * print "response",response | ||
|
|
||
| @t_createPost | ||
| Scenario: Create User posts | ||
| Given path '/posts' | ||
| * request {"userId": "#(userId)", "title": "#(title)", "body": "#(body)"} | ||
| When method POST | ||
| Then match responseStatus == expectedStatus | ||
| * print "response",response | ||
|
|
||
| @t_updatePost | ||
| Scenario: Create User posts | ||
| Given path '/posts/' + userId | ||
| * request {"title": "Kanishk Jain"} | ||
Kanishk4617 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| When method PUT | ||
| Then match responseStatus == expectedStatus | ||
| * print "response",response | ||
This file contains hidden or 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,13 @@ | ||
| { | ||
Kanishk4617 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "expectedPostsResponse": { | ||
| "userId": "#number", | ||
| "id": "#number", | ||
| "title": "#string", | ||
| "body": "#string" | ||
| }, | ||
| "expectedAlbumResponse": { | ||
| "userId": "#number", | ||
| "id": "#number", | ||
| "title": "#string" | ||
| } | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
src/test/java/com/znsio/workflow/CreateAndUpdatePost.feature
This file contains hidden or 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,22 @@ | ||
| @prod | ||
| Feature: Create and Update User Posts | ||
|
|
||
| Background: | ||
| * def userId = generateRandomNumber(3) | ||
| * def title = generateAlphaNumericRandomString(5) | ||
| * def body = generateAlphaNumericRandomString(10) | ||
|
|
||
| @createPost | ||
| Scenario: Create a User post and then Update its title | ||
| * def createPost = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_createPost', {"userId": userId, "title": title, "body": body, expectedStatus: 201}) | ||
| * karate.log('response : ',createPost.response) | ||
Kanishk4617 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * def id = createPost.response.userId | ||
| * def fetchPosts = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getPost', {"userId": id, expectedStatus: 200}) | ||
| * match fetchPosts.response.userId == userId | ||
| * match fetchPosts.response.title == title | ||
| * match fetchPosts.response.body == body | ||
| * def newTitle = generateAlphaNumericRandomString(5) | ||
| * def updatePost = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_updatePost', {"title": newTitle, expectedStatus: 201}) | ||
| * karate.log('response : ',updatePost.response) | ||
Kanishk4617 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * def fetchPosts = karate.call('classpath:com/znsio/templates/fetchPostAndAlbums.feature@t_getPost', {"userId": id, expectedStatus: 200}) | ||
| * match fetchPosts.response.title == newTitle | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.