This is my response.
`
{
"Response": {
"_": {
"QueryResponse": {
"_": null,
"#": {
"totalCount": "55"
}
}
},
"#": {
"time": "2020-12-22T18:21:58.862-08:00"
}
}
}
`
I am doing this in feature file
* print "total count="+ result.session.runtimeData.read_count.Response._.QueryResponse.#.totalCount
and getting
<eval>:1:78 Expected ident but found error result.session.runtimeData.read_taxcode_count.Response._.QueryResponse.#.totalCount ^ in <eval> at line number 1 at column number 78
^ points to #
tried enclosing it in [''] many places for the response but I am not able to get the value.
Sometimes you don't need to complicate things, try this:
* def count = get[0] response..totalCount
Also this would have worked:
* def count = response.Response._.QueryResponse['#'].totalCount
Related
I am using sequelize + typescript over node (with postgresql db) and I have the following model:
id: number,
someField: string,
arr1: number[],
arr2: number[]
and I'm trying to find all records in which arr1 and arr2 don't contain a certain value.
As far as I've seen my only option in one query is a mix between Op.not and Op.contains,
so I've tried the following queries:
/// Number 1
where: {
arr1: {
[Op.not] : {[Op.contains]: [someValue]}
},
arr2: {
[Op.not] : {[Op.contains]: [soemValue]}
}
},
/// Number 2
where: {
[Op.not]: [
{arr1: {[Op.contains]: [someValue]}},
{arr2: {[Op.contains]: [someValue]}}
]
},
Now, number 1 does compile in typescript but when trying to run it the following error returns:
{
"errorId": "db.failure",
"message": "Database error occurred",
"innerError":
{
"name": "SequelizeValidationError",
"errors":
[
{
"message": "{} is not a valid array",
"type": "Validation error",
"path": "arr1",
"value": {},
"origin": "FUNCTION",
"instance": null,
"validatorKey": "ARRAY validator",
"validatorName": null,
"validatorArgs": []
}
]
}
}
So I tried number 2, which didn't compile at all with the following TS error:
Type '{ [Op.not]: ({ arr1: { [Op.contains]: [number]; }; } | { arr2: { [Op.contains]: [number]; }; })[]; }' is not assignable to type 'WhereOptions<any>'.
Types of property '[Op.not]' are incompatible.
Type '({ arr1: { [Op.contains]: [number]; }; } | { arr2: { [Op.contains]: [number]; }; })[]' is not assignable to type 'undefined'
So the question is what am I doing wrong, or in other words, how can I make that query without querying all records and filter using code
Thanks!
You have to use notIn and not contain maybe then it will work:
Official Docs: https://sequelize.org/master/manual/model-querying-basics.html
where: {
arr1: {
[Op.notIn]: someValueArray
},
arr2: {
[Op.notIn]: someValueArray
}
},
Apparently the second option is the correct one, but what was incorrect was the types of sequelize, #ts-ignore fixes the problem
This question already has an answer here:
Using match each contains for json array items assertion
(1 answer)
Closed 1 year ago.
My question about selective asserting with 'match each'.
Below is a sample json body:
* def data =
"""
{
"companies": [
{
"companyDetails": {
"name": "companyName",
"location": {
"address": "companyAddress",
"street": "companyStreet"
}
}
},
{
"companyDetails": {
"name": "companyName",
"location": {
"address": "companyAddress",
"street": "companyStreet"
}
}
}
]
}
"""
How can we assert whether each 'companyDetails' object in the response contains a certain element, e.g. name only?
* match each data.companies contains { companyDetails: { name: '#notnull' } }
When I use above step, this returns below error:
$[0] | actual does not contain expected | all key-values did not match, expected has un-matched keys
So, is there any way we can assert only one field inside this object? For example, assert whether each companyDetails object contains name, but ignores the other elements such as location? Thanks
This will work:
* match each data.companies == { companyDetails: { name: '#notnull', location: '#notnull' } }
This will also work:
* match data.companies contains deep { companyDetails: { name: '#notnull' } }
Sometimes it is better to transform the JSON before a match:
* match each data..companyDetails contains { name: '#notnull' }
This file (getAllDomain.json) has known/valid response but the order of domain_name /domain_code is random which has to compare against api output..
means .. X3 may come first or last and there is no define order.
I was trying to verify each data array element against the response. But its not working.
IS there any way to just verify arrary and all other element other than "data" can be ignored.
* def expected = read('getAllDomain.json')
* def response =
"""
{
"status":"SUCCESS",
"totalCount":3,
"statusCode":"OK",
"ResultData":{
"data":[
{
"domain_code":"X3",
"domain_name":"BMW"
},
{
"domain_code":"Q5",
"domain_name":"AUDI"
},
{
"domain_code":"MDX",
"domain_name":"ACURA"
}
]
}
}
"""
And match response.ResultData.data[*] contains any expected.ResultData.data[0]
Here you go. And try to read the docs, it will actually help you:
* def expected =
"""
[
{
"domain_code": "MDX",
"domain_name": "ACURA"
},
{
"domain_code": "X3",
"domain_name": "BMW"
},
{
"domain_code": "Q5",
"domain_name": "AUDI"
}
]
"""
* def response =
"""
{
"status":"SUCCESS",
"totalCount":3,
"statusCode":"OK",
"ResultData":{
"data":[
{
"domain_code":"X3",
"domain_name":"BMW"
},
{
"domain_code":"Q5",
"domain_name":"AUDI"
},
{
"domain_code":"MDX",
"domain_name":"ACURA"
}
]
}
}
"""
* match response.ResultData.data contains only expected
Trying to get the json key text within karate feature script.
HI, I am new to karate and going through all the documentation of karate..
When I am getting GET response as show below in the code, I am not sure what all keys a response will have. So whenever in the response there is key text is domain_name , then I want to retrieve domain_code
{
"status":"SUCCESS",
"totalCount":1,
"statusCode":"OK",
"ResultData":{
"data":[
{"domain_code":"X3","domain_name":"BMW"},
{"domain_code":"Q5","domain_name":"AUDI"},
{"domain_code":"G450","domain_name":"LEXUS"}
]
}
Here you go. Read the docs if any part is not clear, starting with JsonPath:
* def response =
"""
{
"status": "SUCCESS",
"totalCount": 1,
"statusCode": "OK",
"ResultData": {
"data": [
{"domain_code": "X3", "domain_name": "BMW" },
{"domain_code": "Q5", "domain_name": "AUDI" },
{"domain_code": "G450", "domain_name": "LEXUS" }
]
}
}
"""
* def data = get[0] response..data[?(#.domain_name)]
* def keys = karate.keysOf(data)
* keys.remove('domain_name')
* print keys[0]
I have a un-named JSON array like this from the response and would like to check whether it contains "confirmationNumber": "pqrs" or not. May I know how can I check that in Karate?
[
{
"id": 145,
"confirmationNumber": "abcd"
},{
"id": 723
"confirmationNumber": "pqrs"
}
,{
"id": 7342
"confirmationNumber": "sfeq"
}
]
karate.filter() is good for these situations:
* def response =
"""
[
{
"id":145,
"confirmationNumber":"abcd"
},
{
"id":723,
"confirmationNumber":"pqrs"
},
{
"id":7342,
"confirmationNumber":"sfeq"
}
]
"""
* def fun = function(x){ return x.confirmationNumber == 'pqrs' }
* def found = karate.filter(response, fun)
* match found == '#[1]'
Also see examples of JsonPath: https://github.com/intuit/karate#jsonpath-filters
EDIT: apologies, there is a much simpler way, please read the docs !
* match response contains { id: '#number', confirmationNumber: 'pqrs' }
* def item = { confirmationNumber: 'pqrs' }
* match response contains '#(^item)'