kiranz / just-api Goto Github PK
View Code? Open in Web Editor NEW:boom: Test REST, GraphQL APIs
Home Page: https://kiranz.github.io/just-api/
License: MIT License
:boom: Test REST, GraphQL APIs
Home Page: https://kiranz.github.io/just-api/
License: MIT License
Hi!
I get the following error when access a https endpoint
Error: write EPROTO 140263490227968:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:ssl/record/rec_layer_s3.c:1407:SSL alert number 40
at _errnoException (util.js:992:11)
at WriteWrap.afterWrite [as oncomplete] (net.js:864:14)
My configuration looks like -
meta:
name: GraphQL API
configuration:
host: api.example.com
scheme: https
port: 8443
specs:
- name: Get list of all users
request:
method: post
path: /graphql
headers:
- name: content-type
value: application/json
payload:
body:
type: json
content:
query: >
{
getUser(id: "xxxx-xxxx-xxxx-xxxx-xxxxx70cc6d7"){
first_name
}
}
variables: null
operationName: null
response:
status_code: 200
json_data:
- path: $.data.getUser.first_name
value: "John"
The server has a valid SSL certificate signed by a CA.
Hello!
I have a few use cases where I have to test 2 different rest endpoints for a test case. For example,
When a user creates an account via POST on http://user-service I have to test if http://notify-service sent a welcome email via a GET request using the user id.
How do I test this scenario using just-api with multiple REST services?
Could be useful to use just-api
like a library. In my case, I craft programmatically some YAML files before running the tests. Right now is a 2 steps procedure, but would be more natural to use it in the same program.
DISCLAIMER: I'm completely new to NodeJS, so if I'm saying something stupid, please correct me ๐
An OpenAPI (FKA Swagger) spec often contains multiple schema definitions, such as #/components/responses/someResponseName
It would be very useful to reuse schema definitions from within the existing files, such as:
specs:
- name: Some request
...
response:
json_schema:
type: file
$ref: schemas/openapi.json#/components/responses/NotFoundError
This would read the __dirname/schemas/openapi.json and extract the components.responses.NotFoundError property.
I can probably submit a contribution for this but would like to collect thoughts to make sure I implement it correctly.
Wondering if it's possible to import just-api
as a library into a React project. I would like to use 'just-api
but create a UI dashboard, which would mean saving test states and tests in some DB and other usability features.
if yes are where can I find public API's? Thanks for the great work!
I am trying to call an async function for the end
event for a custom report and the app does not wait for pending callback. I think the problem is because you kill the process here
Line 121 in e6706fd
It seams impossible to send binary payload.
I have directly checked following example:
- name: post binary data (file) as body
request:
path: /echoBinaryBodyResponseStats
method: post
headers:
- name: content-type
value: image/png
payload:
body:
type: binary
content: static/assets/logo.png
response:
status_code: 200
json_data:
- path: $.request_content_size
value: 12371
And it sends [object Object]
as body payload.
Further inspection show that it's a fs.ReadStream
object (created in spec.js:515
?).
Did I missconfigured something or is it a bug or not fully implemented feature?
Tested with node13
and [email protected]
.
Hello @kiranz!
Am really enjoying trying out this tool for a Proof of Concept. Thank you for this!
I think I've read all (or most) of your documentation but have not figured it out. If a have a multi-level dependency set up where a test A in one suite A needs to first call a test B in another suite B, which in turn needs to call a test C in yet another suite C...can I just sort of "chain" them like that and test A in suite A only has to worry about calling/using the test B in suite B and assume that the test B will automatically take care of using/calling test C?
Test C is for authenticating and getting a token. Test B is for getting some default values that will be used across all other numerous tests and suites, such as those in suite A.
Or does it mean that tests in Suite A has to explicitly call both the dependency test B as well as explicitly call/use the dependency in test C?
Again, thanks for this tool and your time! I am not a JS developer so this sort of helps us bridge that gap w/ the actual Dev team.
Hello!
I was wondering if we could use environment variables to replace API tokens in suite YAML as they will be sensitive
In my current project, the GraphQL API is only accessible via a socks5 proxy. But seems Just- API doesn't support proxy.
Can any one have a suggestion?
Hi y'all,
(how) is it possible to use one return value of a call as a parameter for the next one? This would be reeeeeally handy.
Many thanks!
When you call this.runSpec
in before_test
, the test you are executing in runSpec isn't running the before_test
functionality.
Example:
meta:
name: "Test suite"
configuration:
scheme: "https"
custom_configuration:
run_type: inline
inline:
function: !!js/function >
function() {
this.host = process.env.API_URL;
}
specs:
- name: "Get Authorization Token"
enabled: false
before_test:
run_type: inline
inline:
function: !!js/function >
function() {
this.test.payload = { body: {type: 'json', content: {
email: process.env.EMAIL,
password: process.env.PASS
} } };
}
request:
path: "/api/token"
method: "post"
headers:
- name: content-type
value: application/json
response:
status_code: 201
- name: "Get List"
before_test:
run_type: inline
inline:
function: !js/asyncFunction >
async function() {
var response = await this.runSpec('Get Authorization Token');
var tokenResponse = JSON.parse(response.body);
this.test.headers = { Authorization: tokenResponse.token };
}
request:
path: "/api/users"
method: "get"
response:
status_code: 200
headers:
- name: "content-type"
value: !!js/regexp application/json
json_data:
- path: "$.name"
value: "John Smith"
Desired functionality is for test to get the authorization token and set it as the header instead the following error is outputted:
1) Get List (/test.yml)
BeforeTestHookError: RequestBodyNotFoundError - request content-type is application/json, but request body is not found
at Spec.runHook (/node_modules/just-api/src/spec.js:312:19)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:51:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:804:11)
at internal/main/run_main_module.js:21:11
meta:
name: Testing headers
enabled: true
version: "1.0"
configuration:
scheme: http
host: 127.0.0.1
port: 3027
common_headers:
- name: customsuiteheader
value: custom-suite-header-value
- name: content-type
value: application/json
specs:
- name: uses suite-level content-type header
request:
path: /echoJSONBodyResponse
method: post
payload:
body:
type: json
content:
name: Kiran
response:
status_code: 200
Request method is post,request body is provided but Content-Type header is not provided
Suite-level common_headers should be checked when this assertion runs.
A few tests are failing in master:
150 passing (34s)
2 failing
1) Other verbs
"before all" hook:
AssertionError: expected 1 to equal 0
+ expected - actual
-1
+0
at Context.<anonymous> (test/cli/otherverbs.spec.js:13:36)
2) url encoded form post
"before all" hook:
AssertionError: expected 0 to equal 1
+ expected - actual
-0
+1
at Context.<anonymous> (test/cli/urlencodedformpost.spec.js:21:48)
I'm trying to use just-api with graphql. For a graphql query for a single query and response, just-api works
But for graphql multiple field query and response similar to the rest-api example below -
https://github.com/kiranz/just-api/blob/master/test/cli/src/suites/jsondata.suite.yml
json-api does not work.
Here is my graphql query -
{
getAddress(id: "xxx-xxx-xxx") {
zip
name
locality
country
}
}
and I would like to evaluate the response for all the fields.
just-api throws the following error for multi-response data -
0 skipped, 2 failed, 0 passed (2 tests)
0 skipped, 1 failed, 0 passed (1 suites)
Duration: 2.4s
Failures:
1) Get list of all properties (/home/mrcasablr/src/just-api/api-example.yml)
ResponseJSONDataMismatchError: JSON path evaluated value did not match with expected value, json path: $.data.getAddress.zip, Actual value: undefined, Expected value: 90047
request: POST https://api.example.com:8443/graphql
at Spec._validateJSONData (/home/mrcasablr/node_modules/just-api/src/spec.js:699:27)
at Spec.validateResponse (/home/mrcasablr/node_modules/just-api/src/spec.js:333:18)
at Spec.runAsTest (/home/mrcasablr/node_modules/just-api/src/spec.js:123:24)
at process._tickCallback (internal/process/next_tick.js:68:7)
2) validate json response with json data functionality - should fail (/home/mrcasablr/src/just-api/api-example.yml)
ResponseJSONDataMismatchError: JSON path evaluated value did not match with expected value, json path: $.data.getAddress.location, Actual value: undefined, Expected value: "New England"
request: POST https://api.example.com:8443/graphql
at Spec._validateJSONData (/home/mrcasablr/node_modules/just-api/src/spec.js:699:27)
at Spec.validateResponse (/home/mrcasablr/node_modules/just-api/src/spec.js:333:18)
at Spec.runAsTest (/home/mrcasablr/node_modules/just-api/src/spec.js:123:24)
at process._tickCallback (internal/process/next_tick.js:68:7)
Hi again,
I am wondering...is it (or not) possible to separate a request from a response and have them reside in separate YML files? I am guessing not but wanted to confirm.
I specifically call it not a Spec because that term insinuates that it is a test. When it comes to intradependencies across suites...does the response part of a dependency also get executed and that spec is being called from another suite?
Thanks again!
Hello,
I am struggling to use just-api for more advanced requests and workflows. Surely I don't understand fully how to use it. Is a spec, or a test, run differently depending on whether the spect itself is being run directly, i.e. it is the spec of interest, versus when said spec is being called from another spec in a different suite, or even if the spec is in the same suite but is a different spec?
If a spec A that has a before_test
hook gets called from another spec B in the same suite, does the before_test
hook of spec A also get executed? Or are test-context hooks only exercised when the spec/test itself that the hook pertains to gets executed itself?
Please advise...I have been beating my head at this for numerous hours. It's been slooow progress :)
Thanks!
Tick and cross doesn't seem to be displayed as intended on windows command prompt.
one can observe the issue when a test fails.
At the moment it seems like only binary content can be provided as a file path.
For some requests, e.g. GraphQL to properly check coverage, the query might be > 1000 lines, and the schema might cover 100s of Query
and Mutation
endpoints. It's completely impractical to paste the raw query in every single spec file.
Using the example from the readme:
meta:
name: GraphQL location service
configuration:
host: api.graphloc.com
scheme: https
specs:
- name: Get Location of a given ip address
request:
method: post
path: /graphql
headers:
- name: content-type
value: application/json
payload:
body:
type: json
content:
query: >
{
getLocation(ip: "8.8.8.8") {
country {
iso_code
}
}
}
variables: null
operationName: null
response:
status_code: 200
json_data:
- path: $.data.getLocation.country.iso_code
value: US
It would be very useful for payload.body.content.query
to be a file path rather than an inline query.
Currently only node 10.x works since 12.x gulp is incompatible. The build scripts are quite simple and can be moved to simple binaries executed via npm.
Adding a proxy to the tool would be really beneficial since one can then intercept outgoing requests. Currently, I cannot find a way to troubleshoot what went wrong. I've created a spec file to validate a json response schema -> executed it but the request failed with 400 Bad Request, proxying the request to a proxy would be really easy to see what one is sending and then change the request accordingly.
configuration:
custom_configuration:
run_type: module
module:
module_path: some-module.js
function_name: suiteConfigSync
specs:
- name: uses suite-level custom_configuration content-type header
request:
path: /echoJSONBodyResponse
method: post
payload:
body:
type: json
content:
name: Kiran
response:
status_code: 200
module.exports = {
suiteConfigSync: function() {
this.common_headers = [{
name: 'content-type',
value: 'application/json'
}];
}
};
InvalidRequestHeaderError: Request method is post,request body is provided but Content-Type header is not provided
common_headers
should be honored
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.