Related
So when testing one of my reducers in a Preact(not much different to React while testing with JEST) based project, I got bumped into this issue:
Following output comes up when running jest test -
● should setup
expect(received).toEqual(expected)
Expected value to equal:
{"ID": Any<String>, "active": true, "data": Any<Array>}
Received:
{"ID": "BysnEuMlm", "active": true, "data": [{"ID": "Hy7wMAz1lm", "code": "dat.fle", "label": "CRES/datum14.cdata", "name": "File", "status": "READY", "value": {"format": "cdata", "name": "datum14.cdata", "path": "CRES"}}, {"ID": "rkB7RMkeX", "code": "prp.kcv", "label": "3 folds", "name": "k-Fold Cross-Validation", "status": "READY", "value": "3"}, {"ID": "ByCmRfygQ", "code": "ats", "label": undefined, "name": " Best First + Cfs Subset Eval", "status": "READY", "value": {"evaluator": {"name": "CfsSubsetEval"}, "search": {"name": "BestFirst", "options": ["-D", "1", "-N", "5"]}, "use": true}}, {"ID": "HkmVAM1l7", "code": "lrn", "label": undefined, "name": "Naive Bayes", "status": "READY", "value": {"label": "Naive Bayes", "name": "bayes.NaiveBayes", "use": true}}], "output": {"format": "pipeline", "name": "jestReact.cpipe", "path": "/home/rupav/opensource/candis/CRES"}}
Difference:
- Expected
+ Received
Object {
- "ID": Any<String>,
+ "ID": "BysnEuMlm",
"active": true,
- "data": Any<Array>,
+ "data": Array [
+ Object {
+ "ID": "Hy7wMAz1lm",
+ "code": "dat.fle",
+ "label": "CRES/datum14.cdata",
+ "name": "File",
+ "status": "READY",
+ "value": Object {
+ "format": "cdata",
+ "name": "datum14.cdata",
+ "path": "CRES",
+ },
+ },
+ Object {
+ "ID": "rkB7RMkeX",
+ "code": "prp.kcv",
+ "label": "3 folds",
+ "name": "k-Fold Cross-Validation",
+ "status": "READY",
+ "value": "3",
+ },
+ Object {
+ "ID": "ByCmRfygQ",
+ "code": "ats",
+ "label": undefined,
+ "name": " Best First + Cfs Subset Eval",
+ "status": "READY",
+ "value": Object {
+ "evaluator": Object {
+ "name": "CfsSubsetEval",
+ },
+ "search": Object {
+ "name": "BestFirst",
+ "options": Array [
+ "-D",
+ "1",
+ "-N",
+ "5",
+ ],
+ },
+ "use": true,
+ },
+ },
+ Object {
+ "ID": "HkmVAM1l7",
+ "code": "lrn",
+ "label": undefined,
+ "name": "Naive Bayes",
+ "status": "READY",
+ "value": Object {
+ "label": "Naive Bayes",
+ "name": "bayes.NaiveBayes",
+ "use": true,
+ },
+ },
+ ],
+ "output": Object {
+ "format": "pipeline",
+ "name": "jestReact.cpipe",
+ "path": "/home/rupav/opensource/candis/CRES",
+ },
}
Following is the test case:
test('should setup ', () => {
const state = documentProcessor(
undefined,
{
type: ActionType.Asynchronous.READ_SUCCESS,
payload: dokuments.active
})
// expect(state.active.ID).toEqual(expect.any(String)) - Test case passes iff I run this test with this command only.
expect(state.active).toEqual({
data: expect.any(Array),
active: true,
ID: expect.any(String),
})
})
Since state gets changed while calling that reducer, I needed to use expect.any function, but as per the output, although types are same, test is not getting passed.
Rather in expected its showing up Any<String>.
expect.toEqual checks for equality of state.active in your case. To achieve what you want, you have to make multiple expect statements:
expect(state.active.active).toEqual(true)
expect(state.active.data).toEqual(expect.any(Array))
expect(state.active.ID).toEqual(expect.any(String))
You can use toMatchObject:
expect(state.active).toMatchObject({
active: true,
data: expect.any(Array),
ID: expect.any(String)
});
See more examples in official documentation: https://jestjs.io/docs/en/expect#tomatchobjectobject
I have been working on Salesforce to Docusign Integration. I have multiple documents with Specific signer for each document i.e. one document should be send to one specific user, not all. But I want to do this in one Rest API call to docusign! The documents are stored in Accounts attachments which are created dynamically for each user which are specific to user.
I have been trying this using CompositeTemplates, what I am doing is, adding document and Signer in each inlineTemplate, But it is sending all the documents to all the users in sequence.
I don't want to show all document to all the user, they should see only document specific to them.
Below is the JSON which I am sending:
{
"status": "Sent",
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"roleName": "Signer 1",
"recipientId": "1",
"name": "Anmol",
"email": "test#gmail.com"
}
]
},
"envelope": {
"status": "Sent",
"emailSubject": "test1"
},
"documents": [
{
"name": "Doc 1",
"fileExtension": "doc",
"documentId": "1",
"documentBase64": "JVBERi0xLjQKJeLjz9MKN58HkeCg8gJEomcWGJdEFtOYYklsXV2dlT6R6Owc+FXFMNSlpckKM6M/ioTGkROkEjkxBDrgthySkvMxGpQJYapHKWwcwXtRU9GCg=="
}
],
"customFields": {
"listCustomFields": [
{
"value": "00128000003tPKB",
"show": "true",
"required": "false",
"name": "Account",
"fieldId": "1",
"configurationType": "salesforce"
}
]
}
}
],
"compositeTemplateId": "1"
},
{
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"roleName": "Signer 2",
"recipientId": "1",
"name": "Anmol",
"email": "test1#gmail.com"
}
]
},
"envelope": {
"status": "Sent",
"emailSubject": "test2"
},
"documents": [
{
"name": "Doc 2",
"fileExtension": "doc",
"documentId": "2",
"documentBase64": "JVBERi0xLjYNJeLjz9MNCjEzIDAgb2JqDTw8L0xpbmVhcmlmDQoxMTYNCiUlRU9GDQo="
}
],
"customFields": {
"listCustomFields": [
{
"value": "00128000003tPKB",
"show": "true",
"required": "false",
"name": "Account",
"fieldId": "1",
"configurationType": "salesforce"
}
]
}
}
],
"compositeTemplateId": "2"
}
]
}
Any doc, code or suggestions about the approach I am following for this will be very helpful.
To do it in a single api call, specify the excludedDocuments property in the EnvelopeCreate request
excludedDocuments: Specifies the documents that are not visible to the recipient. Document Visibility must be enabled for the account and the enforceSignerVisibility property must be set to true for the envelope to use this.
Here is a sample Json for POST /v2/accounts/{accountId}/envelopes
Note: I have combined both your inline templates into a single inlineTemplate.
{
"status": "Sent",
"emailSubject": "Email Subject to all recipients",
"emailBlurb": "Email body to all recipients",
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"recipientId": "1",
"name": "recipient one",
"email": "recipientone#dsxtr.com",
"excludedDocuments": [ "2" ]
},
{
"recipientId": "2",
"name": "recipient two",
"email": "recipienttwo#dsxtr.com",
"excludedDocuments": [ "1" ]
}
]
},
"documents": [
{
"name": "Doc 1",
"fileExtension": "doc",
"documentId": "1",
"documentBase64": ""
},
{
"name": "Doc 2",
"fileExtension": "doc",
"documentId": "2",
"documentBase64": ""
}
]
}
],
"compositeTemplateId": "1"
}
]
}
I believe you're looking for documentVisibility on the create envelope call.
There are other supporting documentVisibility endpoints here.
I am new to the Sugar CRM 6.5 API. I am having trouble getting my url to post data to the leads module in Sugar. Here is the posting url,
https://yoursite/service/v4_1/rest.php?method=set_entry&input_type=JSON&response_type=JSON&rest_data={"name_value_list":{"last_name":"Peter","status":"New","email1":"test#test.com","lead_source":"test"},"module_name":"Leads"}
Here is my response,
{
"id": "459bf4a2-0b3b-5857-feb5-56fe81e621eb",
"entry_list": {
"modified_by_name": {
"name": "modified_by_name",
"value": "admin"
},
"id": {
"name": "id",
"value": "459bf4a2-0b3b-5857-feb5-56fe81e621eb"
},
"name": {
"name": "name",
"value": " "
},
"date_entered": {
"name": "date_entered",
"value": "2016-04-01 14:10:12"
},
"date_modified": {
"name": "date_modified",
"value": "2016-04-01 14:10:12"
},
"modified_user_id": {
"name": "modified_user_id",
"value": "1"
},
"created_by": {
"name": "created_by",
"value": "1"
},
"deleted": {
"name": "deleted",
"value": 0
},
"full_name": {
"name": "full_name",
"value": " "
},
"do_not_call": {
"name": "do_not_call",
"value": false
},
"converted": {
"name": "converted",
"value": false
},
"lead_source": {
"name": "lead_source",
"value": "Web Site"
},
"status": {
"name": "status",
"value": "New"
},
"jjwg_maps_lat_c": {
"name": "jjwg_maps_lat_c",
"value": 0
},
"jjwg_maps_lng_c": {
"name": "jjwg_maps_lng_c",
"value": 0
}
}
}
When I view the leads, I get a blank record created. Any idea's, Thanks
The format of name_value_list is as follow:
{
"name_value_list":
"full_name": {"name": "full_name", "value": "John"}
}
I have a dynamically changing array based on another code and I'm trying to retrieve specific data from the same.
Here is a sample of one dynamically generated array under $scope.filtereditem:
[{
"active": true,
"createdAt": "2015-10-05T20:19:58.264Z",
"desc": "With arugula, smoked almonds & chipotle vinaigrette",
"flavors": [{
"active": true,
"name": "Chocolate",
"price": 8
}, {
"active": false,
"name": "Strawberry",
"price": 8
}, {
"active": false,
"name": "Hazelnut",
"price": 8
}, {
"active": false,
"name": "Mint",
"price": 8
}],
"img": "https://signsrestaurant.ca/wp-content/uploads/2015/09/Watermelon-Quinoa-Jimaca-Salad.jpg",
"name": "Watermelon Quinoa Jicama Salad (<span class=\"vegan\">VE</span>, <span class=\"gfree\">GF</span>, <span class=\"dfree\">DF</span>)",
"objectId": "x1zpkWmvmP",
"price": 14,
"qty": 1,
"sides": [{
"active": false,
"name": "Soup"
}, {
"active": false,
"name": "Salad"
}, {
"active": false,
"name": "Fries"
}],
"sizes": [{
"active": false,
"name": "Small",
"price": 5
}, {
"active": true,
"name": "Medium",
"price": 10
}, {
"active": false,
"name": "Large",
"price": 15
}],
"type": "Soup",
"updatedAt": "2015-10-21T18:09:37.499Z"
}, {
"active": true,
"createdAt": "2015-10-05T20:35:01.363Z",
"desc": "Buffalo mozzarella, tomato, marinated artichoke hearts, black olives, pesto & balsamic drizzle",
"flavors": [{
"active": false,
"name": "Vanilla",
"price": 8
}, {
"active": false,
"name": "Almond",
"price": 8
}, {
"active": true,
"name": "Hazelnut",
"price": 8
}, {
"active": false,
"name": "Caramel",
"price": 8
}],
"img": "https://signsrestaurant.ca/wp-content/uploads/2015/09/Mediterranean-Salad.jpg",
"name": "Mediterranean Salad (<span class=\"veg\">V</span>, <span class=\"gfree\">GF</span>)",
"objectId": "nI5VSpdBUn",
"price": 15,
"qty": 2,
"sides": [{
"active": false,
"name": "Soup"
}, {
"active": false,
"name": "Salad"
}, {
"active": false,
"name": "Fries"
}],
"sizes": [{
"active": false,
"name": "Small",
"price": 0
}, {
"active": true,
"name": "Medium",
"price": 5
}, {
"active": false,
"name": "Large",
"price": 10
}],
"type": "Salad",
"updatedAt": "2015-10-21T18:09:33.422Z"
}]
That is just a sample and the array changes dynamically based on another code. What I wish to achieve is to retrieve certain data in the form of a scope element, let's name it as $scope.filteredmenu
This is where I'm stuck at. Here is what I have so far for this:
$scope.filteredmenu = function() {
var order = " ";
var side = " ";
angular.forEach($scope.filtereditem, function(item) {
var flavor = " ";
var size = " ";
order += item.name + "Qty: " + item.qty + " , ";
side += "Side: " + item.type + " , ";
angular.forEach(item.flavors, function(option) {
if (option && option.active) {
flavor += "Flavor: " + option.name + " , ";
}
});
angular.forEach(item.sizes, function(option) {
if (option && option.active) {
size += "Size: " + option.name + " , ";
}
});
menuorder += order + side + size + flavor;
});
return menuorder;
};
Basically, I need the output in this format:
For each item,
'item.name' Qty: 'item.qty', Side: 'item.type', Flavor (whichever is active): option.name (in item.flavors), Size (whichever is active): option.name (in item.sizes)
Eventually, I'm trying to send the result $scope.filteredmenu via an email API. I'm not sure what I'm doing wrong. Any help with this code would be much appreciated.
There were some syntax errors:
var output = function() {
var order = " ";
var side = " ";
//Not defined
var menuorder = '';
angular.forEach($scope.filtereditem, function(item) {
var flavor = " ";
var size = " ";
order += item.name + "Qty: " + item.qty + " , ";
//plus sign was missing
side += "Side: " + item.type + " , ";
angular.forEach(item.flavors, function(option) {
if (option && option.active) {
flavor += "Flavor: " + option.name + " , ";
}
});
angular.forEach(item.sizes, function(option) {
if (option && option.active) {
size += "Size: " + option.name + " , ";
}
});
menuorder += order + side + size + flavor;
});
return menuorder;
}
$scope.filteredmenu = output();
here is the working JSFiddler https://jsfiddle.net/hefc5ewe/
I need help in parsing the JSON file using HIVE. This file has nested arrays, when i tried to parse the file or query using the HiVE UDF i can drill down just to one level. Then next level arrays were coming up Null in my result. I have given the example below. File has couple of sections (array ), but below given one is most complex one. I tried to use get_json_object to parse, i was able to get data just one level, it didn't pull the nested arrays at all. It would be helpful if someone guide me in parsing the nested json arrays
"section": {
"moodCode": "xxx",
"classCode": "xxx",
"templateId": {
"root": "2.xx.840"
},
"code": {
"codeSystemName": "LOINC",
},
"title": "problems",
"text": {
"mediaType": "text/x-hl7-text+xml",
"list": [{
"caption": "Recorded",
"item": {
"ID": "pr101",
"content": [{
"ID": "pr101-desc",
"text": "Salm"
},
"003.1"],
"text": " "
},
"text": " "
},
{
"caption": "Reported",
"item": "None Reported",
"text": " "
}],
"text": " "
},
"entry": {
"typeCode": "DRIV",
"act": {
"moodCode": "EVN",
"classCode": "ACT",
"templateId": [{
"root": "2.16.840.1.0.1.27"
},
{
"root": "1.3.6.1.4..1"
},
{
"root": "1.3.6.1.4.4.5.2"
}],
"id": {
"root": "068fd4d4-dfa2-48190768f"
},
"code": {
"nullFlavor": "NA"
},
"statusCode": {
"code": "completed"
},
"effectiveTime": {
"low": {
"value": "20140428144743+0100"
},
"high": {
"value": "20140428144743+0100"
},
"text": " "
},
"entryRelationship": {
"typeCode": "SUBJ",
"observation": {
"moodCode": "EVN",
"classCode": "OBS",
"templateId": [{
"root": "2.16.840.1.20.1.28"
},
{
"root": "1.3.6.1.4.1.5.3.1.4.5"
}],
"id": {
"root": "fa34b4da4dbb-b090-01bd4d6ef62b"
},
"code": {
"codeSystemName": "SNOMED CT",
"code": "282009",
"displayName": "diagnosis",
"codeSystem": "2.16.840.1.6.96"
},
"text": {
"reference": {
"value": "#pr101"
},
"text": " "
},
"statusCode": {
"code": "completed"
},
"effectiveTime": {
"low": {
"value": "20140428144743+0100"
},
"high": {
"nullFlavor": "UNK"
},
"text": " "
},
"value": {
"codeSystemName": "ICD-9",
"xsi:type": "CD",
"code": "003.1",
"displayName": "Sla sia",
"codeSystem": "2.16.840.1.103",
"originalText": {
"reference": {
"value": "#pr101-desc"
},
"text": " "
},
"text": " "
},
"entryRelationship": {
"typeCode": "REFR",
"observation": {
"moodCode": "EVN",
"classCode": "OBS",
"templateId": [{
"root": "2.16.840..1.50"
},
{
"root": "2.16.8410.20.1.57"
},
{
"root": "1.3.6.13.1.4.1.1"
}],
"code": {
"codeSystemName": "LOINC",
"code": "33999-4",
"displayName": "Status",
"codeSystem": "2.16.840.1.113883.6.1"
},
"statusCode": {
"code": "completed"
},
"value": {
"codeSystemName": " CT",
"xsi:type": "CE",
"code": "55563",
"displayName": "active",
"codeSystem": "2.16.8406.96"
},
"text": " "
},
"text": " "
},
"text": " "
},
"text": " "
},
"text": " "
},
"text": " "
},
"text": " "
},
"text": " "
},
When i used get_json_object below mentioned data came up null.
"title": "problems",
"text": {
"mediaType": "text/x-hl7-text+xml",
"list": [{
"caption": "Recorded",
"item": {
"ID": "pr101",
"content": [{
"ID": "pr101-desc",
"text": "Salm"
},
"003.1"],
updated-you have to format your JSON file in such a way that each record should be in just one line, like
'{"section":{"moodCode":"xxx","classCode":"xxx","templateId":{"root":"2.xx.840"},"code":{"codeSystemName":"LOINC"},"title":"problems","text":{"mediaType":"text/x-hl7-text+xml","list":[{"caption":"Recorded","item":{"ID":"pr101","content":[{"ID":"pr101-desc","text":"Salm"},"003.1"],"text":" "},"text":" "},{"caption":"Reported","item":"None Reported","text":" "}],"text":" "},"entry":{"typeCode":"DRIV","act":{"moodCode":"EVN","classCode":"ACT","templateId":[{"root":"2.16.840.1.0.1.27"},{"root":"1.3.6.1.4..1"},{"root":"1.3.6.1.4.4.5.2"}],"id":{"root":"068fd4d4-dfa2-48190768f"},"code":{"nullFlavor":"NA"},"statusCode":{"code":"completed"},"effectiveTime":{"low":{"value":"20140428144743+0100"},"high":{"value":"20140428144743+0100"},"text":""},"entryRelationship":{"typeCode":"SUBJ","observation":{"moodCode":"EVN","classCode":"OBS","templateId":[{"root":"2.16.840.1.20.1.28"},{"root":"1.3.6.1.4.1.5.3.1.4.5"}],"id":{"root":"fa34b4da4dbb-b090-01bd4d6ef62b"},"code":{"codeSystemName":"SNOMEDCT","code":"282009","displayName":"diagnosis","codeSystem":"2.16.840.1.6.96"},"text":"","statusCode":{"code":"completed"},"effectiveTime":{"low":{"value":"20140428144743+0100"},"high":{"nullFlavor":"UNK"},"text":""},"value":{"codeSystemName":"ICD-9","xsi: type":"CD","code":"003.1","displayName":"Slasia","codeSystem":"2.16.840.1.103","originalText":{"reference":{"value":"#pr101-desc"},"text":""},"text":""},"entryRelationship":{"typeCode":"REFR","observation":{"moodCode":"EVN","classCode":"OBS","templateId":[{"root":"2.16.840..1.50"},{"root":"2.16.8410.20.1.57"},{"root":"1.3.6.13.1.4.1.1"}],"code":{"codeSystemName":"LOINC","code":"33999-4","displayName":"Status","codeSystem":"2.16.840.1.113883.6.1"},"statusCode":{"code":"completed"},"value":{"codeSystemName":"CT","xsi: type":"CE","code":"55563","displayName":"active","codeSystem":"2.16.8406.96"},"text":""},"text":""}},"text":""},"text":""},"text":""}},"text":""}'
Now create a table treating the entire string as one column
'drop table json_test;
create external table json_test(value string)
LOCATION 'path'; '
you can lateral view json_tuple to get the fields you need now.
'set hive.cli.print.header=true;
SELECT c.moodCode,c.classCode,d.root,c.title,e.mediaType FROM json_test a LATERAL VIEW json_tuple(a.value, 'section') b AS section LATERAL VIEW json_tuple(b.section,'moodCode','classCode','templateId','title','text')c
AS moodCode,classCode,templateId,title,text LATERAL VIEW json_tuple(c.templateId,'root')d
AS root LATERAL VIEW json_tuple(c.text,'mediaType')e AS mediaType;'
result
'c.moodcode|c.classcode|d.root |c.title |e.mediatype
xxx | xxx |2.xx.840 |problems|text/x-hl7-text+xml'