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

fix: not running all requests in the Postman collection #731

Merged
merged 7 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 3 additions & 1 deletion docs/src/pages/guides/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ You must respond with a capital `"Y"` to confirm if you want to flush the logs o

## Postman

Have an existing request on Postman you want to automate? Monika supports reading postman.yml as configuration input. Use the `-p` or the `--postman` switches.
> NOTE: We only support Postman collection v2.0 and v2.1 files.

Have an existing request on postman you want to automate? Monika supports reading postman.yml as configuration input. Use the `-p` or the `--postman` switches.

```bash
monika -p postman.json
Expand Down
2 changes: 2 additions & 0 deletions docs/src/pages/guides/probes.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ By default, the request body will be treated as-is. If the request header's `Con

## Postman JSON file support

> NOTE: We only support Postman collection v2.0 and v2.1 files.

To run monika using a [Postman](https://www.postman.com/) JSON file, use `--postman` flag as follows:

```bash
Expand Down
90 changes: 78 additions & 12 deletions src/components/config/__tests__/create-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@

import { expect } from 'chai'
import fs from 'fs'
import { createConfig } from '..'
import _ from 'lodash'

import { createConfig } from '../'

beforeEach(() => {
if (fs.existsSync('monika.har.yml')) {
fs.unlinkSync('monika.har.yml')
}

if (fs.existsSync('monika.postman.yml')) {
fs.unlinkSync('monika.postman.yml')
if (fs.existsSync('monika.postman-basic.yml')) {
fs.unlinkSync('monika.postman-basic.yml')
}

if (fs.existsSync('monika.postman-grouped.yml')) {
fs.unlinkSync('monika.postman-grouped.yml')
}

if (fs.existsSync('monika.insomnia.yml')) {
Expand Down Expand Up @@ -61,22 +66,83 @@ describe('Har config', () => {
})
})

const getPostmanConfig = ({ grouped }: { grouped: boolean }) => {
if (grouped) {
const generated = fs.readFileSync('monika.postman-grouped.yml', 'utf-8')

const expected = fs.readFileSync(
'./src/components/config/__tests__/mock_files/expected.postman-grouped.yml',
'utf-8'
)

return { generated, expected }
}

const generated = fs.readFileSync('monika.postman-basic.yml', 'utf-8')

const expected = fs.readFileSync(
'./src/components/config/__tests__/mock_files/expected.postman-basic.yml',
'utf-8'
)

return { generated, expected }
}

describe('Postman config', () => {
describe('Create config from postman file', () => {
it('should create config from postman file', async () => {
it('[v2.0] - should create config from basic postman file', async () => {
const flags = {
postman:
'./src/components/config/__tests__/simple.postman_collection.json',
output: 'monika.postman.yml',
'./src/components/config/__tests__/mock_files/basic-postman_collection-v2.0.json',
output: 'monika.postman-basic.yml',
}

await createConfig(flags)
expect(fs.lstatSync('monika.postman.yml').isFile()).to.be.true
expect(fs.lstatSync('monika.postman-basic.yml').isFile()).to.be.true

const generated = fs.readFileSync('monika.postman.yml', 'utf-8')
const expected = fs.readFileSync(
'./src/components/config/__tests__/expected.postman.yml',
'utf-8'
)
const { generated, expected } = getPostmanConfig({ grouped: false })
expect(_.isEqual(generated, expected)).to.be.true
})

it('[v2.1] - should create config from basic postman file', async () => {
const flags = {
postman:
'./src/components/config/__tests__/mock_files/basic-postman_collection-v2.1.json',
output: 'monika.postman-basic.yml',
}

await createConfig(flags)
expect(fs.lstatSync('monika.postman-basic.yml').isFile()).to.be.true

const { generated, expected } = getPostmanConfig({ grouped: false })
expect(_.isEqual(generated, expected)).to.be.true
})

it('[v2.0] - should create config from grouped postman file', async () => {
const flags = {
postman:
'./src/components/config/__tests__/mock_files/grouped-postman_collection-v2.0.json',
output: 'monika.postman-grouped.yml',
}

await createConfig(flags)
expect(fs.lstatSync('monika.postman-grouped.yml').isFile()).to.be.true

const { generated, expected } = getPostmanConfig({ grouped: true })
expect(_.isEqual(generated, expected)).to.be.true
})

it('[v2.1] - should create config from grouped postman file', async () => {
const flags = {
postman:
'./src/components/config/__tests__/mock_files/grouped-postman_collection-v2.1.json',
output: 'monika.postman-grouped.yml',
}

await createConfig(flags)
expect(fs.lstatSync('monika.postman-grouped.yml').isFile()).to.be.true

const { generated, expected } = getPostmanConfig({ grouped: true })
expect(_.isEqual(generated, expected)).to.be.true
})
})
Expand Down
15 changes: 0 additions & 15 deletions src/components/config/__tests__/expected.postman.yml

This file was deleted.

98 changes: 0 additions & 98 deletions src/components/config/__tests__/grouped.postman_collection.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"info": {
"_postman_id": "7b82602a-a95c-4b91-b783-e7e9251a300a",
"name": "Monika Monitor Collection",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "[GitHub API] Hyperjump Repos",
"request": {
"method": "GET",
"header": [],
"url": "https://api.github.com/users/hyperjumptech/repos"
},
"response": []
},
{
"name": "[GitHub API] Hyperjump",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "any",
"type": "default"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"any\": \"any\"\n}\n",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "https://api.github.com/users/hyperjumptech"
},
"response": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"info": {
"_postman_id": "7b82602a-a95c-4b91-b783-e7e9251a300a",
"name": "Monika Monitor Collection",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "[GitHub API] Hyperjump Repos",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.github.com/users/hyperjumptech/repos",
"protocol": "https",
"host": ["api", "github", "com"],
"path": ["users", "hyperjumptech", "repos"]
}
},
"response": []
},
{
"name": "[GitHub API] Hyperjump",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "any",
"type": "default"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"any\": \"any\"\n}\n",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.github.com/users/hyperjumptech",
"protocol": "https",
"host": ["api", "github", "com"],
"path": ["users", "hyperjumptech"]
}
},
"response": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
probes:
- id: '[GitHub API] Hyperjump Repos'
name: '[GitHub API] Hyperjump Repos'
requests:
- url: https://api.github.com/users/hyperjumptech/repos
method: GET
headers: {}
body: {}
timeout: 10000
incidentThreshold: 5
recoveryThreshold: 5
alerts: []
- id: '[GitHub API] Hyperjump'
name: '[GitHub API] Hyperjump'
requests:
- url: https://api.github.com/users/hyperjumptech
method: GET
headers:
Authorization: any
body:
any: any
timeout: 10000
incidentThreshold: 5
recoveryThreshold: 5
alerts: []
notifications:
- id: default
type: desktop
Loading