Failure to match strings(Arabic) in CHAI assertion library - chai

I have two arrays:
var array_one = [
{
"accountNo": "1",
"id" : 12,
"name" : "אוצר החייל - 14"
},
{
"accountNo": "1",
"id" : 13,
"name" : "china bank"
}
],
array_two = [
{
"accountNo": "1",
"id" : 12,
"name" : "אוצר החייל - 14"
},
{
"accountNo": "1",
"id" : 13,
"name" : "china bank"
}
];
Both the array's contents are same, but it fails to assert that the two array's have the same content. ie
array_one.should.be.deep.equal(array_two) returns false;
And the reason for failure being the matching of strings in Hebrew.
Cannot figure out a way to match Hebrew strings using CHAI assertion library.

Related

how to remove objects that have all keys with null values in dataweave?

I have this below payload and I want to remove object where all the keys have ALL empty values,
[
{
"Order" : "123",
"Product" : "456"
},
{
"Order" : "",
"Product" : ""
}
]
This is what the output should be like,
[
{
"Order" : "123",
"Product" : "456"
}
]
None of the posted solutions handle things like nested structures or arrays, so I thought I'd throw this recursive solution in the ring. This allows us to traverse the entire structure of the object until we hit the first non-null field.
%dw 2.0
output application/json
import everyEntry from dw::core::Objects
import every from dw::core::Arrays
var allFieldsNull = (obj: Any) ->
obj match {
case is Object -> obj everyEntry (allFieldsNull($))
case is Array -> (sizeOf(obj) == 0) or (obj every allFieldsNull($))
//case is Array -> false
else -> isEmpty(obj)
}
---
payload filter !allFieldsNull($)
If you wanted to consider an empty array as enough to keep the object since that technically isn't null, you would just need to comment out the case is Array line and uncomment the one below it.
Input:
[
{
"Order" : "123",
"Product" : "456"
},
{
"Order" : "",
"Product" : "",
"Address": {
"Field1": ""
},
"Test": [
{
"Order" : "",
"Product" : "",
"Address": {
"Field1": ""
}
}
]
},
{
"Order" : null,
"Product" : null,
"Address": {
"Field1": null
},
"Test": [
{
"Order" : null,
"Product" : null,
"Address": {
"Field1": "A value even in a deeply nested field means I show up"
}
}
]
}
]
output:
[
{
"Order": "123",
"Product": "456"
},
{
"Order": null,
"Product": null,
"Address": {
"Field1": null
},
"Test": [
{
"Order": null,
"Product": null,
"Address": {
"Field1": "A value even in a deeply nested field means I show up"
}
}
]
}
]
Would something like this work for you?
Input
[
{
"Order" : "123",
"Product" : "456"
},
{
"Order" : null,
"Product" : null
}
]
Script
%dw 2.0
output application/json
import * from dw::core::Objects
var valuesOfInputObjects = payload map { ($ takeWhile((value, key) -> value == null))}
---
payload -- valuesOfInputObjects
output
[
{
"Order": "123",
"Product": "456"
}
]
You can filter by a condition, using the everyEntry() function to see that not all values are empty.
%dw 2.0
output application/json
import * from dw::core::Objects
---
payload filter ($ someEntry (value, key) -> !isEmpty(value))

Remove Subdocument items with $pull

I'm trying to remove items from subdocuments using ExpressJS and Mongoose but it is only removing the first items, not the sub items.
So I want to remove "subitem 2" in the messages Array
This is the structure:
{
"_id" : ObjectId("5c4ee94b30ebd71cbed89a35"),
"title" : "Test",
"subitem" : [
{
"_id" : ObjectId("5c4ee95630ebd71cbed89a36"),
"title" : "Item 1",
"messages" : [
{
"_id" : ObjectId("5c4ee95f30ebd71cbed89a37"),
"type" : "single_article",
"date" : "Jan 28, 2019",
"title" : "subitem 1",
"text" : ""
}
]
},
{
"_id" : ObjectId("5c4ee96830ebd71cbed89a38"),
"title" : "item 2",
"messages" : [
{
"_id" : ObjectId("5c4ee96e30ebd71cbed89a39"),
"type" : "single_article",
"date" : "Jan 28, 2019",
"title" : "subitem 2",
"text" : ""
}
]
}
],
"__v" : 0
}
And this is the $pull method:
getController.deleteRec = function(req,res,collection){
var id = req.params.id;
console.log(id);
collection.updateOne({'subitem.messages._id': id}, {$pull: {'subitem.0.messages': {"_id": id}}}).
then(function(result){
console.log(result);
});
};
Now I know why it is only deleting the first item because I have "subitem.0.messages". How can I loop over this, so it can delete all items?
You can use $ as a wildcard index, removing all elements in the array matching your query like this:
{$pull: {'subitem.$.messages': {"_id": id}}}
if you want to remove multiple documents:
{$pull: {'subitem.$.messages': {"_id": {$in : [id, id2, id3...]}}}}

