Skip to content

Commit

Permalink
rewrites entire Postman tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-hyperjump committed Jun 23, 2022
1 parent 9f30b54 commit 56212c3
Show file tree
Hide file tree
Showing 12 changed files with 601 additions and 212 deletions.
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

0 comments on commit 56212c3

Please sign in to comment.