How to Set Postman Test Equal to This or That - testing

I am writing an API test in Postman, and I would like it to succeed if a Number is returned or the string "NA".
Based on my current understanding one condition can be tested at a time, like:
pm.test('Qty returned is number', () => {
pm.expect(typeof parseInt(pm.response.json().qty)).to.be.not.equal('NaN');
});
Writing as two separate tests, one will pass and one will fail.
How can I code this exception into a single test?

Worked for my case, wanted the test to pass if one of two values is returned:
.to.be.oneOf(["value1","value2"]);
answer from jaikl

Related

verify a method is called only once with a given parameter with Junit 5

I want to ensure that my test calls the userService.find(userName) only with the expected aTestName and only once. Currently, I am achieving this by the following code. Is there a way to combine the two BDDMockito.then... in one?
String aTestName = "aTestName";
BDDMockito.then(userService).should(times(1)).findByName(any());
BDDMockito.then(userService).should(times(1)).findByName(aTestName);
What you should use is only(). So like:
BDDMockito.then(userService).should(only()).findByName(aTestName);

Karate Netty - CallSingle but not so single

What I had till today:
I have get_jwt.feature and I call it as a part of karate-config.js. Since I have used one account test#test.com I needed only one jwt and I can reuse it across scenarios. callSingle worked as a charm in this case.
Today:
Suddenly I have need for jwt's from two accounts which I dont want to generate for each scenario, callSingle falls short of this task as it does exactly what its supposed to be doing. Now I have hacky idea, I can simply make two files, get_jwt.feature and get_jwt_user2.feature, and single call them each.
So my question: Is there a better way of doing this?
You can use "2 levels" of calls. So point the callSingle() to a JS function that calls get_jwt.feature 2 times, maybe with different arguments and then return a JSON. Pseudo-code below. First is get_jwts.js:
function fn(users) {
var jwt1 = karate.call('get_jwt.feature', users.user1);
var jwt2 = karate.call('get_jwt.feature', users.user2);
return { jwt1: jwt1, jwt2: jwt2 };
};
Then in karate-config.js
config.jwts = karate.callSingle('classpath:get_jwts.js', users);
And now you should be able to do this:
* print jwts.jwt1
* print jwts.jwt2
You can also do a feature-->feature call chain. Do let me know if this works !
EDIT: see Babu's answer in the comments, looks like you can pass an array to callSingle() ! so that may be quite convenient :)

vuefire dynamic query issues

I have an odd issue....
When using dynamic queries with VueFire, the query appears to run and returns data in to an array called customSiteSearch. I can console out the array and see the data there as expected.
The bit that I am struggling with is, when I evaluate the length of the customSiteSearch array after the query has run, it always returns 0 the first time. When I run the function again for a second time it appears to work. What could be the cause of this?
my code:
customSiteExists(customSite){
console.log('starting customSiteExists')
this.$bindAsArray('customSiteSearch', db.ref('slinksites/').orderByChild('customsite').equalTo(customSite) )
console.log('search result', this.customSiteSearch)
console.log(this.customSiteSearch.length)
},

How do I assert to accept one of multiple possible values in JUnit

I have a test that returns some value after completion. The returned value is a String and can have one of several possible values based on some if condition in the test.
But in the assert statement I can check only one of the Expected values not both.
How can I do this? Thank you.
I will use AssertJ for this
assertThat(value).isIn(expected1, expected2, expected3);
The code is much simpler than with Hamcrest.
My solution was to save the result and then run a Jtest that the result was in an array of accepted solutions.
E.g:
`it("Test Message", () => {
const result = testFunction(inputValue);
assert.equal((result in [possibeResult1, possibleResult2, ...]), true);
});`

Multiple calls to a Rhino mocked method return different results

If I want to mock a class that returns a string that is used to determine whether while loop should continue (imagine read while string != null), how can I set the expectation. I have tried the following:
provider.Reader.Expect(r => r.ReadLine()).Return("1,10,20");
provider.Reader.Expect(r => r.ReadLine()).Return(null);
but when it is called twice in the same method, it returns the first string on both occasions, whereas I want it to return the second value (null) if called a second time.
I think you can just stick the repeat on the end of the syntax you're currently using.
provider.Reader.Expect(r => r.ReadLine()).Return("1,10,20").Repeat.Once();
provider.Reader.Expect(r => r.ReadLine()).Return(null).Repeat.Once();
or
provider.Reader.Expect(r => r.ReadLine()).Return("1,10,20").Repeat.Once();
provider.Reader.Expect(r => r.ReadLine()).Return(null);
if you have any calls beyond 2nd call that you want to use second expectation.
I'm not familiar with the syntax you're using. I would write this as:
r.ReadLine();
LastCall.Return("1,10,20").Repeat.Once();
r.ReadLine();
LastCall.Return(null).Repeat.Once();
To ensure that you're specifying the number of times that things are to be repeated. (Don't have Visual Studio to hand, syntax may not be exact.)