Response Actual:
{
"data": [
{
"last_name": "Bluth",
"id": 1,
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/calebogden/128.jpg",
"first_name": "George",
"email": "george.bluth#reqres.in"
},
{
"last_name": "Weaver",
"id": 2,
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg",
"first_name": "Janet",
"email": "janet.weaver#reqres.in"
}
]
}
I have a Database object where it return array of first_name's
Expected:
{"George","Janet"}
I am using scenario outline here as i have bunch of tests need to be check and output is dynamic. How can we write the assertions for this type of scenarios ???
something like response.data[].first_name == expected ??
Sample Code:
Feature: Array Match
Scenario:
* def act =
"""
{
"per_page": 6,
"total": 12,
"ad": {
"company": "StatusCode Weekly",
"text": "A weekly newsletter focusing on software development, infrastructure, the server, performance, and the stack end of things.",
"url": "http://statuscode.org/"
},
"data": [
{
"last_name": "Bluth",
"id": 1,
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/calebogden/128.jpg",
"first_name": "George",
"email": "george.bluth#reqres.in"
},
{
"last_name": "Weaver",
"id": 2,
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg",
"first_name": "Janet",
"email": "janet.weaver#reqres.in"
},
{
"last_name": "Wong",
"id": 3,
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/olegpogodaev/128.jpg",
"first_name": "Emma",
"email": "emma.wong#reqres.in"
},
{
"last_name": "Holt",
"id": 4,
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/marcoramires/128.jpg",
"first_name": "Eve",
"email": "eve.holt#reqres.in"
},
{
"last_name": "Morris",
"id": 5,
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/stephenmoon/128.jpg",
"first_name": "Charles",
"email": "charles.morris#reqres.in"
},
{
"last_name": "Ramos",
"id": 6,
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/bigmancho/128.jpg",
"first_name": "Tracey",
"email": "tracey.ramos#reqres.in"
}
],
"page": 1,
"total_pages": 2
}
"""
* def exp = ["George","Janet","Emma","Eve","Charles","Tracey"]
* match $act.data[*].first_name == exp
Reference Link: https://github.com/intuit/karate#get-short-cut
Related
i have an json response like this :
{
"result": [
{
"id": 2984,
"amount": 5000000,
"account": "money",
"trade_no": "2121683414670617655",
"type": 0,
"for_id": 0,
"created_at": "2021-02-16 20:50:14",
"payment_method": 0,
"status": 1
},
{
"id": 2999,
"amount": -450000,
"account": "money",
"trade_no": "212173166272246C118",
"type": 5,
"for_id": "2021021760479",
"created_at": "2021-01-17 10:14:22",
"payment_method": "0",
"status": 1
},
],
"code": 200,
"description": "OK"
}
and then i want grouping the api by month and year look like this :
please help me to solve this
You can use groupBy method from lodash.
var grouped = _.groupBy(result, function(item) {
return item.created_at.substring(0,7);
});
This will give you data in below format:
{
"2021-02": [
{
"id": 2984,
"amount": 5000000,
"account": "money",
"trade_no": "2121683414670617655",
"type": 0,
"for_id": 0,
"created_at": "2021-02-16 20:50:14",
"payment_method": 0,
"status": 1
}
],
"2021-01": [
{
"id": 2999,
"amount": -450000,
"account": "money",
"trade_no": "212173166272246C118",
"type": 5,
"for_id": "2021021760479",
"created_at": "2021-01-17 10:14:22",
"payment_method": "0",
"status": 1
}
]
}
When rendering the data, you can format your Year-Month key to string using moment like this,
moment('2021-01', 'YYYY-MM').format('MMMM YYYY');
How merge duplicate object and add price like it has tree dublicate then price will add up three time and return new array/obj. this is obj here obj. and also keep track how many duplicates are there
"id1": Object {
"date": 1609247265357,
"orders": Array [
Object {
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/jsa/128.jpg",
"id": 3,
"name": "Tomato",
"price": 15,
},
Object { //this
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/talhaconcepts/128.jpg",
"id": 4,
"name": "Ginger",
"price": 12,
},
Object { //and this
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/talhaconcepts/128.jpg",
"id": 4,
"name": "Ginger",
"price": 12,
},
Object {
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/jsa/128.jpg",
"id": 3,
"name": "Tusi",
"price": 15,
},
],
"uid": "EKSjIptE7Ma32SyGylhKBmLLJHB2",
},......and so on
I am starting out with Postman. I made a simple GET request and got a response. At the end of the response, is "count=14". I am trying to understand what count means here?
I thought the number of records in the response is 14, but its only 10. So what does count=14 mean? Thankyou for your response!
This is the response I got:
{
"records": [
{
"id": "074df210-e1fb-4298-9407-d97881dc1af2",
"fullName": "Abcd",
"email": "janedoe#gmail.com",
"phone": "112-112-112"
},
{
"id": "4f0835d7-7c02-43da-86c7-77a03b4",
"fullName": "John Doe",
"email": "johndoe#gmail.com",
"phone": "1234-234"
},
{
"id": "a9e8cfb6-f62a-4a8e-84a5-df30",
"fullName": "Kitty Doe",
"email": "kittydoe#gmail.com",
"phone": "123-493-892"
},
{
"id": "319bdb34-e1c1-4e86-192",
"fullName": "Lovely Doe",
"email": "lovelydoe#gmail.com",
"phone": "089-829-3898"
},
{
"id": "1dfe5bba-e14b-4e9d-b90c",
"fullName": "Memory Doe",
"email": "memorydoe#gmail.com",
"phone": "273-872-8398"
},
{
"id": "61f466d5-ec00-76ccb88fff5e",
"fullName": "asdas",
"email": "asdas#gmail.com",
"phone": "123-123-9231"
},
{
"id": "f77b8e1d-70f2-4d44-b243-e61eac2a41a0",
"fullName": "asdasda",
"email": "asdasda#gmail.com",
"phone": "123-123-1291"
},
{
"id": "7d071c9e-fce6-4732-bed3-c18412a962c1",
"fullName": "Monday",
"email": "monday#gmail.com",
"phone": "123-129-1231"
},
{
"id": "5a1d1e9d-7396-41e3-aa96-864b",
"fullName": "Tuesday",
"email": "tuesday#gmail.com",
"phone": "123-241-2534"
},
{
"id": "f5da56d1-9fc2861e6da3",
"fullName": "Wednesday",
"email": "wednesday#gmail.com",
"phone": "129-121-1212"
}
],
"count": 14
}
I am using:
https://api.telegram.org/[bot_id]/getUpdates
to retrieve the recent updates. It returns a message object, however it does not include the "text" field of the message.
"message": {
"message_id": 5,
"from": {
"id": 26002823,
"first_name": "Johnny",
"last_name": "Appleseed",
"username": "username"
},
Why is it not returning the "text" value so I can see what the message said?
here is telegram different objects , maybe the message is sticker or document file.
{
"ok": true,
"result": [{
"update_id": 513400512,
"message": {
"message_id": 3,
"from": {
"id": 86853848,
"first_name": "Mojtaba",
"last_name": "Yeganeh",
"username": "mojtabye"
},
"chat": {
"id": 86853848,
"first_name": "Mojtaba",
"last_name": "Yeganeh",
"username": "mojtabye",
"type": "private"
},
"date": 1484944898,
"text": "hi"
}
}, {
"update_id": 513400513,
"message": {
"message_id": 4,
"from": {
"id": 86853848,
"first_name": "Mojtaba",
"last_name": "Yeganeh",
"username": "mojtabye"
},
"chat": {
"id": 86853848,
"first_name": "Mojtaba",
"last_name": "Yeganeh",
"username": "mojtabye",
"type": "private"
},
"date": 1484944975,
"sticker": {
"width": 512,
"height": 512,
"emoji": "\ud83d\ude0d",
"thumb": {
"file_id": "AAQEABMr6HIwAAT9WnLtRCT6KIgiAAIC",
"file_size": 2828,
"width": 128,
"height": 128
},
"file_id": "BQADBAADrwgAAjn8EwY1EPt_ycp8OwI",
"file_size": 14102
}
}
}, {
"update_id": 513400515,
"message": {
"message_id": 6,
"from": {
"id": 86853848,
"first_name": "Mojtaba",
"last_name": "Yeganeh",
"username": "mojtabye"
},
"chat": {
"id": 86853848,
"first_name": "Mojtaba",
"last_name": "Yeganeh",
"username": "mojtabye",
"type": "private"
},
"date": 1484944986,
"text": "\ud83d\ude0d"
}
}, {
"update_id": 513400516,
"message": {
"message_id": 7,
"from": {
"id": 86853848,
"first_name": "Mojtaba",
"last_name": "Yeganeh",
"username": "mojtabye"
},
"chat": {
"id": 86853848,
"first_name": "Mojtaba",
"last_name": "Yeganeh",
"username": "mojtabye",
"type": "private"
},
"date": 1484945102,
"document": {
"mime_type": "video/mp4",
"thumb": {
"file_id": "AAQEABN_NmAZAAScKVXd0kYiFiM4AAIC",
"file_size": 1681,
"width": 67,
"height": 90
},
"file_id": "BQADBAADRwQAAhvmtwXM4rikxEvd7QI",
"file_size": 835339
}
}
}]
}
I have a list of users. I am trying to retrieve their registration, editcount and gender using API:Users, and contribution data using API:Usercontribs.
Because of being gentle with the API, I have to put a bunch of usernames in each request, and I need to match their userIDs in order to be able to merge the results from the two APIs.
I faced an strange problem: there are a fair number of users with different userIDs retrieved by each method. E.g., if you query data for username "December21st2012Freak" from API:Users, you'll get userID 14281125, but requesting the same username from API:Usercontribs, the userID returns as 10141256.
Another example is username "The Sunshine Man", which has userID 4857299 retrieved bu API:Users and userID 4302884 retrieved by API:Usercontribs.
I don't understand why there is such an inconsistency.
Here are exact queries:
https://en.wikipedia.org/w/api.php?action=query&list=users&ususers=December21st2012Freak|The%20Sunshine%20Man&usprop=blockinfo%7Cgroups%7Ceditcount%7Cregistration%7Cemailable%7Cgender
which returns:
{
"query": {
"users": [
{
"userid": 14281125,
"name": "December21st2012Freak",
"editcount": 0,
"registration": "2011-03-29T02:14:36Z",
"groups": [
"*",
"user"
],
"emailable": "",
"gender": "unknown"
},
{
"userid": 4857299,
"name": "The Sunshine Man",
"editcount": 0,
"registration": "2007-07-13T20:00:58Z",
"groups": [
"*",
"user"
],
"gender": "unknown"
}
]
}
}
And the Usercontribs query:
https://en.wikipedia.org/w/api.php?action=query&list=usercontribs&ucuser=December21st2012Freak&uclimit=3&ucdir=newer&continue=
which results:
{
"batchcomplete": "",
"continue": {
"uccontinue": "20090904033705|311775264",
"continue": "-||"
},
"query": {
"usercontribs": [
{
"userid": 10141256,
"user": "December21st2012Freak",
"pageid": 24217201,
"revid": 311775169,
"parentid": 0,
"ns": 3,
"title": "User talk:MsD723",
"timestamp": "2009-09-04T03:36:13Z",
"new": "",
"minor": "",
"top": "",
"comment": "Added welcome template to user talk page. using [[WP:FRIENDLY|Friendly]]",
"size": 1458
},
{
"userid": 10141256,
"user": "December21st2012Freak",
"pageid": 24217203,
"revid": 311775198,
"parentid": 0,
"ns": 3,
"title": "User talk:Oneseeker2",
"timestamp": "2009-09-04T03:36:32Z",
"new": "",
"minor": "",
"top": "",
"comment": "Added welcome template to user talk page. using [[WP:FRIENDLY|Friendly]]",
"size": 1458
},
{
"userid": 10141256,
"user": "December21st2012Freak",
"pageid": 24217208,
"revid": 311775231,
"parentid": 0,
"ns": 3,
"title": "User talk:Carolynhinchey",
"timestamp": "2009-09-04T03:36:46Z",
"new": "",
"minor": "",
"top": "",
"comment": "Added welcome template to user talk page. using [[WP:FRIENDLY|Friendly]]",
"size": 1458
}
]
}
}
And
https://en.wikipedia.org/w/api.php?action=query&list=usercontribs&ucuser=The%20Sunshine%20Man&uclimit=3&ucdir=newer&continue=
which results:
{
"batchcomplete": "",
"continue": {
"uccontinue": "20070517145725|131549160",
"continue": "-||"
},
"query": {
"usercontribs": [
{
"userid": 4302884,
"user": "The Sunshine Man",
"pageid": 11271016,
"revid": 131518067,
"parentid": 131517319,
"ns": 4,
"title": "Wikipedia:Miscellany for deletion/Portal:Aquinas College, Perth",
"timestamp": "2007-05-17T11:48:17Z",
"comment": "/* [[Portal:Aquinas College, Perth]] */ Delete",
"size": 1773
},
{
"userid": 4302884,
"user": "The Sunshine Man",
"pageid": 7797923,
"revid": 131547208,
"parentid": 131525587,
"ns": 3,
"title": "User talk:Ryan Postlethwaite",
"timestamp": "2007-05-17T14:47:29Z",
"comment": "HeHe",
"size": 49019
},
{
"userid": 4302884,
"user": "The Sunshine Man",
"pageid": 11247929,
"revid": 131547970,
"parentid": 131543922,
"ns": 4,
"title": "Wikipedia:Requests for adminship/Bobak",
"timestamp": "2007-05-17T14:51:19Z",
"comment": "Support",
"size": 16492
}
]
}
}
As reported by Tgr: this is a bug, please be patient and wait for it to be fixed. https://phabricator.wikimedia.org/T99929