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

Commit 9f6d03f

Browse files
Ilias Tsangariserunion
authored andcommitted
feat: rm-122 format useragent in simple terms
1 parent ae998e0 commit 9f6d03f

19 files changed

+3939
-18685
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
},
1818
moduleNameMapper: {
1919
'.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy',
20+
'\\.svg$': path.join(__dirname, '/lib/svgr-mock.js'),
2021
},
2122
setupFiles: [path.join(__dirname, '/lib/enzyme')],
2223
testMatch: ['**/__tests__/**/(*.)+test.[jt]s?(x)'],

lib/svgr-mock.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// eslint-disable-next-line no-unused-vars
2+
const React = require('react');
3+
4+
module.exports.default = 'SvgrURL';
5+
module.exports.ReactComponent = 'div';

package-lock.json

Lines changed: 2076 additions & 5701 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"@commitlint/cli": "^11.0.0",
5151
"@commitlint/config-conventional": "^11.0.0",
5252
"@readme/eslint-config": "^4.0.0",
53+
"@svgr/webpack": "^5.5.0",
5354
"babel-core": "^7.0.0-bridge.0",
5455
"babel-eslint": "^10.0.3",
5556
"babel-jest": "^26.0.1",
@@ -84,7 +85,7 @@
8485
},
8586
{
8687
"path": "packages/api-logs/dist/index.js",
87-
"maxSize": "10KB"
88+
"maxSize": "15KB"
8889
},
8990
{
9091
"path": "packages/variable/dist/index.js",

packages/api-explorer/package-lock.json

Lines changed: 0 additions & 12830 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api-logs/__tests__/index.test.jsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const React = require('react');
44
const { shallow } = require('enzyme');
55
const nock = require('nock');
66

7-
const { Logs, checkFreshness, handleResponse } = require('../index.jsx');
7+
const { Logs } = require('../index.jsx');
8+
const { checkFreshness, handleResponse } = require('../utils');
89
const requestmodel = require('./fixtures/requestmodel.json');
910
const oas = require('./fixtures/oas.json');
1011
const operation = require('./fixtures/operation.json');
@@ -199,7 +200,26 @@ describe('Logs', () => {
199200
const comp = shallow(<LogTest {...props} />);
200201
requestmodel.requestHeaders[0].value = 'IE4.0';
201202
comp.setState({ logs: [requestmodel] });
202-
expect(comp.contains(<td>IE4.0</td>)).toBe(true);
203+
const tableData = comp.find('td.useragent').first();
204+
expect(tableData.contains('IE4.0')).toBe(true);
205+
});
206+
207+
it('should render certain userAgents in a simplified way with svg icons', () => {
208+
const comp = shallow(<LogTest {...props} />);
209+
requestmodel.requestHeaders[0].value = 'node-fetch/x.x.x';
210+
comp.setState({ logs: [requestmodel] });
211+
const tableData = comp.find('td.useragent').first();
212+
expect(tableData.exists('SvgrURL')).toBe(true);
213+
expect(tableData.contains('node')).toBe(true);
214+
});
215+
216+
it('should render other userAgents without svg icons', () => {
217+
const comp = shallow(<LogTest {...props} />);
218+
requestmodel.requestHeaders[0].value = 'curl/x.x.x';
219+
comp.setState({ logs: [requestmodel] });
220+
const tableData = comp.find('td.useragent').first();
221+
expect(tableData.exists('SvgrURL')).toBe(false);
222+
expect(tableData.contains('curl/x.x.x')).toBe(true);
203223
});
204224

205225
it('should always return a absolute url', async () => {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { getHeaderValue, getFormattedUserAgent } from '../utils';
2+
3+
describe('API Logs Utils', () => {
4+
describe('getHeaderValue', () => {
5+
let headers;
6+
7+
beforeEach(() => {
8+
headers = [
9+
{ name: 'Content-Type', value: 'image/jpeg' },
10+
{ name: 'User-Agent', value: 'Mozilla' },
11+
];
12+
});
13+
14+
it('returns the value of a specified http header', () => {
15+
expect(getHeaderValue(headers, 'User-Agent')).toBe('Mozilla');
16+
});
17+
18+
it('normalizes case of header key', () => {
19+
expect(getHeaderValue(headers, 'content-type')).toBe('image/jpeg');
20+
});
21+
22+
it('returns null if the header is not present', () => {
23+
expect(getHeaderValue(headers, 'not-here')).toBeNull();
24+
});
25+
});
26+
27+
describe('getFormattedUserAgent', () => {
28+
it('outputs an empty string when fed a falsy value user agent', () => {
29+
expect(getFormattedUserAgent('')).toBe('');
30+
expect(getFormattedUserAgent(undefined)).toBe('');
31+
expect(getFormattedUserAgent(null)).toBe('');
32+
});
33+
34+
it('trims whitespace', () => {
35+
expect(getFormattedUserAgent(' ')).toBe('');
36+
expect(getFormattedUserAgent(' a ')).toBe('a');
37+
});
38+
39+
it('handles readme api explorer', () => {
40+
expect(getFormattedUserAgent('ReadMe-API-Explorer')).toBe('ReadMe API Explorer');
41+
});
42+
43+
it('handles node-fetch', () => {
44+
expect(getFormattedUserAgent('node-fetch/x.x.x')).toBe('node');
45+
});
46+
47+
it('handles python-request', () => {
48+
expect(getFormattedUserAgent('python-request/x.x.x')).toBe('python');
49+
});
50+
51+
it('leaves an unknown user agent untouched', () => {
52+
expect(getFormattedUserAgent('foo-bar/baz')).toBe('foo-bar/baz');
53+
});
54+
});
55+
});
Lines changed: 1 addition & 0 deletions
Loading

packages/api-logs/assets/php-logo.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)