softlayer api: How to order Public Secondary IP Addresses when I ordering?

I want to order Public Secondary IP Addresses when I ordering. And How to submit these order infomation by softlayer api ?
To submit the order information described above, you need to fill the parameter "itemCategoryQuestionAnswers" during the order, that parameter can be found in datatypes like Container_Product_Order_Virtual_Guest and Container_Product_Order_Hardware_Server
Below is an example in JSON for REST:
"itemCategoryQuestionAnswers":[
{
"answer": "2",
"categoryId": 14,
"questionId": 14
},
{
"answer": "4",
"categoryId": 14,
"questionId": 15
}
]
The example above belongs to the first two questions in the form. As you can see, it is necessary to know the id of categoryId and questionId parameters. Follow the steps below.
CategoryID
As greyhoundforty comment you, the link SoftLayer API: Ordering Subnet
is a good starting point. On that page mcruz shows how to execute the method Product_Item_Category::getSubnetCategories. The method returns some thing like this:
{
"categoryCode": "global_ipv6",
"id": 331,
"name": "Global IPv6",
"quantityLimit": 0
},
{
"categoryCode": "sec_ip_addresses",
"id": 14,
"name": "Public Secondary IP Addresses",
"quantityLimit": 0
},
On this case the categoryId is 14 for category "Public Secondary IP Addresses".
QuestionID
To get all questions related to the category "sec_ip_addresses" you can use the method Product_Item_Category::getQuestions or Product_Item_Category::getQuestionReferences. On this case I'll show you how execute getQuestionReferences method:
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Product_Item_Category/14/getQuestionReferences?objectMask=[question]
Method: GET
It should returns something like this:
{
"id": 61,
"questionId": 14,
"required": true,
"question": {
"description": "The number of IP addresses expected to be used within the next 30 days.",
"id": 14
}
},
{
"id": 62,
"questionId": 15,
"required": true,
"question": {
"description": "The number of IP addresses expected to be used within the next 12 months.",
"id": 15
}
},
Now you can know the questionId of each question in the form.
Order Virtual Guest with a Secondary Public Ip Address
Below is an example in REST to order a virtual guest with a secondary ip address and two first questions in the form.
Note: Don't forget change [username], [apikey], prices, and other ids with your own data
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder
Method: POST
Body JSON:
{
"parameters":[
{
"complexType": "SoftLayer_Container_Product_Order_Virtual_Guest",
"packageId": 46,
"location": "AMSTERDAM",
"quantity": 1,
"prices":[
{"id":14640},
{"id":11644},
{"id":9205},
{"id":22272},
{"id":52231},
{"id":21},
{"id":2202},
{"id":13945},
{"id":55},
{"id":57},
{"id":58},
{"id":420},
{"id":418},
{"id":22}
],
"virtualGuests":[
{
"hostname": "test",
"domain": "example.com"
}
],
"itemCategoryQuestionAnswers":[
{
"answer": "2",
"categoryId": 14,
"questionId": 14
},
{
"answer": "4",
"categoryId": 14,
"questionId": 15
}
]
}
]
}
About your REST structure
I don't know what REST client you are using, but I was able to reproduce your issue in a RESTclient from firefox, in other REST clients like Insomnia I'm just getting errors.
Basically, you are getting empty response because your JSON structure have some mistakes. First, all data in body needs to be into "parameters" object, please review the example above. Second, value of "sshKeyIds" needs to be into double quotes because it is an string. Finally, I recommend you put all objects and string values into double quotation mark due to it is the JSON standard format, you can verify this information in jQuery.parseJSON single quote vs double quote and http://www.json.org/.
Important: Before to use placeOrder method I recommend you to execute verifyOrder first. When, you are ready to order just change verifyOrder by placeOrder in the URL request.
I modified your request as following
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder
Method: POST
Body in JSON format:
{
"parameters":[
{
"complexType" : "SoftLayer_Container_Product_Order_Virtual_Guest",
"location" : "449604",
"packageId" : 46,
"quantity" : 1,
"useHourlyPricing" : true,
"virtualGuests" : [
{
"domain" : "aaa.com",
"hostname" : "sshkey_07"
}
],
"sshKeys" : [
{ "sshKeyIds" : ["620913L"] }
],
"prices" : [
{"id" : 1644 },
{"id" : 2202 },
{"id" : 2259 },
{"id" : 273 },
{"id" : 1640 },
{"id" : 17442},
{"id" : 905 },
{"id" : 21 },
{"id" : 57 },
{"id" : 55 },
{"id" : 58 },
{"id" : 420 },
{"id" : 418 },
{"id" : 22 },
{"id" : 1800 }
],
"itemCategoryQuestionAnswers" : [{
"answer" : "4",
"questionId" : 14,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "4",
"questionId" : 15,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "aaaa",
"questionId" : 16,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "allesa",
"questionId" : 9,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "product manager",
"questionId" : 10,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "xxx#mail.com",
"questionId" : 11,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "xxxxxxxxx",
"questionId" : 12,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "1",
"questionId" : 13,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}
]
}
]
}
Let me know if you have any doubt or need further assistance.

