postman collection runner pass an array of values in data file - testing

I have an api definition like this :
{
"myVar01": "{{myVar01}}",
"myVar02": "{{myVar02}}",
"myVar03": "{{<myVar03>}}",
"myVar04": {
"myVar04-01": "{{myVar04-01}}",
"myVar04-02": "{{myVar04-02}}",
"myDataArray": [
{
"myArrayVar01": "{{myArrayVar01}}",
"myArrayVar02": "{{myArrayVar02}}",
"myArrayVar03": "{{myArrayVar03}}",
"myArrayVar04": "{{myArrayVar04}}",
"myArrayVar05": "{{myArrayVar05}}"
},
{
"myArrayVar01": "{{myArrayVar01}}",
"myArrayVar02": "{{myArrayVar02}}",
"myArrayVar03": "{{myArrayVar03}}",
"myArrayVar04": "{{myArrayVar04}}",
"myArrayVar05": "{{myArrayVar05}}"
},
.....
]
]
}
}
I have to create a data file to run several tests on this api, the question is how can I define my data file to create data for "myDataArray" structure?

Ok, finally I found the problem.
The API definition has to be like this :
{
"myVar01": "{{myVar01}}",
"myVar02": "{{myVar02}}",
"myVar03": "{{myVar03}}",
"Struct": {
"myVar04-01": "{{myVar04-01}}",
"myVar04-02": "{{myVar04-02}}",
"myDataArray": {{localVarDataAray}}
}
}
The json file has to be like that :
[
{
"myVar01": "0123456789012345678901234567890123456789",
"myVar02": "0123456789012345678901234567890123456789",
"myVar03": "0123456789012345678901234567890123456789",
"myVar04-01": "0123456789012345678901234567890123456789",
"myVar04-02": "0123456789012345678901234567890123456789",
"myDataArray":[{
"myArrayVar01": 1,
"myArrayVar02": 1,
"myArrayVar03": 1,
"myArrayVar04": 4,
"myArrayVar05": 0
},{
"myArrayVar01": 2,
"myArrayVar02": 2,
"myArrayVar03": 2,
"myArrayVar04": 4,
"myArrayVar05": 0
}]
},
{
"myVar01": "0123456789012345678901234567890123456789",
"myVar02": "0123456789012345678901234567890123456789",
"myVar03": "0123456789012345678901234567890123456789",
"myVar04-01": "0123456789012345678901234567890123456789",
"myVar04-02": "0123456789012345678901234567890123456789",
"myDataArray":[{
"myArrayVar01": 1,
"myArrayVar02": 1,
"myArrayVar03": 1,
"myArrayVar04": 4,
"myArrayVar05": 0
},{
"myArrayVar01": 2,
"myArrayVar02": 2,
"myArrayVar03": 2,
"myArrayVar04": 4,
"myArrayVar05": 0
}]
}
]
And I had to define a pre-request sctipt like that :
let localVarDataAray="";
pm.variables.set('localVarDataAray',JSON.stringify(data.myDataArray));
And it works fine

Related

Ramda - how to use multiple functions on the same data structure

