Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions packages/api-logs/__tests__/fixtures/requestmodel.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,151 @@
"subdomain" : "readme",
"clientIPAddress" : "someip",
"development" : false,
"creator" : {
"name" : "readmeio",
"version" : "0.0.0",
"comment" : "linux/v8.11.2"
},
"startedDateTime" : "2018-08-16T00:02:12.999+0000",
"responseTime": 3,
"method": "GET",
"url" : "https://dash.readme.io/api/v1/docs/search?query=test",
"httpVersion" : "1.1",
"requestHeaders" : [
{
"name" : "user-agent",
"value" : "curl/7.54.0",
"_id" : "5b74bf05774f44001dd990f1"
},
{
"name" : "host",
"value" : "readme.readme.io",
"_id" : "5b74bf05774f44001dd990f6"
},
{
"name" : "connection",
"value" : "close",
"_id" : "5b74bf05774f44001dd990f5"
},
{
"name" : "x-forwarded-host",
"value" : "dash.readme.io",
"_id" : "5b74bf05774f44001dd990f4"
},
{
"name" : "accept",
"value" : "*/*",
"_id" : "5b74bf05774f44001dd990f3"
},
{
"name" : "x-forwarded-for",
"value" : "136.24.201.16, 54.210.159.126",
"_id" : "5b74bf05774f44001dd990f0"
},
{
"name" : "x-forwarded-port",
"value" : "443",
"_id" : "5b74bf05774f44001dd990ef"
},
{
"name" : "x-forwarded-proto",
"value" : "https",
"_id" : "5b74bf05774f44001dd990ee"
},
{
"name" : "x-request-id",
"value" : "b2dd95ae-04fb-4e44-ad0a-2e5b73162317",
"_id" : "5b74bf05774f44001dd990ed"
},
{
"name" : "via",
"value" : "1.1 vegur",
"_id" : "5b74bf05774f44001dd990ec"
},
{
"name" : "connect-time",
"value" : "0",
"_id" : "5b74bf05774f44001dd990eb"
}
],
"queryString" : [
{
"name" : "query",
"value" : "test",
"_id" : "5b74bf05774f44001dd990f7"
}
],
"requestBody" : {
"mimeType" : "application/json",
"params" : [

]
},
"status": "400",
"statusText" : "Bad Request",
"headers" : [
{
"name" : "x-xss-protection",
"value" : "1; mode=block",
"_id" : "5b74bf05774f44001dd99102"
},
{
"name" : "x-dns-prefetch-control",
"value" : "off",
"_id" : "5b74bf05774f44001dd99101"
},
{
"name" : "x-frame-options",
"value" : "Deny",
"_id" : "5b74bf05774f44001dd99100"
},
{
"name" : "strict-transport-security",
"value" : "max-age=15552000; includeSubDomains",
"_id" : "5b74bf05774f44001dd990ff"
},
{
"name" : "x-download-options",
"value" : "noopen",
"_id" : "5b74bf05774f44001dd990fe"
},
{
"name" : "x-content-type-options",
"value" : "nosniff",
"_id" : "5b74bf05774f44001dd990fd"
},
{
"name" : "x-powered-by",
"value" : "Express",
"_id" : "5b74bf05774f44001dd990fc"
},
{
"name" : "content-type",
"value" : "application/json; charset=utf-8",
"_id" : "5b74bf05774f44001dd990fb"
},
{
"name" : "content-length",
"value" : "80",
"_id" : "5b74bf05774f44001dd990fa"
},
{
"name" : "etag",
"value" : "W/\"50-iwDQZvKva0kjfFp1QELFLv23tQg\"",
"_id" : "5b74bf05774f44001dd990f9"
},
{
"name" : "vary",
"value" : "Accept-Encoding",
"_id" : "5b74bf05774f44001dd990f8"
}
],
"responseBody": {
"text" : "{\"error\":\"Bad Request\",\"description\":\"You must provide a version\",\"errors\":null}",
"size" : 80,
"mimeType" : "application/json; charset=utf-8",
"_id" : "5b74bf05774f44001dd99103"
},
"createdAt" : "2018-08-16T00:02:13.081+0000",
"updatedAt" : "2018-08-16T00:02:13.081+0000"
}
4 changes: 2 additions & 2 deletions packages/api-logs/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Logs', () => {
it('should render a log with no user-agent', () => {
const comp = shallow(<LogTest {...props} />);
const clonedLog = JSON.parse(JSON.stringify(requestmodel));
clonedLog.request.log.entries[0].request.headers[0].name = '';
clonedLog.requestHeaders[0].name = '';
comp.setState({ logs: [clonedLog] });

expect(
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('Logs', () => {

it('when parsed agent is not Other', () => {
const comp = shallow(<LogTest {...props} />);
requestmodel.request.log.entries[0].request.headers[0].value = 'IE4.0';
requestmodel.requestHeaders[0].value = 'IE4.0';
comp.setState({ logs: [requestmodel] });
expect(comp.contains(<td>IE4.0</td>)).toBe(true);
});
Expand Down
11 changes: 4 additions & 7 deletions packages/api-logs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ const LoadingSvg = props => (
);

function getLanguage(log) {
const header = log.request.log.entries[0].request.headers.find(
e => e.name.toLowerCase() === 'user-agent',
);
const header = log.requestHeaders.find(e => e.name.toLowerCase() === 'user-agent');
if (header) return header.value;
return '-';
}
Expand Down Expand Up @@ -154,12 +152,11 @@ class Logs extends React.Component {
const { logs } = this.state;

return logs.map(log => {
const entry = log.request.log.entries[0];
return (
<tr key={log._id} onClick={this.visitLogItem.bind(this, log)}>
<td>{entry.request.method}</td>
<td>{entry.response.status}</td>
<td>{entry.request.url}</td>
<td>{log.method}</td>
<td>{log.status}</td>
<td>{log.url}</td>
<td>{log.group.label}</td>
<td>{getLanguage(log)}</td>
<td>{new Date(log.createdAt).toLocaleString()}</td>
Expand Down