transform json to work with ember-data

When visiting my test api it returns a json in the following format to my ember application:
{
{ "1" : {
"id" : "1",
"name" : "test1",
"amount" : "12,90"
}
},
{ "2" : {
"id" : "2",
"name" : "test2",
"amount" : "9,30"
}
},
}
My Model for the data is looks like this:
var budget = DS.Model.extend({
amount: DS.attr('string'),
name: DS.attr('string')
});
export default budget;
With the given JSON my hbs template render nothing as no model was set by ember data...
The format i would expect looks like the following example:
{
[{
"id" : "1",
"name" : "test1",
"amount" : "12,90"
},
{
"id" : "2",
"name" : "test2",
"amount" : "9,30"
}]
}
Is there a possibility to transform the upper json to the json i expected? I am using the Ember App Kit for my application. As API i want to use SLIM Php Framework with NotORM.
EmberData expects the JSON format returned by your API to be in this format for all budgets:
{
"budgets":
[{
"id" : "1",
"name" : "test1",
"amount" : "12,90"
},
{
"id" : "2",
"name" : "test2",
"amount" : "9,30"
}]
}
And for a single budget, it expects:
{
"budget": { "id": 2, "name": "test", "amount": "9,30" }
}
If you want to override this by creating your own extractSingle and extract methods in the BudgetSerializer. You can find more info here
App.BudgetSerializer = DS.RESTSerializer.extend({
// First, restructure the top-level so it's organized by type
extractSingle: function(store, type, payload, id, requestType) {
// do your transformation
return this._super(store, type, payload, id, requestType);
}
});

Iterative data store in extjs

I want to create hierarchical tabs ( they could be up to n level) using ext-js 4.1. I am trying to create a store as below, for the tab hierarchy. so I can use a generic method to create tabs. How can i iterate through this store structure to create hierarchical tabs?
Hope the structure below is readable :-) showing each level clearly and the depth for the tabs.
"toptab1": [{
"id" : 1000
"name" : "coo",
"child": [{
"id": 1 ,
"name": "foo" ,
"child": [{
"id" : 11 ,
"name": "roo" ,
"child": [{
"id" : 111,
"name" : "hoo"
},
{
"id: 112,
"name": "poo"
}]
},
{
"id" : 12 ,
"name" : "too"
}]
},
{
"id" : 2,
"name" : "woo",
"child" :[{
"id": 21,
"name" : "soo"
"child" : [{
"id" : 211,
"name" : "boo"
}]
},
{
"id" : 22,
"name" : "doo"
}]
},
{
"id" : 3,
"name": "zoo"
}];
I would create a model to store the information about your tabs.
Then use a TreeStore to store them in the correct hierarchy.
Then you can do something like.
var topLevel = this.getTabStore().getRootNode();
topLevel.cascadeBy(function(tab) {
//Do what you want with each tab here.
});
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.TreeStore-method-getRootNode
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.NodeInterface-method-cascadeBy