I am trying to use multiple ramda functions on this example:
const data = {
"tableItems": [
{
"id": 1,
"name": "1",
"startingPoint": true,
"pageNumber": 15,
"nodes": [
100,
200
]
},
{
"id": 2,
"name": "2",
"startingPoint": true,
"pageNumber": 14,
"nodes": [
300,
400
]
}
],
"nodes": [
{
"id": 100,
"tableItemId": 1,
"content": "test"
},
{
"id": 200,
"tableItemId": 1,
"content": "test"
},
{
"id": 300,
"tableItemId": 2,
"content": "test"
},
{
"id": 400,
"tableItemId": 2,
"content": "test"
}
]
}
I am trying to create new JSON which should look like this where nodes array should be filled with another ramda function:
const newJSON = [
{
"id": "chapter-1",
"name": "2",
"nodes": []
},
{
"id": "chapter-2",
"name": "1",
"nodes": []
}
]
I started with:
let chapters = [];
let chapter;
const getChapters = R.pipe(
R.path(['tableItems']),
R.sortBy(R.prop('pageNumber')),
R.map((tableItem) => {
if(tableItem.startingPoint) {
chapter = {
id: `chapter-${chapters.length+1}`,
name: tableItem.name,
nodes: []
}
chapters.push(chapter);
}
return tableItem
})
)
But how to combine getNodes which needs access to the whole scope of data?
I tried pipe but something is not working.
Example:
const getNodes = R.pipe(
R.path(['nodes']),
R.map((node) => {
console.log(node)
})
)
R.pipe(
getChapters,
getNodes
)(data)
Any help would be appreciated.
We could write something like this, using Ramda:
const {pipe, sortBy, prop, filter, map, applySpec, identity, propEq, find, __, addIndex, assoc} = R
const transform = ({tableItems, nodes}) => pipe (
filter (prop ('startingPoint')),
sortBy (prop ('pageNumber')),
map (applySpec ({
name: prop('name'),
nodes: pipe (prop('nodes'), map (pipe (propEq ('id'), find (__, nodes))), filter (Boolean))
})),
addIndex (map) ((o, i) => assoc ('id', `chapter-${i + 1}`, o))
) (tableItems)
const data = {tableItems: [{id: 1, name: "1", startingPoint: true, pageNumber: 15, nodes: [100, 200]}, {id: 2, name: "2", startingPoint: true, pageNumber: 14, nodes: [300, 400]}], nodes: [{id: 100, tableItemId: 1, content: "test"}, {id: 200, tableItemId: 1, content: "test"}, {id: 300, tableItemId: 2, content: "test"}, {id: 400, tableItemId: 2, content: "test"}]}
console .log (transform (data))
.as-console-wrapper {max-height: 100% !important; top: 0}
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.min.js"></script>
First we filter the tableItems to include only those with startingPoint of true, then we sort the result by pageNumber. Then for each, we create name and nodes elements, based on the original data and on a function that maps the node values to the element in the initial nodes property. Finally, for each one, we add the chapter-# id element using addIndex (map).
This works, and is not horrible. It would take a fair bit of work to make this entirely point-free, I believe. And I don't find it worthwhile... especially because this Ramda version doesn't add anything to a simpler vanilla implementation:
const transform = ({tableItems, nodes}) =>
tableItems
.filter (x => x .startingPoint)
.sort (({pageNumber: a}, {pageNumber: b}) => a - b)
.map (({name, nodes: ns}, i) => ({
id: `chapter-${i + 1}`,
name,
nodes: ns .map (n => nodes .find (node => node .id == n)) .filter (Boolean)
}))
const data = {tableItems: [{id: 1, name: "1", startingPoint: true, pageNumber: 15, nodes: [100, 200]}, {id: 2, name: "2", startingPoint: true, pageNumber: 14, nodes: [300, 400]}], nodes: [{id: 100, tableItemId: 1, content: "test"}, {id: 200, tableItemId: 1, content: "test"}, {id: 300, tableItemId: 2, content: "test"}, {id: 400, tableItemId: 2, content: "test"}]}
console .log (transform (data))
.as-console-wrapper {max-height: 100% !important; top: 0}
This works similarly to the above except that it assigns the id at the same time as name and nodes.
I'm a founder of Ramda and remain a big fan. But it doesn't always add anything to vanilla modern JS.
You can use a curried function. Because the pipe will always pipe the result of the previous function call into the next function. You can use R.tap if you want to step over.
However, I guess you want to have the data object and the output of the previous function call both in your getNodes function. In that case you can use a curried function, where you pass the response of the previous function as last parameter.
const getNodes = R.curryN(2, function(data, tableItemList){
console.log(tableItemList) // result of previous function call
return R.pipe(
R.path(['nodes']),
R.map((node) => {
console.log('node:', node);
})
)(data)
})
And use it like:
R.pipe(
getChapters,
getNodes(data)
)(data)
I would split the solution into two steps:
Prepare the tableItems and nodes to the required end state using R.evolve - filter, sort, and then use R.toPairs the tableItems to get an array that includes the index and the object. Group the nodes by id so you can pick the relevant nodes by id in the combine step.
Combine both properties to create the end result by mapping the new tableItems, and using R.applySpec to create the properties.
const {pipe, evolve, filter, prop, sortBy, toPairs, groupBy, map, applySpec, path, flip, pick} = R
const transform = pipe(
evolve({ // prepare
tableItems: pipe(
filter(prop('startingPoint')),
sortBy(prop('pageNumber')),
toPairs
),
nodes: groupBy(prop('id'))
}),
({ tableItems, nodes }) => // combine
map(applySpec({
id: ([i]) => `chapter-${+i + 1}`,
name: path([1, 'name']),
nodes: pipe(path([1, 'nodes']), flip(pick)(nodes)),
}))(tableItems)
)
const data = {tableItems: [{id: 1, name: "1", startingPoint: true, pageNumber: 15, nodes: [100, 200]}, {id: 2, name: "2", startingPoint: true, pageNumber: 14, nodes: [300, 400]}], nodes: [{id: 100, tableItemId: 1, content: "test"}, {id: 200, tableItemId: 1, content: "test"}, {id: 300, tableItemId: 2, content: "test"}, {id: 400, tableItemId: 2, content: "test"}]}
console.log(transform(data))
.as-console-wrapper {max-height: 100% !important; top: 0}
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.min.js"></script>

