|
1 | 1 | const isAuthReady = require('../../src/lib/is-auth-ready');
|
2 | 2 | const Oas = require('../../src/lib/Oas.js');
|
3 |
| -const petstore = require('../fixtures/petstore/oas'); |
4 |
| -const auth = require('../fixtures/auth-types/oas'); |
| 3 | +const authTypesOas = require('../fixtures/auth-types/oas'); |
5 | 4 |
|
6 |
| -const oas = new Oas(petstore); |
7 |
| -const oas2 = new Oas(auth); |
| 5 | +const oas = new Oas(authTypesOas); |
8 | 6 |
|
9 | 7 | describe('isAuthReady', () => {
|
10 | 8 | it('should return true if auth data is passed in correctly for api key condition', () => {
|
11 |
| - const operation = oas.operation('/pet/{petId}', 'get'); |
| 9 | + const operation = oas.operation('/api-key', 'post'); |
12 | 10 |
|
13 |
| - expect(isAuthReady(operation, { api_key: 'test' })).toBe(true); |
| 11 | + expect(isAuthReady(operation, { apiKey: 'test' })).toBe(true); |
14 | 12 | });
|
15 | 13 |
|
16 | 14 | it('should return false if auth data is not passed in for api key condition', () => {
|
17 |
| - const operation = oas.operation('/pet/{petId}', 'get'); |
| 15 | + const operation = oas.operation('/api-key', 'post'); |
18 | 16 |
|
19 |
| - expect(isAuthReady(operation, { api_key: '' })).toBe(false); |
| 17 | + expect(isAuthReady(operation, { apiKey: '' })).toBe(false); |
20 | 18 | });
|
21 | 19 |
|
22 | 20 | it('should return false if auth data is not passed in correctly for oauth condition', () => {
|
23 |
| - const operation = oas.operation('/pet/{petId}', 'delete'); |
| 21 | + const operation = oas.operation('/oauth', 'post'); |
24 | 22 |
|
25 |
| - expect(isAuthReady(operation, { petstore_auth: '' })).toBe(false); |
| 23 | + expect(isAuthReady(operation, { oauth: '' })).toBe(false); |
26 | 24 | });
|
27 | 25 |
|
28 | 26 | it('should return true if auth data is passed in correctly for oauth condition', () => {
|
29 |
| - const operation = oas.operation('/pet/{petId}', 'delete'); |
| 27 | + const operation = oas.operation('/oauth', 'post'); |
30 | 28 |
|
31 |
| - expect(isAuthReady(operation, { petstore_auth: 'ouath' })).toBe(true); |
| 29 | + expect(isAuthReady(operation, { oauth: 'bearer' })).toBe(true); |
32 | 30 | });
|
33 | 31 |
|
34 | 32 | it('should return true if auth data is passed in for basic condition', () => {
|
35 |
| - const operation = oas2.operation('/basic', 'post'); |
| 33 | + const operation = oas.operation('/basic', 'post'); |
36 | 34 |
|
37 | 35 | expect(isAuthReady(operation, { basic: { username: 'test', password: 'pass' } })).toBe(true);
|
38 | 36 | });
|
39 | 37 |
|
40 | 38 | it('should return false if auth data is not passed in for basic condition', () => {
|
41 |
| - const operation = oas2.operation('/basic', 'post'); |
| 39 | + const operation = oas.operation('/basic', 'post'); |
42 | 40 |
|
43 | 41 | expect(isAuthReady(operation, { basic: { username: '', password: '' } })).toBe(false);
|
44 | 42 | });
|
45 | 43 |
|
46 | 44 | it('should return true if endpoint does not need auth or passed in auth is correct', () => {
|
47 |
| - const operation = oas.operation('/store/order/{orderId}', 'get'); |
| 45 | + const operation = oas.operation('/no-auth', 'post'); |
48 | 46 |
|
49 | 47 | expect(isAuthReady(operation)).toBe(true);
|
50 | 48 | });
|
|
0 commit comments