-
Notifications
You must be signed in to change notification settings - Fork 21
Fetch posts and albums for a given user | API Assignments #8
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| @userPostsandAlbums @prod | ||
| # TARGET_ENVIRONMENT=prod TYPE=api TAG=@getUserPosts ./gradlew test | ||
|
|
||
| Feature: Fetch user details wrt jsonPlaceHolder api | ||
| Background: | ||
| * def jsonPostsData = read('classpath:com/znsio/templates/postsData.json') | ||
| * def jsonAlbumsData = read('classpath:com/znsio/templates/albumsData.json') | ||
|
|
||
| @getUserPosts | ||
| Scenario Outline: Get posts for a specific user | ||
| Given def getUserPosts = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_getUserPosts',{'user_Id' : <userId>,status:<status>}) | ||
| Then karate.log("Response from GET request for posts : ", getUserPosts.response) | ||
| And match each getUserPosts.response[*].userId == <userId> | ||
| And match each getUserPosts.response[*] == jsonPostsData.postSchema | ||
| Examples: | ||
| | userId | status | | ||
| | 1 | 200 | | ||
| | 110 | 404 | | ||
| | | 404 | | ||
| | *^$#^& | 400 | | ||
| | null | 400 | | ||
|
|
||
| @getUserAlbums | ||
| Scenario Outline: Get albums for a specific user | ||
| Given def getUserAlbums = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_getUserAlbums',{user_Id: <userId>,"status":<status>}) | ||
| Then karate.log("Response from get request for albums :", getUserAlbums.response) | ||
| And match each getUserAlbums.response[*].userId == <userId> | ||
| And match each getUserAlbums.response[*] == jsonAlbumsData.albumSchema | ||
| Examples: | ||
| | userId | status | | ||
| | 1 | 200 | | ||
| | 110 | 404 | | ||
| | | 404 | | ||
| | *^$#^& | 404 | | ||
| | null | 400 | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "albumSchema": | ||
| { | ||
| "userId": "#number", | ||
| "id": "#number", | ||
| "title": "#string" | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "postSchema": | ||
| { | ||
| "userId": "#number", | ||
| "id": "#number", | ||
| "title": "#string", | ||
| "body": "#string" | ||
| }, | ||
|
|
||
| "createdPostSchema": | ||
| { | ||
| "title": "#string", | ||
| "body": "#string", | ||
| "userId": "#number", | ||
| "id": "#number" | ||
| }, | ||
|
|
||
| "Payload": | ||
| { | ||
| "title": "ABC_10", | ||
|
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. Use randomiser functions to generate data. |
||
| "body": "Sample blog", | ||
| "userId": 1 | ||
| }, | ||
|
|
||
| "Payload_patch": | ||
| { | ||
| "title": "Modified_title" | ||
| }, | ||
|
|
||
| "id": 101, | ||
| "status":200 | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| @usertemplate | ||
|
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. File name is incorrect. Please give suitable name for Template. |
||
| Feature: Template for JsonPlaceHolder api | ||
|
|
||
| Background: | ||
| * print "jsonPlaceHolder url " + env.jsonPlaceholderUrl | ||
|
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. Use Karate.log() instead using print. |
||
| Given url env.jsonPlaceholderUrl | ||
|
|
||
| @t_getUserPosts | ||
| Scenario: Get all the posts for a given user | ||
| # * def query = {userId:'#(user_Id)'} | ||
|
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. remove commented lines. |
||
| Given path '/posts' | ||
| And params {userId:'#(user_Id)'} | ||
| When method GET | ||
| Then karate.log("Response status is ", responseStatus) | ||
| And match responseStatus == status | ||
|
|
||
| @t_getUserAlbums | ||
| Scenario: Get albums for a given user | ||
| Given path '/users/' + user_Id + '/albums' | ||
| When method GET | ||
| Then karate.log("Response status is ", responseStatus) | ||
| And match responseStatus == status | ||
|
|
||
| @t_createPost | ||
| Scenario: Create a post | ||
| Given path '/posts' | ||
| And request payload | ||
| When method POST | ||
| Then status 201 | ||
|
|
||
| @t_updatePost | ||
| Scenario: Update a post | ||
| Given path '/posts' | ||
| And request payload | ||
| When method PATCH | ||
| Then status 200 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| @prod @userWorkFlow | ||
| #TARGET_ENVIRONMENT=prod TYPE=workflow TAG=@userPost ./gradlew test | ||
|
|
||
| Feature: Create and Update post - JsonPlaceHolder API | ||
| Background: | ||
| * def jsonPostsData = read('classpath:com/znsio/templates/postsData.json') | ||
|
|
||
| @createAndUpdatePost | ||
| Scenario: Create a post and update title later | ||
| Given def createPost = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_createPost', {'payload': jsonPostsData.Payload}) | ||
| Then karate.log('Created post response', createPost.response) | ||
| And match createPost.response.id == jsonPostsData.id | ||
| And match createPost.response.title == jsonPostsData.Payload.title | ||
| And match createPost.response == jsonPostsData.createdPostSchema | ||
| Given def getPosts = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_getUserPosts', {'user_Id': createPost.response.userId,'status':jsonPostsData.status}) | ||
| And match getPosts.response.length == '#notpresent' | ||
| Then def updatePost = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_updatePost', {'Id': jsonPostsData.id, 'payload': jsonPostsData.Payload_patch}) | ||
| Then karate.log("Response for the updated post", updatePost.response) | ||
| Then match updatePost.response.title == Payload_patch.title | ||
| Given def getPosts = karate.call('classpath:com/znsio/templates/userTemplates.feature@t_getUserPosts',{'user_Id': createPost.response.userId,'status':jsonPostsData.status}) | ||
| Then match getPosts.response.title == "#notpresent" |
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.
If these variable is not common throughout scenarios, initialise them in scenario level.