mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Add tests for authentication getter & setter. Refactor the setter method
This commit is contained in:
parent
0bab48e3e5
commit
2dd8bd93cd
@ -27,6 +27,7 @@ describe('init()', () => {
|
||||
expect(Object.keys(result.request).sort()).toEqual([
|
||||
'addHeader',
|
||||
'addParameter',
|
||||
'getAuthentication',
|
||||
'getBodyText',
|
||||
'getEnvironment',
|
||||
'getEnvironmentVariable',
|
||||
@ -42,6 +43,7 @@ describe('init()', () => {
|
||||
'hasParameter',
|
||||
'removeHeader',
|
||||
'removeParameter',
|
||||
'setAuthentication',
|
||||
'setBodyText',
|
||||
'setCookie',
|
||||
'setHeader',
|
||||
@ -57,6 +59,7 @@ describe('init()', () => {
|
||||
const result = plugin.init(await models.request.getById('req_1'), CONTEXT, true);
|
||||
expect(Object.keys(result)).toEqual(['request']);
|
||||
expect(Object.keys(result.request).sort()).toEqual([
|
||||
'getAuthentication',
|
||||
'getBodyText',
|
||||
'getEnvironment',
|
||||
'getEnvironmentVariable',
|
||||
@ -87,6 +90,7 @@ describe('request.*', () => {
|
||||
parentId: 'wrk_1',
|
||||
name: 'My Request',
|
||||
body: { text: 'body' },
|
||||
authentication: { type: 'oauth2' },
|
||||
headers: [
|
||||
{ name: 'hello', value: 'world' },
|
||||
{ name: 'Content-Type', value: 'application/json' },
|
||||
@ -102,6 +106,7 @@ describe('request.*', () => {
|
||||
expect(result.request.getUrl()).toBe('');
|
||||
expect(result.request.getMethod()).toBe('GET');
|
||||
expect(result.request.getBodyText()).toBe('body');
|
||||
expect(result.request.getAuthentication()).toEqual({ type: 'oauth2' });
|
||||
});
|
||||
|
||||
it('works for parameters', async () => {
|
||||
@ -203,4 +208,16 @@ describe('request.*', () => {
|
||||
expect(result.request.getEnvironmentVariable('null_test')).toBe(null);
|
||||
expect(result.request.getEnvironmentVariable('bad')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('works for authentication', async () => {
|
||||
const request = await models.request.getById('req_1');
|
||||
request.authentication = {}; // Because the plugin technically needs a RenderedRequest
|
||||
|
||||
const result = plugin.init(request, CONTEXT);
|
||||
|
||||
result.request.setAuthentication('foo', 'bar');
|
||||
result.request.setAuthentication('foo', 'baz');
|
||||
expect(result.request.getAuthentication()).toEqual({ foo: 'baz' });
|
||||
expect(request.authentication).toEqual({ foo: 'baz' });
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user