mirror of https://github.com/Seich/Beau.git
Added support for multiple request configurations. (#54)
This allows multiple requests to hit the same verb+path combination.
This was previously impossible, to address it, it's now possible to pass
an array of request settings as the body of a request each request will
be added to the request list individually.
Example:
```
GET /some/path:
- alias: first
headers:
request: first
- alias: second
headers:
request: second
```
This commit is contained in:
parent
8a1ecc67bd
commit
94332bd125
File diff suppressed because it is too large
Load Diff
|
|
@ -157,4 +157,20 @@ describe('Config', () => {
|
||||||
let config = new Config(doc);
|
let config = new Config(doc);
|
||||||
expect(config.REQUESTS[0].HEADERS.hello).toBe(1);
|
expect(config.REQUESTS[0].HEADERS.hello).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(`should allow different settings for the same request`, () => {
|
||||||
|
const doc = yaml.safeLoad(`
|
||||||
|
host: https://example.com
|
||||||
|
GET /1:
|
||||||
|
- alias: req1
|
||||||
|
headers:
|
||||||
|
request: 1
|
||||||
|
- alias: req2
|
||||||
|
headers:
|
||||||
|
request: 2
|
||||||
|
`);
|
||||||
|
|
||||||
|
let config = new Config(doc);
|
||||||
|
expect(config.REQUESTS.length).toBe(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,20 @@ class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadRequests(host, settings) {
|
loadRequests(host, settings) {
|
||||||
let requests = Object.entries(host)
|
Object.entries(host)
|
||||||
.filter(([key]) => requestRegex.test(key))
|
.filter(([key]) => requestRegex.test(key))
|
||||||
.map(([key, rDefinition]) => {
|
.forEach(([key, rDefinition]) => {
|
||||||
|
if (Array.isArray(rDefinition)) {
|
||||||
|
rDefinition.forEach(req =>
|
||||||
|
this.addRequest(key, req, settings)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.addRequest(key, rDefinition, settings);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addRequest(key, rDefinition, settings) {
|
||||||
let requestDefinitionIsString = typeof rDefinition === 'string';
|
let requestDefinitionIsString = typeof rDefinition === 'string';
|
||||||
let originalRequest = requestDefinitionIsString
|
let originalRequest = requestDefinitionIsString
|
||||||
? { ALIAS: rDefinition }
|
? { ALIAS: rDefinition }
|
||||||
|
|
@ -72,10 +83,7 @@ class Config {
|
||||||
|
|
||||||
let defaults = UpperCaseKeys(settings.DEFAULTS);
|
let defaults = UpperCaseKeys(settings.DEFAULTS);
|
||||||
|
|
||||||
return deepMerge(defaults, request);
|
this.REQUESTS.push(deepMerge(defaults, request));
|
||||||
});
|
|
||||||
|
|
||||||
this.REQUESTS = this.REQUESTS.concat(requests);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadConfig(host) {
|
loadConfig(host) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue