I`m performing API automation testing and use GET request via Cypress and receive in the body the next structure:
{
my_list: [
{
code: "SAT-12-33-1",
description: "FLOOR 1",
payment: "128"
},
{
code: "SAT-12-33-2",
description: "FLOOR 2",
payment: "33"
},
{
code: "SAT-12-33-3",
description: "FLOOR 3",
payment: "311"
},
{
code: "SAT-12-33-4",
description: "FLOOR 4",
payment: "342"
},
{
....and so on. The full structure is 3400 records.
Could somebody give me an exact example, HOW to validate, that for instance this chunk (2 elements only) of code:
{
code: "SAT-12-33-2",
description: "FLOOR 2",
payment: "33"
},
{
code: "SAT-12-33-3",
description: "FLOOR 3",
payment: "311"
}
exactly matching on the received array of 3400 records. In my case, I will have 3 or 4 elements and I have to compare them/validate versus the big array.
I have tried expect(response.body).to.contain(), deep.equal(), .should('include') and more, but does not work to me.
Can someone provide the exact code that matching part of the structure above to the whole request body with the same structure? Again, I will have 2 or 3 elements and want to compare them together to a big array of 3400 elements?
Thank you very much!
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have assigned a task to group data in angular js using underscore js.
My JSON :
data = [
{
"Building*": "Building A",
"Wing*": "Wing C",
"Floor*": "Floor 3",
"Room Name*": "Room 3",
"Room Type*": "AC",
"Location*": "Location 1",
"Device ID*": 27,
"Category*": "Soap Hygene",
"Dispenser Name*": "Dispenser 34",
"Type*": "Manual",
"Cartridge Type*": "Type 1",
"Date of installation": "2016-04-11T06:06:22 -06:-30",
"Contact Last Name": "Maynard",
"Email Address": "thomas.boscher#gmail.com",
"Mobile Number with country code": "+1 (949) 590-3465",
"Description": "Description of device",
"Model": 37
},
{
"Building*": "Building B",
"Wing*": "Wing B",
"Floor*": "Floor 3",
"Room Name*": "Room 1",
"Room Type*": "AC",
"Location*": "Location 3",
"Device ID*": 26,
"Category*": "Soap Hygene",
"Dispenser Name*": "Dispenser 33",
"Type*": "Manual",
"Cartridge Type*": "Type 2",
"Date of installation": "2015-07-24T12:42:24 -06:-30",
"Contact Last Name": "Holland",
"Email Address": "thomas.boscher#gmail.com",
"Mobile Number with country code": "+1 (947) 491-2353",
"Description": "Description of device",
"Model": 32
}
]
I need data in below format, where it has each building details containing the wing and floor data
updateData = [{
building: 'Building A' ,
buildingData:[ {
wing: "Wing A",
wingData: [{
floor:'Floor 2',
floorData:[{
room:'Room 3',
roomData:[]
}]
}]
}]
}];
I tried :
js fiddle
But it fails. Need help. Thanks in advance.
From my understanding you want to groupBy in the following nested order:
Building ->> Wing ->> Floor ->> Room
You can try calling groupBy recursively (or looping through, up to you) by passing an array of the order of nested attribute you want to groupBy. Try this snippet below:
const nestedOrder = ['Building*', 'Wing*', 'Floor*', 'Room Name*']
function groupFilter (rawData, attrList) {
if (attrList.length == 0) return rawData
var currentAttr = _(attrList).first()
return _(rawData)
.chain()
.groupBy(currentAttr)
.map((list, attrName) => Object({
[currentAttr]: attrName,
[`${currentAttr}Data`]: groupFilter(list, _(attrList).rest())
}))
.value()
}
console.log(groupFilter(data, nestedOrder))
The raw data will then be compacted to the deepest nested attribute, in this case 'Room Name*', you can then write your custom filter to output what you want RoomData to hold.
Not sure if its the right way to do it, but if runtime isnt a big issue for you then I think you can make it work fine.
Hopefully this helps/works out for you.
My database structure looks like this (simplified):
{
"articles": {
"-uniqueId1": {
"title": "Article 1",
"category": "news"
},
"-uniqueId2": {
"title": "Article 2",
"category": "other"
},
"-uniqueId3": {
"title": "Article 3",
"category": "news"
},
"-uniqueId4": {
"title": "Article 4",
"category": "news"
}
},
"articlesByCategory": {
"news": {
"-uniqueId1": true,
"-uniqueId3": true,
"-uniqueId4": true
},
"other": {
"-uniqueId2": true
}
}
}
The query needs to fetch articles where a specific article's category isn't within. Does that make sense? Say, if uniqueId2 is of category "other", the query would only fetch articles within "news" and all other existing categories. But since the list may contain, say millions of articles, I have to be as specific as possible and not fetch articles that doesn't match this exact criteria. Therefor, a query like below would be ideal:
const ref = firebase.database().ref("articlesByCategory");
ref.orderByChild("-uniqueId2").equalTo(null).once("value", function(snapshot) {
console.log(snapshot.key);
});
Here I am searching for categories where a specific property is absent (where a property equals to null). This is explained here: Firebase: Query to exclude data based on a condition
However, doing a query like this requires me to index every article's unique id on "/articlesByCategory" in the security rules. But it would be unrealistic and non-optimal to dynamically add new article ids inside the ".indexOn" array as that would end up with millions of unique (auto-generated) ids:
{
"articles": {
".read": true,
".write": true
},
"articlesByCategory": {
".read": true,
".write": true,
".indexOn": ["-uniqueId1", "-uniqueId2", "-uniqueId3", "-uniqueId4"...] // List would be endless!
}
}
So how is this achievable? Why am I seeing these sorts of structures (inverted indexing) as ideal solutions everywhere on StackOverflow, but no one seems to tackle this issue?
Firebase only can query order statements on nodes with auto-generated ids, and when you've defined your own keys, firebase is unable to perform any sorting/ordering
The ideal way to generate keys is
firebase.getInstance().getReference("articles").push(myArticle);
this will result in a slightly different database structure like
{
"12dakj137_9": { // this is a auto-generated id
"article1": {
"title": "Article 1",
"category": "news"
},
"12asjh_123": {
"title": "Article 2",
"category": "other"
},...
}
Now firebase is able to order/sort and the way you do this is by
firebase.getInstance().child("articles").orderByChild("category").equalTo("other");
Sorry for the noob question but I am just getting started with Angular. I have this array declared in services.js:
var articles = [{
id: 1,
title: 'Article 1 Title',
intro: 'Article 1 Intro',
image: 'photo.jpg',
published: '27/10/2016',
text: 'Article 1 Text',
url: 'http://www.domain.com'
}, {
id: 2,
title: 'Article 2 Title',
intro: 'Article 2 Intro',
image: 'photo.jpg',
published: '27/10/2016',
text: 'Article 2 Text',
url: 'http://www.domain.com'
}];
Now that everything works fine in my Angular App I want to read this array from a JSON file that can be found, for example, at www.domain.com/articles.json and it looks like this:
{
"articles": [
{
"id": 1,
"title": "Article 1",
"intro": "Article 1 Intro",
"image": "image.png",
"published": "27/10/2016",
"text": "Article 1 Text",
"url": "http://www.domain.com/article-1"
},
{
"id": 2,
"title": "Article 2",
"intro": "Article 2 Intro",
"image": "image.png",
"published": "27/10/2016",
"text": "Article 2 Text",
"url": "http://www.domain.com/article-2"
}
]
}
How can I make this change?
To get the data of the file in your Angular app, you'll have to get the file's contents through an HTTP request. The easiest way to do this is by using the $http service.
Example (with relative url):
$http.get('/articles.json').then(function (response) {
var articles = response.data.articles;
// Do something with articles...
});
The callback function you're passing to the then method will be called when the HTTP request was successful. Note that your data will only be available in this callback function. Also don't forget to include a dependency to the $http service in your controller. ;)
I need to remove one of the 'answers' objects nested in the Doc below. I have the text of the answer I'm looking for. I don't have the index of the question OR the answer that I need to drill down into the arrays.
For example, I know that the text of the question I'm trying to drill down into is "This is a question." and the answer I want to delete is "Answer One".
How would you go about doing that?
Here's the sample MongoDB Doc:
(Quizzes have Questions; Questions have Answers)
{
name: "Sample Quiz",
categories: [
{ name: "testcategory1", description: "this is a test category" }
,{ name: "categoryTWO", description: "the second category" }
],
questions: [
{ text: "This is a question."
,answers: [
{text: "Answer One", affected_categories: "testcategory1"}
,{text: "Answer Two", affected_categories: "testcategory1"}
,{text: "Answer Three", affected_categories: "categoryTWO"}
]
}
,{ text: "This is the second question."
,answers: [
{text: "Mepho One", affected_categories: "testcategory1"}
,{text: "Answer Toodlydoo", affected_categories: "testcategory1"}
,{text: "Lehmen Sumtin", affected_categories: "categoryTWO"}
]
}
],
}
When I was deleting an item that was nested a single level down (in this case, a question), I was able to do it with a query like:
Quizzes.update(
{ _id: quizID, 'questions.text': questionText },
{ $pull: { questions: {text: questionText }}}
);
(as described here: http://docs.mongodb.org/manual/core/update/#Updating-ModifierOperations , in the section titled "Update an Element without Specifying Its Position")
I tried expanding that to something like:
Quizzes.update(
{ _id: quizID, 'answers.text': answerText },
{ $pull: { questions: {text: questionText {answers: {text: answerText }}}}}
);
but didn't have any luck.
Any ideas would be greatly appreciated.
Use the positional operator in combination with $pull condition:
> db.quizzes.update(
{_id:<quizID>, "questions.text":"This is the second question."},
{$pull:{ "questions.$.answers":{"text":"Answer Toodlydoo"}}}
);
The above works to remove the second answer from the second question.
I'm building a read only backbone app with data (sourced from a single static json file) that follows a building/campus structure of sort. That is:
[{
"name": "Building Name",
"id": "building",
"floors":[{
"name":"Ground Floor",
"rooms":[{
"name": "Room 1"
},
{
"name": "Room 2"
}]
},
{
"name":"First Floor",
"rooms":[{
"name": "Room 3"
},
{
"name": "Room 4"
}]
}]
},
{
"name": "Another Building",
"id": "building_2",
"floors":[{
"name":"Ground Floor",
"rooms":[{
}]
},
{
"name":"First Floor",
"rooms":[{
}]
}]
}]
I currently have a basic app set up that shows the list of buildings and floors for each building on a default '' route.
I would like to use the router so that APP/#buildingId/ shows the list of floors for a building with 'buildingId' and APP/#buildingId/#floorId shows the relevant list of rooms, etc.
JSBIN of my current code (without data.json) - http://jsbin.com/welcome/5850/edit
Lots of code is probably obsolete, but I was trying different ways to structure the models/collections. This app will never be more than read-only which is why I went with a static file.
Similar problem: How to use JSON to power interactive Backbone.js app
The solution presented doesn't use the Router at all.
Is this what you are asking for?:
// code simplified and no tested
App.Router = Backbone.Router.extend({
routes: {
"/APP/:buildingId/:floorId": "showRooms",
"/APP/:buildingId": "showFloors"
},
showRooms: function( buildingId, floorId ) {
// code to show the rooms
},
showFloors: function( buildingId ) {
// code to show the floors
},
});
Or am I missing something?