Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Commit

Permalink
release 2.1.0
Browse files Browse the repository at this point in the history
* remove entrypoint from Dockerfile
* check for version 2 in yml
* resolve #113
  • Loading branch information
jgroom33 committed Dec 13, 2018
1 parent f2d9eea commit 43f6d77
Show file tree
Hide file tree
Showing 57 changed files with 109 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ COPY --from=builder /app /app
WORKDIR /app
RUN npm link

ENTRYPOINT ["strest"]
CMD ["strest", "tests/success/"]
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ We'll be using the [postman-echo](https://docs.postman-echo.com) test API in thi
To get started, we're using [this file](tests/success/postman.strest.yml) _(The extension needs to be `.strest.yml` or `.strest.yaml`)_

```yaml
version: 1 # only version at the moment
version: 2 # only version at the moment

requests: # all test requests will be listed here
testRequest: # name the request however you want
Expand Down Expand Up @@ -116,7 +116,7 @@ With __Strest__ you're able to predefine a very well structured test file once,
To create multiple requests, simply add multiple entries into the `requests` yaml object.

```yaml
version: 1
version: 2

requests:
requestOne:
Expand Down Expand Up @@ -191,7 +191,7 @@ This can also be used across files as demonstrated [here](tests/success/chaining
Use JsonPath to extract specific data from previous. [This](https://github.com/dchester/jsonpath) library is used.

```yaml
version: 1
version: 2
requests:
set_JsonPath:
request:
Expand Down Expand Up @@ -232,7 +232,7 @@ If you need to generate some random values, you are able to do so by using [Fake
### Example - Faker

```yaml
version: 1
version: 2
requests:
fake:
Expand All @@ -259,7 +259,7 @@ strest tests/success/Env/environ.strest.yml
```

```yaml
version: 1
version: 2
# ensure the ENV var is set: `export STREST_URL=https://jsonplaceholder.typicode.com`
requests:
environment:
Expand All @@ -273,7 +273,7 @@ requests:
### Example - User Defined Variables
```yml
version: 1
version: 2

variables: # Define variables here
testUrl: https://jsonplaceholder.typicode.com/todos/1
Expand All @@ -293,7 +293,7 @@ requests:
With **Strest** you can skip a response by setting a match criteria

```yaml
version: 1
version: 2

requests:
if_Set:
Expand Down Expand Up @@ -347,7 +347,7 @@ requests:
### Type
```yaml
version: 1
version: 2

requests:
typeValidate:
Expand All @@ -368,7 +368,7 @@ requests:
Regex can be used to validate status code or any other returned param
```yml
version: 1
version: 2

requests:
codeValidate:
Expand All @@ -391,7 +391,7 @@ requests:
Validate the response using a specified json(yaml) schema. The schema can be defined in the variables portion or within the request.
```yaml
version: 1
version: 2
variables:
schemaValidate:
type: array
Expand Down Expand Up @@ -455,7 +455,7 @@ stREST uses [nunjucks](https://mozilla.github.io/nunjucks/templating.html) to pa
This allows passing complex objects between requests using the [`dump` filter](https://mozilla.github.io/nunjucks/templating.html#dump)

```yaml
version: 1
version: 2
requests:
objectSet:
request:
Expand Down
16 changes: 8 additions & 8 deletions SCHEMA.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

Property specifying the version of the schema. Available versions:

- `1`
- `2`

## `variables`

Expand Down Expand Up @@ -101,7 +101,7 @@ requests:
This provides conditional execution of a request.

```yaml
version: 1
version: 2
requests:
if_Set:
Expand Down Expand Up @@ -187,7 +187,7 @@ Set the mimeType to:

```yaml
# JSON Example
version: 1
version: 2
requests:
postRequest:
Expand All @@ -203,7 +203,7 @@ requests:

```yaml
# Raw Data Example
version: 1
version: 2
requests:
postRequest:
Expand All @@ -220,7 +220,7 @@ requests:
Conforms to [this](http://www.softwareishard.com/blog/har-12-spec/#queryString) shema. Formatted as an Array.

```yaml
version: 1
version: 2
requests:
responseHeaders:
Expand All @@ -240,7 +240,7 @@ Specify HTTP headers that you want to be sent with the request. Formatted as an

```yaml
# Basic Example
version: 1
version: 2
requests:
requestHeaders:
Expand Down Expand Up @@ -315,7 +315,7 @@ requests:
##### Type

```yaml
version: 1
version: 2
requests:
typeValidate:
Expand All @@ -336,7 +336,7 @@ requests:
Regex can be used to validate status code or any other returned param

```yml
version: 1
version: 2
requests:
codeValidate:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@strest/cli",
"version": "2.0.1",
"version": "2.1.0",
"description": "A new dimension of REST API testing",
"main": "dist/main.js",
"repository": "https://github.com/eykhagen/strest",
Expand Down
3 changes: 1 addition & 2 deletions src/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,11 @@ const requestsSchema = Joi.object().keys({
const requestNameSchema = Joi.object().pattern(/\w+/, requestsSchema);

export const Schema = Joi.object({
version: Joi.number().min(1).max(1),
version: Joi.number().min(2).max(2),
requests: requestNameSchema,
allowInsecure: Joi.boolean().optional(),
variables: Joi.object().optional(),
// Created dynamically
raw: Joi.string().required(),
relativePath: Joi.string().required(),
});

Expand Down
9 changes: 5 additions & 4 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const performTests = async (testObjects: object[], cmd: any) => {
let result = "succeeded"
let error = null
const requestReponsesObj = Array.from(requestReponses.entries()).reduce((main, [key, value]) => ({...main, [key]: value}), {})
let computed = computeRequestObject(requestName, testObject.raw, requestReponsesObj);
let computed = computeRequestObject(val, requestReponsesObj);
if (error !== null) {
// pass
} else {
Expand Down Expand Up @@ -233,17 +233,18 @@ export const performTests = async (testObjects: object[], cmd: any) => {
* Use nunjucks to replace and update the object
* @param obj working obj
*/
export const computeRequestObject = (requestName: string, raw: string, r: any) => {
export const computeRequestObject = (request: requestsObjectSchema, r: any) => {

let merged = { ...r, ...definedVariables };
nunjucksEnv.addGlobal('JsonPath', function (path: string) {
return jp.value(merged, path)
})
// Parse obj using nunjucks
try {
let converted = nunjucksEnv.renderString(raw, merged)
const yamlRequest = yaml.dump(request, {lineWidth:5000})
let converted = nunjucksEnv.renderString(yamlRequest, merged)
const parsed: any = yaml.safeLoad(converted)
return parsed.requests[requestName]
return parsed
} catch (e) {
throw e;
}
Expand Down
1 change: 0 additions & 1 deletion src/yaml-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const parseTestingFiles = (pathArray: string[], dir: string) => {
if(dir === null) {
dir = '';
}
parsed.raw = data
parsed.relativePath = removeFilename.replace(path.join(process.cwd(), dir), '.' + path.sep);
responseData.push(parsed);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/failure/failureJsonschema.strest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2
variables:
schemaValidate:
type: string
Expand Down
2 changes: 1 addition & 1 deletion tests/failure/failureNunjucks.strest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

variables:
testUrl: https://jsonplaceholder.typicode.com/todos/1
Expand Down
2 changes: 1 addition & 1 deletion tests/failure/failureSchema.strest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
codeTypeFailure:
Expand Down
2 changes: 1 addition & 1 deletion tests/failure/failureValidateCode.strest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
codeFailure:
Expand Down
2 changes: 1 addition & 1 deletion tests/failure/failureValidateCodeRegex.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
failureCodeRegex201:
Expand Down
2 changes: 1 addition & 1 deletion tests/failure/failureValidateExpect.strest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
invalidValidation:
Expand Down
2 changes: 1 addition & 1 deletion tests/failure/failureValidateJsonpath.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
failureCodeRegex201:
Expand Down
2 changes: 1 addition & 1 deletion tests/failure/failureValidateObject.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2
requests:
objectSet:
request:
Expand Down
2 changes: 1 addition & 1 deletion tests/failure/failureValidateType.strest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
codeTypeFailure:
Expand Down
13 changes: 13 additions & 0 deletions tests/failure/failureVersion.strest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 1

requests:
indifferent:
request:
url: https://postman-echo.com/post
method: POST
postData:
mimeType: application/json
text:
myArray:
- item1
- item2
2 changes: 1 addition & 1 deletion tests/success/Methods/Env/environ.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2
# ensure the ENV var is set: `export STREST_URL=https://jsonplaceholder.typicode.com`
requests:
environment:
Expand Down
2 changes: 1 addition & 1 deletion tests/success/Methods/Fake/name.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
fake:
Expand Down
2 changes: 1 addition & 1 deletion tests/success/Methods/JsonPath/JsonPath.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2
# Using http://jsonpath.com as object and simple testing
requests:
set_JsonPath:
Expand Down
2 changes: 1 addition & 1 deletion tests/success/Value/array.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
arr:
Expand Down
20 changes: 20 additions & 0 deletions tests/success/Value/nunjucks.strest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2

requests:
value1:
request:
url: https://postman-echo.com/get
method: GET
queryString:
- name: foo
value: bar
value2:
request:
url: https://postman-echo.com/get
method: GET
queryString:
- name: baz
value: <$ value1.content.args.foo | string $>
validate:
- jsonpath: content.args.baz
expect: bar
4 changes: 2 additions & 2 deletions tests/success/Value/value.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
value1:
Expand All @@ -17,4 +17,4 @@ requests:
value: <$ value1.content.args.foo $>
validate:
- jsonpath: content.args.baz
expect: bar
expect: bar
2 changes: 1 addition & 1 deletion tests/success/auth/basic.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
basic_auth:
Expand Down
2 changes: 1 addition & 1 deletion tests/success/chaining/login.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
login:
Expand Down
2 changes: 1 addition & 1 deletion tests/success/chaining/var/one.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2
variables:
testUrl: https://jsonplaceholder.typicode.com/todos/1

Expand Down
2 changes: 1 addition & 1 deletion tests/success/chaining/var/two.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
chaining_var2:
Expand Down
2 changes: 1 addition & 1 deletion tests/success/chaining/verify_login_chained.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2
# This file assumes login.strest.yml was executed.
requests:
verify_login_chained:
Expand Down
2 changes: 1 addition & 1 deletion tests/success/headers/0-requestHeaders.strest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
version: 2

requests:
requestHeaders:
Expand Down
Loading

0 comments on commit 43f6d77

Please sign in to comment.