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

Commit

Permalink
feat: rm-122 format useragent in simple terms
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilias Tsangaris authored and erunion committed Feb 3, 2021
1 parent ae998e0 commit 9f6d03f
Show file tree
Hide file tree
Showing 19 changed files with 3,939 additions and 18,685 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
},
moduleNameMapper: {
'.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy',
'\\.svg$': path.join(__dirname, '/lib/svgr-mock.js'),
},
setupFiles: [path.join(__dirname, '/lib/enzyme')],
testMatch: ['**/__tests__/**/(*.)+test.[jt]s?(x)'],
Expand Down
5 changes: 5 additions & 0 deletions lib/svgr-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// eslint-disable-next-line no-unused-vars
const React = require('react');

module.exports.default = 'SvgrURL';
module.exports.ReactComponent = 'div';
7,777 changes: 2,076 additions & 5,701 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@readme/eslint-config": "^4.0.0",
"@svgr/webpack": "^5.5.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.3",
"babel-jest": "^26.0.1",
Expand Down Expand Up @@ -84,7 +85,7 @@
},
{
"path": "packages/api-logs/dist/index.js",
"maxSize": "10KB"
"maxSize": "15KB"
},
{
"path": "packages/variable/dist/index.js",
Expand Down
12,830 changes: 0 additions & 12,830 deletions packages/api-explorer/package-lock.json

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions packages/api-logs/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const React = require('react');
const { shallow } = require('enzyme');
const nock = require('nock');

const { Logs, checkFreshness, handleResponse } = require('../index.jsx');
const { Logs } = require('../index.jsx');
const { checkFreshness, handleResponse } = require('../utils');
const requestmodel = require('./fixtures/requestmodel.json');
const oas = require('./fixtures/oas.json');
const operation = require('./fixtures/operation.json');
Expand Down Expand Up @@ -199,7 +200,26 @@ describe('Logs', () => {
const comp = shallow(<LogTest {...props} />);
requestmodel.requestHeaders[0].value = 'IE4.0';
comp.setState({ logs: [requestmodel] });
expect(comp.contains(<td>IE4.0</td>)).toBe(true);
const tableData = comp.find('td.useragent').first();
expect(tableData.contains('IE4.0')).toBe(true);
});

it('should render certain userAgents in a simplified way with svg icons', () => {
const comp = shallow(<LogTest {...props} />);
requestmodel.requestHeaders[0].value = 'node-fetch/x.x.x';
comp.setState({ logs: [requestmodel] });
const tableData = comp.find('td.useragent').first();
expect(tableData.exists('SvgrURL')).toBe(true);
expect(tableData.contains('node')).toBe(true);
});

it('should render other userAgents without svg icons', () => {
const comp = shallow(<LogTest {...props} />);
requestmodel.requestHeaders[0].value = 'curl/x.x.x';
comp.setState({ logs: [requestmodel] });
const tableData = comp.find('td.useragent').first();
expect(tableData.exists('SvgrURL')).toBe(false);
expect(tableData.contains('curl/x.x.x')).toBe(true);
});

it('should always return a absolute url', async () => {
Expand Down
55 changes: 55 additions & 0 deletions packages/api-logs/__tests__/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { getHeaderValue, getFormattedUserAgent } from '../utils';

describe('API Logs Utils', () => {
describe('getHeaderValue', () => {
let headers;

beforeEach(() => {
headers = [
{ name: 'Content-Type', value: 'image/jpeg' },
{ name: 'User-Agent', value: 'Mozilla' },
];
});

it('returns the value of a specified http header', () => {
expect(getHeaderValue(headers, 'User-Agent')).toBe('Mozilla');
});

it('normalizes case of header key', () => {
expect(getHeaderValue(headers, 'content-type')).toBe('image/jpeg');
});

it('returns null if the header is not present', () => {
expect(getHeaderValue(headers, 'not-here')).toBeNull();
});
});

describe('getFormattedUserAgent', () => {
it('outputs an empty string when fed a falsy value user agent', () => {
expect(getFormattedUserAgent('')).toBe('');
expect(getFormattedUserAgent(undefined)).toBe('');
expect(getFormattedUserAgent(null)).toBe('');
});

it('trims whitespace', () => {
expect(getFormattedUserAgent(' ')).toBe('');
expect(getFormattedUserAgent(' a ')).toBe('a');
});

it('handles readme api explorer', () => {
expect(getFormattedUserAgent('ReadMe-API-Explorer')).toBe('ReadMe API Explorer');
});

it('handles node-fetch', () => {
expect(getFormattedUserAgent('node-fetch/x.x.x')).toBe('node');
});

it('handles python-request', () => {
expect(getFormattedUserAgent('python-request/x.x.x')).toBe('python');
});

it('leaves an unknown user agent untouched', () => {
expect(getFormattedUserAgent('foo-bar/baz')).toBe('foo-bar/baz');
});
});
});
1 change: 1 addition & 0 deletions packages/api-logs/assets/node-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/api-logs/assets/php-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/api-logs/assets/python-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/api-logs/assets/readme-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/api-logs/assets/ruby-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9f6d03f

Please sign in to comment.