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:
Sergio Díaz 2018-01-11 00:14:22 -06:00 committed by GitHub
commit d598e5e322
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -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,
},
}
`;

View File

@ -3,6 +3,10 @@ const requestPromiseNativeMock = require('request-promise-native');
describe('RequestList', () => {
const endpoint = 'http://martianwabbit.com';
let env = {
environmental: true
};
const doc = {
'POST /session': null,
'Not a Request': null,
@ -21,6 +25,7 @@ describe('RequestList', () => {
requestPromiseNativeMock.fail = false;
requests = new RequestList(doc, {
ENDPOINT: endpoint,
ENVIRONMENT: env,
PLUGINS: [
{
'beau-jwt': {
@ -54,7 +59,7 @@ describe('RequestList', () => {
});
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 () => {
@ -62,6 +67,12 @@ describe('RequestList', () => {
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 () => {
await expect(requests.execByAlias('notAnAlias')).rejects.toThrow(Error);
});