Postman automatically resets environment variable Current Value to null - postman

I have an environment with few variables set in Initial Values.
//Variable, Initial Value, Current Value
VAR 1, Initial 1, null
VAR 2, Initial 2, null
I updated the environment Current Values to Initial Values by clicking Reset All. My environment now looks like this and I save it.
//Variable, Initial Value, Current Value
VAR 1, Initial 1, Initial 1
VAR 2, Initial 2, Initial 2
Now, when I run my collection requests, I get the following error:
Error: getaddrinfo ENOTFOUND null
Upon checking my environment variables, I see the current value resets to null again. Any idea why this is happening ? Am I missing something obvious. There are also nothing set in the Tests.
//Variable, Initial Value, Current Value
VAR 1, Initial 1, null
VAR 2, Initial 2, null

To debug such issues try out the following steps:
Create a new collection and a new fresh request and send it and see the behaviour is seen again
Check if there is any collection level script
Check if you misspelt pm.environment.get as pm.environment.set
Make sure after clicking reset, or editing variables you save the environment

Related

Postman: How to store an array from response and use it to make multiple requests

Let's say I have an API endpoint /bar that returns:
{
"fooIds": [1,2,3]
}
and a /foo/<id> endpoint that i would like to call with those ids.
Is there way of getting postman to make a call to the /bar endpoint and subsequent calls to /foo?
Create yourself a collection in Postman with two requests. The first one for /bar, second one for /foo/{{id}} where {{id}} is a Postman parameter stored in either the globals or environment variables (either place is fine, the example below uses the globals).
Then in the test script of the first request save fooIds to the globals with
pm.globals.set('fooIds', pm.response.json().fooIds.join(','));
In the pre-request of the second request
// fetch the fooIds into an array (leaves it undefined if not found)
const fooIds = pm.globals.has('fooIds') && pm.globals.get('fooIds').split(',');
// if fooIds was found, and has a first element, save it
fooIds && fooIds[0] && pm.globals.set('id',fooIds.shift()); // .shift() removes the first element
// save the updated fooIds back to the globals
pm.globals.set('fooIds', fooIds.join(','));
Note: when fooIds = [], then fooIds.join(',') returns "", and setting a global variable to "" deletes it.
and finally in the test script of the second request
pm.globals.has('fooIds') && postman.setNextRequest('nameOfFooRequest')
If you run that in the Postman Collection Runner, that should (hopefully) iterate over the array of id's.
(be sure to save before you run as you might have an infinite loop)
Let me know if you have any issues.

Update newly created record on client after successfully processing the Create request on server

Please, consider following scenario:
IgniteUI 16.1 igGrid powered with igGridUpdating feature and RESTDataSource
User creates a new record through modal dialog
Post request is initiated with form data
Server processes the create request and returns an object, populated with correct ID
In success handler on the client side, the newly added in the grid row has to be found and updated with correct ID returned from the server.
The ID column serves as a grid's primary key and it's hidden
What happens when a new row is adding?
We are watching infragistics.lob-16.1.js
In _dialogOpening(), row 68167, _originalValues are computed via $.extend(this._originalValues, values, this._originalValues), where values = _getDefaultValues() or with other words values.id = this._pkVal. And _pkVal is a counter that is incremented each time when a new row appears.
Keeping that in mind, later, _endEditDialog() is called, where newValues, representing the entered data by the user, are merged with default values of the input form: newValues = this._getNewValuesForRow(colElements) followed by newValues = $.extend({}, prevValues, newValues) and prevValues are the same _originalValues from above.
Then an _addRow() is called, which calls on its run grid.dataSource.addRow() and a transaction is created.
My point here is the updating feature generates ID automatically for the new row and ID = CurrentRowsCount + 1.
So, if the grid contains 8 records, then newly created record will automatically be assigned with ID = 9. And imagine, if one of existing records has an ID = 9, then igGridUpdating's updateRow(rowId, values) will update both rows, existing and the new one. And I realy want to call this method in order to update the row with the data, returned from the server.
How could I intervene in the whole picture and accomplish the update of the new row?
The auto-generated primary keys are only meant to cover the most basic scenarios. If your app supports row deletion you should change them with something that will keep them unique using the generatePrimaryKeyValue event.
Using updateRow after receiving the permanent keys from the server is the way to go, however, remember to pop the transaction from the allTransactions array so the update doesn't go to the server on the next saveChanges call.

Ember .observe() returns callback twice when used with query-params

http://jsbin.com/vowup/2
If I click change to random, program logs in console twice.
For some strange reason it works ok when setting revision variable to string, but logs twice for number or any other kind of variable
Change your code to this and the answer will become clear:
toggleHistory: (function() {
console.log(this.get("revision"));
}).observes("revision")
You will see output like:
0.7038348997011781
"0.7038348997011781"
Your numbers are being coerced to strings. That is caused by this line:
queryParams: ["revision"]
Query system is listening to changes and converting every new value into string, so it could appear as part of the URL. That's why you get two changed events.

Property 'ID' is part of the object's key information and cannot be modified

I'm trying to run an MVC unit test on an action that clones a record. Naturally, we use the master record's primary key to pull it from the database first using a simple DbSet.Find(). Right now I have about 100 unit tests written, and 98/100 are passing including a number of which are required to test various aspects of this type of transaction... and they're all passing.
In the first step a user has chosen to create an Agency but selected that they also would like to add another. The page will post back to the Create POST controller method and save.
Once the save is complete, the program is design to re-route back to the Create GET method. From there it gathers the relevant information and posts the new model object back to the view.
var result = _controlAgtTran.Create(_agency, "andAddAnother") as RedirectToRouteResult;
var message = _controlAgtTran.Create(int.Parse(result.RouteValues["id"].ToString()), null, null, null, null, null, true, result.RouteValues["msg"].ToString()) as ViewResult;
Nothing too complicated happens once we're re-routed to the GET action, as you can see below. We simply call a DbSet.Find(<PK>) method to grab the object we just saved.
AgentTransmission master = db.AgentTransmission.Find(id);
However, each and every time, and for this operation alone, I the following error message. I've stepped through the code to make sure the id variable is not null, I've queried the database to make sure it's correct, and I've compared this portion of the unit test to others in the solution and can't find a difference. Any help/suggestions would be greatly appreciated.
The property 'ID' is part of the object's key information and cannot be modified.
EDIT

Mage_Core_Model_Config doesn't fetch value in unit-tests

I found a strange problem while doing some unit-testing on Magento.
I have a test function which test a value from core_config_data table. So in order to have access to that value for test, in the setUp() function I am saving the config value in database:
public function setUp()
{
parent::setUp();
$systemConfig = new Mage_Core_Model_Config();
$systemConfig->saveConfig(
'my/custom/path/config',
12
);
}
and in my test method I am getting that value from database likeso:
$productsNo = Mage::getStoreConfig(my/custom/path/config);
but its value is null, and not a string as expected.
This is strange, because if I am refreshing the database after running the test, the value it's existing in database. And if I'm running the test again, the test will work and the value it's not null anymore.
What am I doing wrong? I don't save the value correctly, or I don't fetch it in a good way?
You only save the configuration value to the database, but you don't refresh the config cache, which is used by Mage::getStoreConfig().
To achieve saving and refreshing at the same time you could use:
Mage::app()->getConfig()
->saveConfig('my/custom/path/config', 12)
->reinit();
This way the configuration value will be available in the current and subsequent requests.
In case you don't really need persistence, that is, if you only need this configuration value for the current request, than I'd rather recommend to use:
Mage:app()->getStore()
->setConfig('my/custom/path/config', 12);