mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-15 03:41:28 +00:00
Merge pull request #5690 from james-ha-bruno/feat/add-get-tags-for-requests
adding req getTags methods
This commit is contained in:
@@ -27,6 +27,7 @@ const STATIC_API_HINTS = {
|
||||
'req.setTimeout(timeout)',
|
||||
'req.getExecutionMode()',
|
||||
'req.getName()',
|
||||
'req.getTags()',
|
||||
'req.disableParsingResponseJson()',
|
||||
'req.onFail(function(err) {})',
|
||||
],
|
||||
|
||||
@@ -42,6 +42,7 @@ const prepareRequest = async (item = {}, collection = {}) => {
|
||||
url: request.url,
|
||||
headers: headers,
|
||||
name: item.name,
|
||||
tags: item.tags || [],
|
||||
pathParams: request.params?.filter((param) => param.type === 'path'),
|
||||
settings: item.settings,
|
||||
responseType: 'arraybuffer'
|
||||
|
||||
@@ -346,6 +346,7 @@ const prepareRequest = async (item, collection = {}, abortController) => {
|
||||
url,
|
||||
headers,
|
||||
name: item.name,
|
||||
tags: item.tags || [],
|
||||
pathParams: request.params?.filter((param) => param.type === 'path'),
|
||||
settings,
|
||||
responseType: 'arraybuffer'
|
||||
|
||||
@@ -18,6 +18,7 @@ class BrunoRequest {
|
||||
this.headers = req.headers;
|
||||
this.timeout = req.timeout;
|
||||
this.name = req.name;
|
||||
this.tags = req.tags || [];
|
||||
/**
|
||||
* We automatically parse the JSON body if the content type is JSON
|
||||
* This is to make it easier for the user to access the body directly
|
||||
@@ -189,6 +190,14 @@ class BrunoRequest {
|
||||
getName() {
|
||||
return this.req.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tags associated with this request
|
||||
* @returns {Array<string>} Array of tag strings
|
||||
*/
|
||||
getTags() {
|
||||
return this.req.tags || [];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BrunoRequest;
|
||||
|
||||
@@ -9,6 +9,7 @@ const addBrunoRequestShimToContext = (vm, req) => {
|
||||
const body = marshallToVm(req.getBody(), vm);
|
||||
const timeout = marshallToVm(req.getTimeout(), vm);
|
||||
const name = marshallToVm(req.getName(), vm);
|
||||
const tags = marshallToVm(req.getTags(), vm);
|
||||
|
||||
vm.setProp(reqObject, 'url', url);
|
||||
vm.setProp(reqObject, 'method', method);
|
||||
@@ -16,6 +17,7 @@ const addBrunoRequestShimToContext = (vm, req) => {
|
||||
vm.setProp(reqObject, 'body', body);
|
||||
vm.setProp(reqObject, 'timeout', timeout);
|
||||
vm.setProp(reqObject, 'name', name);
|
||||
vm.setProp(reqObject, 'tags', tags);
|
||||
|
||||
url.dispose();
|
||||
method.dispose();
|
||||
@@ -23,6 +25,7 @@ const addBrunoRequestShimToContext = (vm, req) => {
|
||||
body.dispose();
|
||||
timeout.dispose();
|
||||
name.dispose();
|
||||
tags.dispose();
|
||||
|
||||
let getUrl = vm.newFunction('getUrl', function () {
|
||||
return marshallToVm(req.getUrl(), vm);
|
||||
@@ -126,6 +129,12 @@ const addBrunoRequestShimToContext = (vm, req) => {
|
||||
vm.setProp(reqObject, 'getExecutionMode', getExecutionMode);
|
||||
getExecutionMode.dispose();
|
||||
|
||||
let getTags = vm.newFunction('getTags', function () {
|
||||
return marshallToVm(req.getTags(), vm);
|
||||
});
|
||||
vm.setProp(reqObject, 'getTags', getTags);
|
||||
getTags.dispose();
|
||||
|
||||
vm.setProp(vm.global, 'req', reqObject);
|
||||
reqObject.dispose();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
meta {
|
||||
name: getTags
|
||||
type: http
|
||||
seq: 11
|
||||
tags: [
|
||||
api
|
||||
test
|
||||
tags
|
||||
]
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{host}}/api/echo/json
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
// Test getTags() function
|
||||
const tags = req.getTags();
|
||||
bru.setVar('request-tags', tags);
|
||||
}
|
||||
|
||||
tests {
|
||||
test("req.getTags() should return array of tags", function() {
|
||||
const tags = bru.getVar('request-tags');
|
||||
expect(tags).to.be.an('array');
|
||||
expect(tags).to.include('api');
|
||||
expect(tags).to.include('test');
|
||||
expect(tags).to.include('tags');
|
||||
expect(tags.length).to.be.equal(3);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user