Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature to sort Postman requests #3

Merged
merged 1 commit into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ postman-config.json
postman-testsuite.json

.DS_Store
.idea
2,548 changes: 2,548 additions & 0 deletions examples/postman-ordering/crm.yml

Large diffs are not rendered by default.

11,465 changes: 11,465 additions & 0 deletions examples/postman-ordering/crmApi.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions examples/postman-ordering/portman-config.ordering.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"preRequestScripts": [
"pm.collectionVariables.set('status', pm.iterationData.get('status') || 'open')"
],
"variableOverwrites": {
"application_id": "{{applicationId}}"
},
"globalReplacements": [
{
"searchFor": "\"maxItems\":2,",
"replaceWith": ""
}
],
"orderOfOperations": [
"POST::/crm/leads",
"GET::/crm/leads/{id}",
"PATCH::/crm/leads/{id}",
"DELETE::/crm/leads/{id}",
"GET::/crm/leads"
]
}
121 changes: 121 additions & 0 deletions examples/postman-ordering/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Postman collection request ordering

This example contains the setup of Portman to convert & sort an OpenApi, with sorting of the Postman requests.

_use-case_: execute Postman requests in a certain order typically linked to test scenario's, like CRUD.

## CLI usage

```ssh
yarn portman -l ./examples/postman-ordering/crm.yml -t false -c ./examples/postman-ordering/portman-config.ordering.json
```

This is a very simple example where we just take the the `crm.yml` OpenApi and convert it with ordering in place.

## Portman settings

The `orderOfOperations` is a list of OpenApi operations, which is used by Portman to sort the Postman requests in the
desired order.

The OpenApi operation is the unique combination of the OpenApi method & path, with a `::` separator symbol.
The example: `"GET::/crm/leads"` will target only the "GET" method and the specific path "/crm/leads".

## Example explained

In our example we want to run the execution of the CRM leads operations in specific order in Postman.

So in our Portman configuration file , we have defined the `orderOfOperations` with the desired order for the "leads"
endpoints. REMARK: Items that are **not** defined in the `orderOfOperations` list will remain at their current order.

./examples/postman-ordering/portman-config.ordering.json >>

````json
{
"orderOfOperations": [
"POST::/crm/leads",
"GET::/crm/leads/{id}",
"PATCH::/crm/leads/{id}",
"DELETE::/crm/leads/{id}",
"GET::/crm/leads"
]
}
````

The result will be that initial OpenApi file, with the operations orders like:

./examples/postman-ordering/crm.yml >>

```yaml
paths:
/crm/leads:
get:
operationId: leadsAll
summary: List leads
post:
operationId: leadsAdd
summary: Create lead
'/crm/leads/{id}':
get:
operationId: leadsOne
summary: Get lead
patch:
operationId: leadsUpdate
summary: Update lead
delete:
operationId: leadsDelete
summary: Delete lead

```

will be converted in a Postman Collection that is order like this:

./examples/postman-ordering/crmApi.json >>

```json
{
"item": [
{
"id": "7aba139c-6c52-4d20-a1f2-e5f54482dd31",
"name": "Leads",
"item": [
{
"id": "eeca3dd2-c57f-4ba9-b347-927b0fa867dc",
"name": "Create lead"
},
{
"id": "c9807808-5c7b-4194-b899-5d0317c1ddc1",
"name": "Get lead"
},
{
"id": "1e6e89d5-a975-4f34-b548-b16d64e12ba7",
"name": "Update lead"
},
{
"id": "41e14505-3cd5-461d-a252-16af1ac9894d",
"name": "Delete lead"
},
{
"id": "240d8dd4-ea17-4e66-a564-2ed7380d559a",
"name": "List leads"
}
]
}
]
}
```

**End result**

Original order for items as defined in OpenApi:
1) List leads - GET
2) Create lead - POST
3) Get lead - GET
4) Update lead - PATCH
5) Delete lead - DELETE

Ordered items in Postman after conversion as defined in the Portman configuration:
1) Create lead - POST
2) Get lead - GET
3) Update lead - PATCH
4) Delete lead - DELETE
5) List leads - GET
Loading