Error:Uncaught AssertionError: expected { Object (response) } to equal { Object (response) } - json

I am facing an issue in test case when i am trying to do deepEqual where i am trying to compare the exact structure of result data with sample data.
the above is my sample json data which i created with the result of the actual data.
Code:
it('comparing structures',()=>{
var result = instance.parseResponse(input,esResponse);
console.log(result);
assert.deepEqual( result, expectedJSON);
});
Here in console i am getting the result .
Taking the result i am creating the sample data .
Code :
var expectedJSON={
"response":{
"aggregate":{
"average":43.833333333333336,
"count":6,
"max":90,
"min":10,
"total":263
},
"endDate":"Tue Jul 05 2016 05:30:00 GMT+0530 (India Standard Time)",
"groupBy":"datetime",
"metricType":"distance_metric",
"quarters":[{
"aggregate":{
"average":0,
"count":undefined,
"max":0,
"min":0,
"total":0
},
"quarter":4,
"startDate":"Invalid Date"
}],
"startDate":"Tue Jan 12 2016 05:30:00 GMT+0530 (India Standard Time)",
"type":"person"
}
};
I am doing this because i need to create the exact Json structure and let anything may be the result the structure should match .
but i am getting the fail test case

deepEqual have a lot of issues and is old now. Lot of new ECMA features aren't supported either. I found this one very interesting: https://github.com/zubuzon/kewlr

When you use deepEqual it checks not only the structure of the object but also the type of object. In this case it is given by __proto__

Related

Loading JSON data to Array and fetching the values in JMeter

I want to put the JSON data into an array and fetch the data
{
"data":{
"platform":{
"id":"d0feb170-76ed-77e9-a24f-44c49397cb8f",
"version":0,
"updatedTime":1557910234867,
"dataVersion":{
"version":0,
"updatedTime":1557910234867
}
},
"machine":{
"version":44,
"updatedTime":1557910026619,
"version":{
"version":19,
"updatedTime":1557910026619
},
"systemId":"Machine1",
"activeStatus":"true",
"settings":[
{
"protNumber":"1.2",
"proto":"TestHead2^^Adult^^Head",
"id":"21a8fbb8-40ea-4868-ae3a-ee1d130eb01b",
"name":"TestHead2",
"humanoid":"Adult",
"anatomy":"Head",
"lastUpdated":"Wed, 15 May 2019 08:47:06 GMT",
"version":0
},
{
"protNumber":"1.8",
"proto":"TestHead8^^Adult^^Head",
"id":"2a25874e-cb9f-40c1-93db-a0859b209491",
"name":"TestHead8",
"humanoid":"Adult",
"anatomy":"Head",
"lastUpdated":"Wed, 15 May 2019 08:47:06 GMT",
"version":0
},
{
"protNumber":"1.88",
"proto":"TestHead88^^Adult^^Head",
"id":"50cc13d8-6d43-4fcd-9d60-08ce4f97632d",
"name":"TestHead88",
"humanoid":"Adult",
"anatomy":"Head",
"lastUpdated":"Wed, 15 May 2019 08:47:06 GMT",
"version":0
}
],
"deviceDeviation":{
"new":9,
"deviated":0,
"newMatched":0,
"totalProtocols":3
}
}
},
"success":true,
"statusCode":200,
"errorMessage":""
}
How can I put the data in the settings into an Array and fetch them one by one?
Use JSON Extractor to fetch data:-
Below, I have created one JSON extractor config for protNumber.
Please check the variable in the results. You can use the first three variables or if you need all then use the 4th...depend on your requirement. Fetch using ${prNumVar_1},${prNumVar_2} etc
Create multiple extractor for different variables..like prot, id, name as per your requirement.
Hope this helps.

how to change date format in mongodb

I have created mongodb collection using nodejs as below:
var mongoose = require('mongoose');
var TTTUsersSchema = new mongoose.Schema({
username: String,
password:String,
active: Boolean,
created_at: { type: Date, default: Date.now },
updated_at: { type: Date, default: Date.now },
});
module.exports = mongoose.model('Users', TTTUsersSchema);
Since creating record the default date is stored as Tue Nov 13 2018
20:53:47 GMT+0000 (GMT Standard Time) so when I fetch this field then it
is displayed in HTML as above. I want to display it in DD/MM/YY HH:MM
format.
Where I need to change? In HTML UI level? or at Mondgodb collection level.
Please help.
Time stamps should always be stored in a consistent way, e.g. like ISODate() in MongoDB, and always be handled in the code in a consistent way, e.g. like Date object in Javascript.
Only when you
present a time stamp to a user as string, or
parse a time string from the user
then you do conversions.
Unfortunately JavaScript Date object is severely limited, so I would suggest to use a package like Moment.js which offers lots of formatting capabilities:
const moment = require('moment');
// date is a Date object you got, e.g. from MongoDB
const time = moment(date);
console.log(time.format("DD/MM/YY HH:mm"));
You need to format your date time at view layer.
one option is to format at your controller if you are using MVC or at the layer that produce view model.
the another option is to format at html using javascript. You may need to use lib like moment.js
Assume current day is Tue Nov 13 2018 20:53:47 GMT+0000
Use .toDateString()
var date = new Date();
console.log(date.toDateString());
It will display:
Tue Nov 13 2018

