How to assert two dynamic values in postman? - postman

I"m having a postman test to check for two values in the response. Here' the code snippet below
pm.test('Validate the Response', function () {
var json = pm.response.json();
id1 = pm.globals.get("global_var1");
id2 = pm.globals.get("global_var2");
pm.expect(json.ids).to.eql([id1,id2]);
});
Here the id1 and id2 values randomly change ( i.e test101,test102 or test202,test203 or test403,test401)
Since they don't follow an order, how i make the assertion to check the values in any order during assertion?

Not sure about the structure of your response data but if it's like this:
{
"ids": "test101,test102"
}
Then a check like this can be what you need:
pm.test('Validate the Response', () => {
let idList = _.get(pm.response.json(), "ids"),
id1 = pm.globals.get("global_var1"),
id2 = pm.globals.get("global_var2");
pm.expect(idList).to.include(id1,id2);
});

Related

In postman tests, how can I find if a value is set where another value is equal to something?

Example:
[
{
"id": 1,
"value": 1000,
},
{
"id": 2,
"value": 500,
},
]
I want to basically say check that value is 1000 where id = 1.
The code:
pm.test("Check value is correct", function () {
const responseJson = pm.response.json();
pm.expect(responseJson.value = 1000);
pm.expect(responseJson.id = 1);
});
Is that the correct way to do that test? Or is that going to check both is valid?
responseJson is an array, so it is not going to work, because you are not accessing any array element. Always try your code first. There are other problems, e.g. pm.expect(responseJson.value = 1000); is not gonna work, you have to chain the checks, this syntax is incorrect.
You can filter based on id and check the value then:
pm.test("Check value is correct", function () {
const responseJson = pm.response.json();
const [filteredObject] = responseJson.filter(el => el.id === 1);
pm.expect(filteredObject.value).to.eql(1000);
});
I recommend reading test examples in Postman docs.

How to delete a few rows via SQL in QuestDB?

is there a way to delete a view rows matching a query in QuestDB?
I can't find any statement allowing me that.
This would be the best option:
delete from mytable where columnvalue==2;
Thanks!
In QuestDb Update and Delete statement are not supported. At least now. The ways to delete data are:
Drop a partition
Write a copy of the table without the rows you want to delete, drop table and then rename the table to the one you wanted. Something like
Create table mytablecopy AS (
SELECT * FROM mytable where columnvalue != 2
) Timstamp(...) PARTITION BY ...;
DROP TABLE mytable;
RENAME table mytablecopy TO mytable;
These are costly workarounds for exceptional cases.
Updates are allowed in questdb now. In my opinion a much better option is to have an extra column in all your tables called something like isDeleted and use the the update query to maintain what is deleted and whats not. Another note here would be to add indexing on this column for efficiency.
see this for more details : https://questdb.io/docs/develop/update-data#postgres-compatibility
See the example below how to use the update query :
"use strict"
const { Client } = require("pg")
const start = async () => {
const client = new Client({
database: "qdb",
host: "127.0.0.1",
password: "quest",
port: 8812,
user: "admin",
options: "-c statement_timeout=300000"
})
await client.connect()
const createTable = await client.query(
"CREATE TABLE IF NOT EXISTS trades (ts TIMESTAMP, date DATE, name STRING, value INT) timestamp(ts);"
)
console.log(createTable)
for (let rows = 0; rows < 10; rows++) {
// Providing a 'name' field allows for prepared statements / bind variables
let now = new Date().toISOString()
const query = {
name: "insert-values",
text: "INSERT INTO trades VALUES($1, $2, $3, $4);",
values: [now, now, "node pg prep statement", rows],
}
await client.query(query)
}
const updateData = await client.query(
"UPDATE trades SET name = 'update example', value = 123 WHERE value > 7;"
)
console.log(updateData)
await client.query("COMMIT")
const readAll = await client.query("SELECT * FROM trades")
console.log(readAll.rows)
await client.end()
}
start()
.then(() => console.log("Done"))
.catch(console.error)

Mongodb returns all fields even with projection specified

Update:
I want to only return all documents that fit four characters of a given username that is entered. So if I have a list of usernames and I type in mango3333, all usernames that are starting with "mang" should be returned. I used a regexp for that, and now I want to only return for example the username and the id of that document and not all fields, but it returns all fields.
An example document looks like this:
{"_id":{"$oid":"5d75299b0d01830"},
"User":
{ "username":"mango",
"userid":"8b8d25d3-3fe6-4d1c",
"token":"token",
"pw":"password",
"statusmessage":"",
"lastlogin":{"$date":{"$numberLong":"1567959451354"}},
"registered":{"$date":{"$numberLong":"1567959451354"}
}
This is my query:
const db = dbClient.db(dbName);
const regexp = new RegExp(username, "gi");
db.collection(collectionName).find({ "User.Username": regexp }, { "User.Username": 1, "User.UserID": 1, "User.Statusmessage": 1 })
.toArray()
.then(result => {
console.log(result);
})
.catch(err => console.error(`Failed to get results: ${err}`));
What am I doing wrong?
The 2nd portion of the find method is an options object, not just projection. The projection portion of the query will need to be specified in this options object. Try the following:
db.collection(collectionName).find(
{ "User.Username": regexp },
{
projection: {
"User.Username": 1,
"User.UserID": 1,
"User.Statusmessage": 1
}
}
)
.toArray()
.then(result => {
console.log(result);
})
See https://mongodb.github.io/node-mongodb-native/3.3/api/Collection.html#find

Apex Interactive Grid how to retrieve a specific record

I am retrieving my grid data using:
var ig$ = apex.region("myGrid1").widget(),
view = ig$.interactiveGrid("getCurrentView");
Now I want to check for a specific record based on 2 columns: id1 and id2 where id1 = 1 and id2 = 7
How can I do that with javascript?
You can iterate for each record like this:
//"myGrid1" should be the static id of the IG region
var widget = apex.region('myGrid1').widget();
var grid = widget.interactiveGrid('getViews','grid');
var model = grid.model;
var results = [];
model.forEach(function(r) {
var record = r;
//the name of the columns should be ID1 and ID2, if not
//make the necessary changes using "_" to represent "space"
var value1 = model.getValue(record,'ID1');
var value2 = model.getValue(record,'ID2');
if(value1 == 1 && value2 == 7) {
results.push(record);
}
})
console.log(results);
To test this code, execute it on console.
To start the console on chrome just press F12
good luck.

Google chart Showing zero in case of missing date in bar graph

I have an object which contains "Date" and "Amount".The object will contain the data for last seven days.If any one date is missing in the object I want to show the bar graph as 0 for that date.
Can someone help me with this issue?
Found the answer .Incase if any one require you can have a look at below code
var orders = _orderService.GetAll(c => c.RestaurantId == restaurantId && (c.Date > DateTime.Now.AddDays(-7))).OrderBy(x => x.Date).GroupBy(item => item.Date.Date).OrderBy(g => g.Key).
Select(i => new Order { Date = i.Key.Date, GrossAmount = i.Sum(w => w.GrossAmount) }).ToList();
var from = DateTime.Now.AddDays(-7);
var to = DateTime.Now.AddDays(-1);
var days = Enumerable.Range(0, 1 + to.Subtract(from).Days)
.Select(offset => from.AddDays(offset))
.ToArray();
var data = days.Select(i =>new Order{ Date=i.Date,GrossAmount=orders.Where(p=>p.Date==i.Date).Sum(w=>w.GrossAmount)}).ToList();