ava support for snapshot property matchers - ava

Does ava support snapshot property matchers?
I am using ava snapshots to test an API endpoint that returns a JSON object. The response contains some properties that are unique to the request (e.g. timestamp, request id).
I know that Jest allows to use property matchers so a property can match to any value. I wonder if ava supports this as well.

It does not. Your best bet is to use destructuring to remove the changing values before you snapshot.

Related

I have been trying to compare all the contentid's of two api's in Jmeter

I have two api's which has the same contents but only the url changes, and I want to compare all the contents from both APIs using jmeter
I have used json extractor and extracted by using path as
$.. contentid given match no as -1 and checked the _All option
I have used beanshell assertion to compare the both APIs response, but one api has the all contentid's in random jumbled format so when I run the assertion I am getting error as assertion failed
For example response of one api has
{123,345,678,week,add}
And other api has
{add,123,678,week,345}
Can you help and possibly show how to compare them and get success
Take a look at JSONassert library, it allows comparing the JSON responses ignoring the attributes order and focusing only on content.
Also since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so it worth considering migrating to JSR223 Assertion.
More information: Introduction to JSONassert

key authorisation test case by JSON.strongify in JMEter

I testing authorisation in JMeter.
Authorisation is by key, who is send in JSON.stringify.
first is open connected by web socket,
next send is key in json format.
how is the best way to testing is? what test case could be?
i think set happy path, and next authentication failed and in this give
1. missing key - what testing/ set this in jmeter ?
2.bad key - not exist - what set this in jmeter?
what could be addicted test case/?
what testing authentication in jmeter?
You can use JMeter WebSocket Samplers in order to open the WebSocket connection and send your request payload. Note that WebSocket Samplers are not a part of official JMeter distribution, you will need to install them using JMeter Plugins Manager. You need WebSocket Samplers by Peter Doornbosch
You can use Response Assertion to add a conditional check to server response and change expected result according to your test case.
With regards to possible test cases - you should stick to the functional requirements and make sure that all of them are covered. If you don't have explicit requirements you're limited only by your fantasy and the time you have to implement your test, several possible use cases could be: something very big, null, numeric, boolean, another JSON object, JSON array, malformed JSON, not sending anything (session timeout), etc.

How to write an object to gcp object store with x-goog-if-generation-match from a cloud function

I'd like to write an object to gcp object store, while using the x-goog-if-generation-match feature. Using #google-cloud/storage npm library, the file object does not seem to have an option for setting the required object generation.
What are the alternatives?
As you noticed, the #google-cloud/storage npm library doesn't support generation and metageneration preconditions.
As an alternative, you may use either the Storage XML API or the Storage JSON API which do support it. Depending on if you want to use one or the other, you'll be able to use preconditions via HTTP Headers or query string parameters. You'll find the whole list of those here.
Another alternative is to use some kind of optimistic locking:
get the generation id
write object
get the generation id again
repeat until generation after = generation before + 1

How to apply low-level character filter to Jackson JSON parsing?

I have a (JSON) REST-based application based on Spring and RESTEasy. We have a requirement to limit the set of characters that are accepted as input to the services. I could apply the restriction to the POJOs themselves during or after deserialization, but it seems more efficient to insert some kind of filter into the Jackson parsing as it's reading the JSON stream, since it's obviously inspecting each character at some point anyway.
Question is, does Jackson provide a plug-in point to do that? Something that would enable me to decorate or override the low-level parsing at such a time that I could verify each character of each property value is valid (i.e., in a particular set according to the app requirements).
If you mean allowed characters within JSON String values, no, there is no filter or transformer functionality currently. You could consider implementing JsonParserDelegate, which could intercept calls to getText(), but that may not be very clean mechanism. Alternatively you could first read content as tree (JsonNode), traverse it and cleanse String values; and only after that do data-binding using ObjectMapper.convertValue(fromNode, MyType.class).
In the context of RESTEasy, you can inject the custom JsonParserDelegate by extending MappingJsonFactory and overriding the _createJsonParser(...) methods to return the custom delegate. Then implement an extension to JacksonJsonProvider (Jackson's JAX-RS provider) that creates an ObjectMapper with your custom factory in its constructor. Examples of this can be found in this answer to a related question.

Jmeter and Json, extracting and using variables for another request

I'm new to JMeter and I'm probably missing something quite simple...
Note: I'm using a json add-on as well.
After making a request, I extract a value from the response. If I check the view results I'm able to see the correct value in the variable I created.
-Initial extraction of value-
-how I tried to use my new value for a new request-
If I try use the variable in another request, I receive an error because the variable is now the default value.
What am I doing incorrectly that makes the second post request to use the default value and not the value it captured (if I did that correctly).
Thanks
JSON Path Extractor is a Post Processor. It is not a Sampler. It should be the child element of the first request 'Create Order' in your test plan if you are going to extract from the 'Create Order' response. If it is in same level with other requests, the post processor will be executed for each and every samplers in the same level. That is why, You are able to see the value for the first time. Now Post processor tries to extract the value from the Debug Sampler as well. As Debug Sampler does not match your JSON extract condition, It sets the default value.
2 years later (March 2018), with Jmeter version 4.0, solution it's the same.
With the new interface, simply by dragging the json extractor on the http request, the json is limited to perform the extraction operation on it, maintaining the results.