How can I find all of the emails listed in this file and delete everything else?

I have a file filled with objects in JSON format containing an email property for thousands of users.
{
"object":"list",
"read_only":{
},
"full_access":{
"data":[
{
"id":"32923939",
"platform_id":"12313",
"name":"test",
"email":"test#example.com",
"created_date":"08 Feb 17 10:02 +0000"
},
{
"id":"135541",
"platform_id":"1234",
"name":"test",
"email":"test#example.com",
"created_date":"08 Feb 17 10:00 +0000"
},
{
"id":"484949383",
"platform_id":"494948",
"name":"test",
"email":"test#example.com",
"created_date":"08 Feb 17 08:46 +0000"
},
{
"id":"595033",
"platform_id":"test",
"name":"test",
"email":"test#example.com",
"created_date":"30 Sep 16 17:51 +0000"
}
]
},
"never_logged_in":{
}
}
The problem I am facing is that some of the objects are not formatted correctly, so I am unable to work with them in code. I am wondering if there is a way that I can search the file for a string, "email:", followed by the email address, and delete everything else. I feel like I can accomplish this using regex, to detect the email address, but I am unsure of how to do it myself.
Could anyone offer any insight or recommendations?
In Javascript, you can do something like -
var myJson = {"object":"list","read_only":{},"full_access":{"data":[{"id":"32923939","platform_id":"12313","name":"test","email":"test#example.com","created_date":"08 Feb 17 10:02 +0000"},{"id":"135541","platform_id":"1234","name":"test","email":"test#example.com","created_date":"08 Feb 17 10:00 +0000"},{"id":"484949383","platform_id":"494948","name":"test","email":"test#example.com","created_date":"08 Feb 17 08:46 +0000"},{"id":"595033","platform_id":"test","name":"test","email":"test#example.com","created_date":"30 Sep 16 17:51 +0000"}]},"never_logged_in":{}}
var result = myJson.full_access.data.filter(x=>x.email && x.email!="")
.map(x=>x.email);
console.log(result);
It will check if an element in the data property has email (.filter method), and then map out the email ids in an array.
Here's a JSFiddle link. Check the console for output.
Note : If you just want to do it as a one time activity, paste the original object you received in the Fiddle and just copy the result object from console.
Also, you can use a linter like JSONLint to check where all the JSON is breaking.

Json data generator date and time only

I'm trying to generate some Json data using http://beta.json-generator.com/, but I can not figure out how to generate date and time only (instead of datetime)
For example, the following code:
[
{
'repeat(5, 10)': {
_id: '{{objectId()}}',
date: '{{date()}}',
date_only: '{{date()}}', //how can I show here date only
time_only: '{{date()}}', //how can I show here time only
user: {
first: '{{firstName()}}',
last: '{{surname()}}'
},
phone: '+1 {{phone()}}'
}
}
]
Any ideas on how to code the date_only and time_only lines to truncate the datetime?
Also, can the {date} be formatted. For example instead of:
"Sat Mar 31 1990 21:01:10 GMT+0000 (UTC)"
... something like:
"2010-12-13 21:01:10 GMT"
Thanks
checkout
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
hope this one helps u

JSON feed error

Yes - yet another question re JSON feeds not displaying.
Have searched everywhere for an answer but failed so am asking here.
This is my code to create the JSON:
{url: 'json-events-feed.php?clinician_id='+0, backgroundColor:'yellow', textColor:'black', borderColor:'white', error: function() {
alert('Error message');
},}
This is the returned JSON feed:
[
{
"id":"42",
"title":"Cooper Amess",
"start":"Fri, 02 May 2014 08:00:00",
"end":"Fri, 02 May 2014 10:00:00",
"allDay":false,
"type":"None"
}
]
So the I get the alert : "Error message", but how can I find what the error actually is?
I can't find any documentation on 'error:' anywhere.
I've tried changing the date format: without the ',', as a Unix date etc. but to no avail.
Any help would be appreciated.
Rob
Your start and end date times are not unix timestamps. Check out http://www.epochconverter.com/ to play with some unix timestamps.