mirror of https://github.com/Seich/Beau.git
Merge pull request #5 from Seich/environment-variables
This adds a missing test for when a request is already in a cache.
This commit is contained in:
commit
d598e5e322
|
|
@ -0,0 +1,21 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`RequestList should execute requests by alias. 1`] = `
|
||||||
|
Object {
|
||||||
|
"body": "{\\"hello\\": \\"world\\"}",
|
||||||
|
"changed": true,
|
||||||
|
"request": Object {
|
||||||
|
"body": Object {
|
||||||
|
"lastname": "Diaz",
|
||||||
|
"name": "Sergio",
|
||||||
|
},
|
||||||
|
"endpoint": "http://martianwabbit.com/user",
|
||||||
|
"headers": Object {},
|
||||||
|
},
|
||||||
|
"response": Object {
|
||||||
|
"body": "{\\"hello\\": \\"world\\"}",
|
||||||
|
"headers": Array [],
|
||||||
|
"status": 200,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
@ -3,6 +3,10 @@ const requestPromiseNativeMock = require('request-promise-native');
|
||||||
|
|
||||||
describe('RequestList', () => {
|
describe('RequestList', () => {
|
||||||
const endpoint = 'http://martianwabbit.com';
|
const endpoint = 'http://martianwabbit.com';
|
||||||
|
let env = {
|
||||||
|
environmental: true
|
||||||
|
};
|
||||||
|
|
||||||
const doc = {
|
const doc = {
|
||||||
'POST /session': null,
|
'POST /session': null,
|
||||||
'Not a Request': null,
|
'Not a Request': null,
|
||||||
|
|
@ -21,6 +25,7 @@ describe('RequestList', () => {
|
||||||
requestPromiseNativeMock.fail = false;
|
requestPromiseNativeMock.fail = false;
|
||||||
requests = new RequestList(doc, {
|
requests = new RequestList(doc, {
|
||||||
ENDPOINT: endpoint,
|
ENDPOINT: endpoint,
|
||||||
|
ENVIRONMENT: env,
|
||||||
PLUGINS: [
|
PLUGINS: [
|
||||||
{
|
{
|
||||||
'beau-jwt': {
|
'beau-jwt': {
|
||||||
|
|
@ -54,7 +59,7 @@ describe('RequestList', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should execute requests by alias.', async () => {
|
it('should execute requests by alias.', async () => {
|
||||||
await requests.execByAlias('user');
|
await expect(requests.execByAlias('user')).resolves.toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if the request fails', async () => {
|
it('should fail if the request fails', async () => {
|
||||||
|
|
@ -62,6 +67,12 @@ describe('RequestList', () => {
|
||||||
await expect(requests.execByAlias('user')).rejects.toThrow(Error);
|
await expect(requests.execByAlias('user')).rejects.toThrow(Error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return a cached result if available', async () => {
|
||||||
|
const obj = { test: true };
|
||||||
|
requests.cache.add('$test', obj);
|
||||||
|
await expect(requests.execByAlias('test')).resolves.toBe(obj);
|
||||||
|
});
|
||||||
|
|
||||||
it('should fail if the alias is not found', async () => {
|
it('should fail if the alias is not found', async () => {
|
||||||
await expect(requests.execByAlias('notAnAlias')).rejects.toThrow(Error);
|
await expect(requests.execByAlias('notAnAlias')).rejects.toThrow(Error);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue