Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit f1b20dc

Browse files
author
Dom Harrington
committed
Refactor is-auth-ready tests to use auth-types OAS only
1 parent 1ebf0f4 commit f1b20dc

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

packages/api-explorer-ui/__tests__/fixtures/auth-types/oas.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"post": {
1010
"security": [
1111
{
12-
"oauth2": ["write:things"]
12+
"oauth": ["write:things"]
1313
}
1414
]
1515
}

packages/api-explorer-ui/__tests__/lib/is-auth-ready.test.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,48 @@
11
const isAuthReady = require('../../src/lib/is-auth-ready');
22
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');
54

6-
const oas = new Oas(petstore);
7-
const oas2 = new Oas(auth);
5+
const oas = new Oas(authTypesOas);
86

97
describe('isAuthReady', () => {
108
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');
1210

13-
expect(isAuthReady(operation, { api_key: 'test' })).toBe(true);
11+
expect(isAuthReady(operation, { apiKey: 'test' })).toBe(true);
1412
});
1513

1614
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');
1816

19-
expect(isAuthReady(operation, { api_key: '' })).toBe(false);
17+
expect(isAuthReady(operation, { apiKey: '' })).toBe(false);
2018
});
2119

2220
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');
2422

25-
expect(isAuthReady(operation, { petstore_auth: '' })).toBe(false);
23+
expect(isAuthReady(operation, { oauth: '' })).toBe(false);
2624
});
2725

2826
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');
3028

31-
expect(isAuthReady(operation, { petstore_auth: 'ouath' })).toBe(true);
29+
expect(isAuthReady(operation, { oauth: 'bearer' })).toBe(true);
3230
});
3331

3432
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');
3634

3735
expect(isAuthReady(operation, { basic: { username: 'test', password: 'pass' } })).toBe(true);
3836
});
3937

4038
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');
4240

4341
expect(isAuthReady(operation, { basic: { username: '', password: '' } })).toBe(false);
4442
});
4543

4644
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');
4846

4947
expect(isAuthReady(operation)).toBe(true);
5048
});

0 commit comments

Comments
 (0)