how to import data file (json, jsx, js, etc) for react native ios?

I have a data file something like this.
[
{
"id": 1,
"title": "Car",
"personal_require": 1,
"public_serve": 1,
"public_require": 1,
"personal_serve": 1
},
{
"id": 2,
"title": "House",
"personal_require": 1,
"public_serve": 1,
"public_require": 1,
"personal_serve": 1
},
{
"id": 3,
"title": "Finance",
"personal_require": 1,
"public_serve": 1,
"public_require": 1,
"personal_serve": 1
}
]
I use import and it works for web, but for iOS it seems the system won't able to find the file. I got error:
Failed building JavaScript bundle. Unable to resolve module
../tests/data/defaultWishlist.json from
/Users/wlin/dev/wishlist/screens/ServeScreen.tsx:
None of these files exist: * defaultWishlist.json *
tests/data/defaultWishlist.json/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
15 | import WishlistItem from "../components/WishlistItemText"; 16 |
import { Wishlist } from "../types";
17 | import * as defaultWishlist from "../tests/data/defaultWishlist.json";
| ^ 18 | 19 | type ServeNavigationProp = StackNavigationProp<ServeParamList,
"ServeScreen">; 20 | type Props = { Warning: Problem checking
watchman version. Invalid Version: 20210524.
I have tried json, js, ts, jsx... none of them work.
Full code is here: https://github.com/dotku/aladdin/tree/iosBundleFail
As what I've seen you were trying to import it wrongly.
To fix this change your defaultWishlist.js to defaultWishlist.json
then don't use export inside the json file.
Example of /tests/data/defaultWishlist.json:
[
{
id: 1,
title: "Car",
personal_require: 1,
public_serve: 1,
public_require: 1,
personal_serve: 1,
},
{
id: 2,
title: "House",
personal_require: 1,
public_serve: 1,
public_require: 1,
personal_serve: 1,
},
{
id: 3,
title: "Finance",
personal_require: 1,
public_serve: 1,
public_require: 1,
personal_serve: 1,
},
]
Then you can use this json on every file as long as you call it:
const list = require('./___test___/defaultWishlist.json');
Here's a reproducible snack: Snack Example
Edit:
Just to add if you were trying to import it as a JS file. The structure should be like this:
const export data = [
{
id: 1,
title: "Car",
personal_require: 1,
public_serve: 1,
public_require: 1,
personal_serve: 1,
},
{
id: 2,
title: "House",
personal_require: 1,
public_serve: 1,
public_require: 1,
personal_serve: 1,
},
{
id: 3,
title: "Finance",
personal_require: 1,
public_serve: 1,
public_require: 1,
personal_serve: 1,
},
]
then on your file you are going to call it like this:
import {data} from './___test___/defaultWishlist.js'

Apex Line Area chart is not getting displayed on the page in Vuejs

I am stuck on a page where i am not able to display the charts on the page.
To make it simplify what I have done is, here is the code sandbox:
I see there an error in console about the data, I am not sure about it.
https://codesandbox.io/s/compassionate-snyder-bckoq
I want to display the chart like this (as an example), but I am not able to display on the code sandbox
Please help.
The format of series is not aligned with ApexCharts.
You need to transform the data to match with ApexChart format.
Please see the changes in the codesandbox.
https://codesandbox.io/s/small-dew-eztod?file=/src/components/HelloWorld.vue
options: {
// X axis labels
xaxis: {
type: 'date',
categories: ["2021-05-04", "2021-05-05", "2021-05-07"]
},
},
series: [
{
name: "total",
data: [2, 2, 1],
},
{
name: "pending",
data: [0, 1, 0],
},
{
name: "approved",
data: [2, 1, 1],
},
{
name: "rejected",
data: [0, 0, 0],
},
],
Transform data to fit ApexChart
const data = {
"2021-05-04": {
total: 2,
pending: 0,
approved: 2,
rejected: 0,
},
"2021-05-05": {
total: 2,
pending: 1,
approved: 1,
rejected: 0,
},
"2021-05-07": {
total: 1,
pending: 0,
approved: 1,
rejected: 0,
},
};
const xaxis = {
type: "date",
categories: Object.keys(data).map((key) => key), // ['2021-05-04', '2021-05-05', '2021-05-07']
};
let statusObj = [];
for (const dataValue of Object.values(data)) { // get the values from keys '2021-05-04', '2021-05-05' ...
// loop the values, e.g. 1st loop: { total: 2, pending: 0, approved: 2, rejected: 0, }
for (const [key, value] of Object.entries(dataValue)) {
// take 'total' as example, find if statusObj already has { name: 'total', data: [x] }, e.g. statusObj = { name: 'total', data: [1] }
const existingStatusIndex = Object.keys(statusObj).find(
(sKey) => statusObj[sKey].name === key
);
// if yes, return the index of it
if (existingStatusIndex) {
// add new data value to existing data object. e.g. { name: 'total', data: [1, 2] }
statusObj[existingStatusIndex].data.push(value);
continue;
}
// if no, create a new object and add it to statusObj
statusObj.push({
name: key,
data: [value],
});
}
}
Output:
xaxis {
type: 'date',
categories: [ '2021-05-04', '2021-05-05', '2021-05-07' ]
}
statusObj [
{ name: 'total', data: [ 2, 2, 1 ] },
{ name: 'pending', data: [ 0, 1, 0 ] },
{ name: 'approved', data: [ 2, 1, 1 ] },
{ name: 'rejected', data: [ 0, 0, 0 ] }
]

SELECT Array elements using Cosmos SQL query

Need to select array elements as row element.
Cosmos Documents JSON
1.
{
"CountyId": 1
"CountyCode": "Abbeville",
"Cities": [
{ "CityId": 1, "CityName": "Arborville" }
]
}
2.
{
"CountyId": 2
"CountyCode": "Adair",
"Cities": [
{ "CityId": 2, "CityName": "Ballard" },
{ "CityId": 3, "CityName": "Brashear" },
]
}
And the result that I need would like this.
Please try the following query:
SELECT c.CountyId, c.CountyCode, d.CityId, d.CityName FROM c
Join d in c.Cities
This produces the following output:
[
{
"CountyId": 1,
"CountyCode": "Abbeville",
"CityId": 1,
"CityName": "Arborville"
},
{
"CountyId": 2,
"CountyCode": "Adair",
"CityId": 2,
"CityName": "Ballard"
},
{
"CountyId": 2,
"CountyCode": "Adair",
"CityId": 3,
"CityName": "Brashear"
}
]

Duplicate objects based on prop list

I have a list of objects such this one:
var original = [
{
prop1: 1,
prop2: 2,
tags: ["tag1", "tag2"]
},
{
prop1: 3,
prop2: 4,
tags: ["tag1", "tag3", "tag4"]
},
{
prop1: 5,
prop2: 6,
tags: ["tag4"]
}
]
I want to duplicate the objects based on tags in order to finally have one object for every tag (also duplicated ones) using ramda.js.
var parsed = [
{
prop1: 1,
prop2: 2,
tags: ["tag1"]
},
{
prop1: 1,
prop2: 2,
tags: ["tag2"]
},
{
prop1: 3,
prop2: 4,
tags: ["tag1"]
},
{
prop1: 3,
prop2: 4,
tags: ["tag3"]
},
{
prop1: 3,
prop2: 4,
tags: ["tag4"]
},
{
prop1: 5,
prop2: 6,
tags: ["tag4"]
}
]
I tried with this function but I think there is some better solution
var f = (a,b) => R.evolve({tags: () => a}, b)
R.unnest(
R.map((v) =>
R.zipWith(f, v.tags, R.repeat(v, v.tags.length))
)(original)
)
You can do it like this:
const dup = pipe(
map(obj => map(tag => merge(obj, {tags: [tag]}), obj.tags)),
flatten
);
Or, perhaps more readably, like this:
const spread = obj => map(
tag => merge(obj, {tags: [tag]}
), obj.tags);
const dup = pipe(
map(spread),
flatten
);
While this probably could be made points-free with enough effort, it would likely be much uglier.
You can see this in action on the Ramda REPL.