Skip to content

Commit

Permalink
SWG-9025 tests + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MiloszTarka committed Jan 18, 2024
1 parent 559c8e1 commit 002469d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ USAGE
* [`swaggerhub api:unpublish OWNER/API_NAME/VERSION`](#swaggerhub-apiunpublish)
* [`swaggerhub api:update OWNER/API_NAME/[VERSION]`](#swaggerhub-apiupdate)
* [`swaggerhub api:validate OWNER/API_NAME/[VERSION]`](#swaggerhub-apivalidate)
* [`swaggerhub api:validate:download-rules OWNER`](#swaggerhub-apivalidatedownload-rules)
* [`swaggerhub api:validate:local`](#swaggerhub-apivalidatelocal)
* [`swaggerhub configure`](#swaggerhub-configure)
* [`swaggerhub domain:create OWNER/DOMAIN_NAME/[VERSION]`](#swaggerhub-domaincreate)
Expand Down Expand Up @@ -425,6 +426,37 @@ EXAMPLES

_See code: [src/commands/api/validate/local.js](https://github.com/SmartBear/swaggerhub-cli/blob/v0.8.1/src/commands/api/validate/local.js)_

## `swaggerhub api:validate:download-rules`

Get existing SwaggerHub's organization standardization ruleset.

```
USAGE
$ swaggerhub api:validate:download-rules OWNER [-s] [-d] [-h]
ARGUMENTS
OWNER Which organization standardization rules to fetch from SwaggerHub
FLAGS
-d, --include-disabled-rules Includes disabled rules in fetched organization's ruleset
-h, --help Show CLI help.
-s, --include-system-rules Includes system rules in fetched organization's ruleset
DESCRIPTION
Get existing SwaggerHub's organization standardization ruleset.
Requires organization name argument. An error will occur if provided organization is non existing
or your account is not permitted to access that organization settings.
If the flag `-s` or `--include-system-rules` is used, the returned ruleset will also include SwaggerHub system rules.
If the flag `-d` or `--include-disabled-rules` is used, the returned ruleset will also include disabled custom rules
EXAMPLES
$ swaggerhub api:validate:download-rules myOrg -s
$ swaggerhub api:validate:download-rules myOrg --include-disabled-rules -s
```

_See code: [src/commands/api/validate/download-rules.js](https://github.com/SmartBear/swaggerhub-cli/blob/v0.8.1/src/commands/api/validate/download-rules.js)_

## `swaggerhub configure`

configure application settings
Expand Down
12 changes: 8 additions & 4 deletions src/commands/api/validate/download-rules.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { Flags, Args } = require('@oclif/core')
const BaseValidateCommand = require('../../../support/command/base-validate-command')
const BaseCommand = require('../../../support/command/base-command')
const { pipeAsync } = require('../../../utils/general')
const { getResponseContent } = require('../../../support/command/handle-response')
const { getStandardization } = require('../../../requests/standardization')

class ValidateDownloadRulesCommand extends BaseValidateCommand {
class ValidateDownloadRulesCommand extends BaseCommand {
async run() {
const { args, flags } = await this.parse(ValidateDownloadRulesCommand)

Expand All @@ -25,7 +25,11 @@ class ValidateDownloadRulesCommand extends BaseValidateCommand {
}
}

ValidateDownloadRulesCommand.description = `TODO`
ValidateDownloadRulesCommand.description = `Get existing SwaggerHub's organization standardization ruleset.
Requires organization name argument. An error will occur if provided organization is non existing
or your account is not permitted to access that organization settings.
If the flag \`-s\` or \`--include-system-rules\` is used, the returned ruleset will also include SwaggerHub system rules.
If the flag \`-d\` or \`--include-disabled-rules\` is used, the returned ruleset will also include disabled custom rules`

ValidateDownloadRulesCommand.examples = [
'swaggerhub api:validate:download-rules myOrg -s',
Expand All @@ -49,6 +53,6 @@ ValidateDownloadRulesCommand.flags = {
description: 'Includes disabled rules in fetched organization\'s ruleset',
required: false
}),
...BaseValidateCommand.flags
...BaseCommand.flags
}
module.exports = ValidateDownloadRulesCommand
19 changes: 7 additions & 12 deletions test/commands/api/validate/download-rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
ruleset,
rulesetWithDisabledRule,
rulesetWithSystemRule,
rulesetWithDisabledAndSystemRule, basicRules
rulesetWithDisabledAndSystemRule
} = require('../../../resources/rulesets')

const orgName = 'org1'
Expand All @@ -15,7 +15,6 @@ describe('invalid api:validate:download-rules', () => {
.exit(2)
.it('runs api:validate:download-rules with no organization name provided')


test
.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' }))
.nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' }}, api => api
Expand All @@ -25,18 +24,15 @@ describe('invalid api:validate:download-rules', () => {
)
.command(['api:validate:download-rules', 'org2'])
.exit(2)
.it('Access Denied returned when trying to fetch ruleset of not existing organization')
.it('Access Denied returned when trying to fetch ruleset of not existing or not available organization')

test
.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' }))
.nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' }}, api => api
.get(`/org2/spectral`)
.query({ includeSystemRules : false, includeDisabledRules : false})
.reply(404, 'Access Denied')
.stub(config, 'isURLValid', () => false)
.command(['api:validate:download-rules', 'org1'])
.catch(ctx =>
expect(ctx.message).to.equal('Please verify that the configured SwaggerHub URL is correct.')
)
.command(['api:validate:download-rules', 'org2'])
.exit(2)
.it('Access Denied returned when trying to fetch ruleset of not existing organization')
.it('invalid SwaggerHub URL provided in the config')
})

describe('valid api:validate:download-rules', () => {
Expand Down Expand Up @@ -66,7 +62,6 @@ describe('valid api:validate:download-rules', () => {
expect(ctx.stdout).to.contains(JSON.stringify(rulesetWithSystemRule, null, 2))
})


test
.stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' }))
.nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' }}, api => api
Expand Down

0 comments on commit 002469d

Please sign in to comment.