Skip to content

Commit

Permalink
Fix: missing query in api-blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
pustovitDmytro committed Aug 27, 2022
1 parent 0105e14 commit de6826b
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"incredible"
],
"rules": {
"more/no-hardcoded-password": 0
"more/no-hardcoded-password": 0,
"unicorn/catch-error-name": 0
},
"overrides": [{
"files": "tests/examples/*test.js",
Expand Down
1 change: 1 addition & 0 deletions examples/weather/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function customTitle(req) {
: 'Get list of forecasts'
};
}

router.get('/forecasts', chr(customTitle), forecastsList);

app.use('/api', router);
Expand Down
7 changes: 4 additions & 3 deletions examples/weather/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export function cityCreate(req, res) {
}

export function forecastsList(req, res) {
res.send(forecasts.filter(i => req.query.cityId
? i.city === +req.query.cityId
: true)
res.send(
forecasts.filter(i => req.query.cityId
? i.city === +req.query.cityId
: true)
);
}

Expand Down
7 changes: 7 additions & 0 deletions templates/reporters/api-blueprint.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ FORMAT: 1A
{{@key}}: {{this}}
{{/each}}
{{/if}}
{{#if (notEmpty request.query)}}

+ Parameters
{{#each request.query}}
{{@key}}: {{this}}
{{/each}}
{{/if}}
{{#if request.body}}

+ Body
Expand Down
58 changes: 58 additions & 0 deletions tests/features/query.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { assert } from 'chai';
import Test from '../Test';
import chronicle, { reporters, Axios } from '../entry';
import { mockAppUrl } from '../constants';

const Reporter = reporters['api-blueprint'];

const factory = new Test(chronicle);
const axios = new Axios(chronicle);

suite('Feature: request query');

before(async function () {
await factory.cleanup();
await factory.setActions();
await factory.setTmpFolder();
await factory.startMockApp();
});

test('Positive: capture query from axios', async function () {
const context = { title: 'paggination', group: 'axios queries' };

const response = await axios({
method : 'GET',
url : `${mockAppUrl}/api/users?limit=10&offset=20`,
with : context
});

assert.isNotEmpty(response.data);
const action = factory.ensureAction(context, {
method : 'GET',
path : '/api/users'
});

assert.deepOwnInclude(action.toJSON().request, {
query : { limit: '10', offset: '20' }
});
});

test('Positive: save query in api-blueprint', async function () {
const seed = factory.findAction({
'group' : 'Features',
'title' : 'query'
});
const action = seed.data;

const groups = { [action.context.group]: { [action.context.title]: [ action.id ] } };
const reporter = new Reporter();
const map = new Map([ [ action.id, action ] ]);

await reporter._init();
console.log(reporter._generate(groups, map));
assert.match(reporter._generate(groups, map), /\+ Request\s*\+ Parameters\s*status: ACTIVE/);
});

after(async function () {
await factory.cleanup();
});
15 changes: 15 additions & 0 deletions tests/mock/fixtures/actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,20 @@
"link": "http://pabeve.ao/mum",
"country": "Turkmenistan"
}
},
{
"context": {
"group": "Features",
"title": "query"
},
"url": "http://127.0.0.1:62887/users?status=ACTIVE",
"method": "GET",
"resBody": [
{
"id": 1,
"status": "ACTIVE",
"name": "Kathryn Grant"
}
]
}
]

0 comments on commit de6826b

Please sign in to comment.