automock 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad019453cd437e171e90bb3aa46b0534e0b8ebfb
4
- data.tar.gz: 7ba73e33adf4b48b147b9f9bb20f43bcf36c4630
3
+ metadata.gz: 135fcd6b5d6b550ee5517926d3216d2cffde3d48
4
+ data.tar.gz: c40a97ffe18428bc4f98ccbcb12d228e8b616d4a
5
5
  SHA512:
6
- metadata.gz: aa4345c15d65c374dbf57e1e62416e73d43a1655178f0020a5db45ebb77916ca2a0b75f3bf151e2b317c0e5e50ab426e8047e2fef6a5838ecfaa668f271c4691
7
- data.tar.gz: 2905bc703d27b84b63a59317e88d42c24f564d574677759b48b303b147e18238a6e116e68700c319df4a99e2ba32ec48550dfaa79b3c3432a3790cbe4cae6a30
6
+ metadata.gz: 101888f9eaafb90feecb6210803c661949902ee9a5f779c420f11713f02f763750dd8f9bd4dd48735de386438524b7dcb62a5c2fa894415e92eb7cb8d727a4ad
7
+ data.tar.gz: 9b9ea6d44fe6743f9f49aee3fd5cf1901f3d4181065abf559f5c9a565b52b056e44142b88f1697c71701fb546d3fc06e3979398fb8567246946fc530900340ad
@@ -1,3 +1,3 @@
1
1
  module Automock
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,5 +1,9 @@
1
1
  {
2
2
  "name": "automock",
3
+ "engines" : {
4
+ "node": ">=4.0.0",
5
+ "npm": ">=2.0.0"
6
+ },
3
7
  "devDependencies": {
4
8
  "async": "^1.5.1",
5
9
  "babel": "^6.1.18",
@@ -1,11 +1,23 @@
1
1
  import React from 'react';
2
2
 
3
3
  export default class FileList extends React.Component {
4
+ constructor() {
5
+ super();
6
+ this.state = { searchingValue: '' };
7
+
8
+ }
4
9
  handleSelect(file) {
5
10
  this.props.onChange(file);
6
11
  }
12
+ handleChangeIncrementalSearchInput(e) {
13
+ this.setState({ searchingValue: e.target.value });
14
+ }
7
15
  render() {
8
16
  const options = this.props.files.map((file) => {
17
+ const { searchingValue } = this.state;
18
+ if (searchingValue && file.name.indexOf(searchingValue) < 0) {
19
+ return;
20
+ }
9
21
  let className = 'item';
10
22
  if (file === this.props.viewingFile) {
11
23
  className += ' active';
@@ -23,6 +35,7 @@ export default class FileList extends React.Component {
23
35
  return(
24
36
  <div className="file-list col-xs-5">
25
37
  <h5>{this.props.title}</h5>
38
+ <input className="incremental-search-input" onChange={this.handleChangeIncrementalSearchInput.bind(this)}/>
26
39
  <div className="file-select-box">
27
40
  {options}
28
41
  </div>
@@ -1,6 +1,7 @@
1
1
  .selectable-lists {
2
2
  height: 300px;
3
3
  }
4
+
4
5
  .file-list {
5
6
  margin-bottom: 8px;
6
7
  height: 100%;
@@ -10,6 +11,7 @@
10
11
  overflow-y: auto;
11
12
  overflow-x: hidden;
12
13
  }
14
+
13
15
  .item {
14
16
  color: #555;
15
17
  display: block;
@@ -22,9 +24,15 @@
22
24
  background-color: #f5f5f5;
23
25
  }
24
26
  }
27
+
25
28
  .item.active {
26
29
  color: #fff;
27
30
  background-color: #337ab7;
28
31
  border-color: #337ab7;
29
32
  }
33
+
34
+ .incremental-search-input {
35
+ width: 100%;
36
+ margin-bottom: 4px;
37
+ }
30
38
  }
@@ -1,7 +1,7 @@
1
1
  .select-buttons {
2
2
  display: flex;
3
3
  flex-direction: column;
4
- height: 200px;
4
+ height: 320px;
5
5
  justify-content: space-around;
6
6
 
7
7
  button { display: block; }
@@ -9,20 +9,17 @@ class ProxyServer {
9
9
  constructor() {
10
10
  const targetPort = process.env.AUTOMOCK_TARGET_PORT || 3000;
11
11
  const proxyPort = process.env.AUTOMOCK_PROXY_PORT || 8001;
12
- this.server = httpProxy.createProxyServer({
13
- target:`http://localhost:${targetPort}`
14
- }).listen(proxyPort);
12
+ this.server = httpProxy.createProxyServer({ target:`http://localhost:${targetPort}` }).listen(proxyPort);
15
13
  this.selectedFiles = [];
16
14
  }
17
15
 
18
16
  loadSelectedFiles() {
19
- SelectedFile.findAll().then((records) => {
17
+ return SelectedFile.findAll().then((records) => {
20
18
  this.selectedFiles = records;
21
19
  });
22
20
  }
23
21
 
24
22
  start() {
25
- this.loadSelectedFiles();
26
23
  this.server.on('proxyRes', (_proxyRes, req, res) => {
27
24
  const lookupedSelectedFile = _.find(this.selectedFiles, (selectedFile) =>
28
25
  (selectedFile.uri === req.url) && (selectedFile.method === req.method)
@@ -34,7 +31,7 @@ class ProxyServer {
34
31
  bufs.push(body);
35
32
  };
36
33
  res.end = () => {
37
- fs.readFile(`${process.env.AUTOMOCK_DATA_PATH}/${lookupedSelectedFile.name}`, 'utf8', function (_err, text) {
34
+ fs.readFile(`${process.env.AUTOMOCK_DATA_PATH}/${lookupedSelectedFile.name}`, 'utf8', (_err, text) => {
38
35
  const mockData = JSON.parse(text);
39
36
  writeHead.call(res, mockData.status, mockData.response_header);
40
37
  write.call(res, mockData.response_body);
@@ -44,6 +41,7 @@ class ProxyServer {
44
41
  };
45
42
  }
46
43
  });
44
+ return this.loadSelectedFiles();
47
45
  }
48
46
  }
49
47
 
@@ -1 +1 @@
1
- {"description":"api description","method":"POST","uri":"/api/v1/users","status": "201","response_body":"{\"users\":[{\"username\":\"sample\",\"email\":\"sample@ggg.com\"}]}"}
1
+ {"description":"This is test API","method":"GET","uri":"/test.json","status":200,"response_header":{"X-Frame-Options":"SAMEORIGIN","X-XSS-Protection":"1; mode=block","X-Content-Type-Options":"nosniff","Content-Type":"application/json; charset=utf-8","ETag":"W/\"e224cce5657514dd4f022471dc9261c6\"","Cache-Control":"max-age=0, private, must-revalidate","X-Request-Id":"fbdd7722-e642-4a49-8837-f3c14cc72a4e","X-Runtime":"0.009382","Content-Length":"42"},"response_body":"{\"users\":[{\"user\":{\"name\":\"dummy user\"}}]}"}
@@ -13,12 +13,23 @@ describe('GET /mock_files', function () {
13
13
  get('/mock_files').
14
14
  expect(200, [
15
15
  {
16
- description: 'api description',
17
- method: 'POST',
18
- name: 'test.json',
19
- status: '201',
20
- response_body: '{\"users\":[{\"username\":\"sample\",\"email\":\"sample@ggg.com\"}]}',
21
- uri: '/api/v1/users'
16
+ "description": "This is test API",
17
+ "method": "GET",
18
+ "name": "test.json",
19
+ "response_body": "{\"users\":[{\"user\":{\"name\":\"dummy user\"}}]}",
20
+ "response_header": {
21
+ "Cache-Control": "max-age=0, private, must-revalidate",
22
+ "Content-Length": "42",
23
+ "Content-Type": "application/json; charset=utf-8",
24
+ "ETag": "W/\"e224cce5657514dd4f022471dc9261c6\"",
25
+ "X-Content-Type-Options": "nosniff",
26
+ "X-Frame-Options": "SAMEORIGIN",
27
+ "X-Request-Id": "fbdd7722-e642-4a49-8837-f3c14cc72a4e",
28
+ "X-Runtime": "0.009382",
29
+ "X-XSS-Protection": "1; mode=block"
30
+ },
31
+ "status": 200,
32
+ "uri": "/test.json"
22
33
  },
23
34
  {
24
35
  description: 'description',
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ require('./common_hooks');
4
+ const request = require('superagent');
5
+ const assert = require('power-assert');
6
+
7
+ const http = require('http');
8
+ const ProxyServer = require('../../src/proxy_server');
9
+ const SelectedFile = require('../../dist/models/selected_file');
10
+ const fs = require('fs');
11
+
12
+ let targetServer;
13
+ let proxy;
14
+ describe('ProxyServer', () => {
15
+ before(() => {
16
+ process.env.AUTOMOCK_PROXY_PORT = 9999;
17
+ process.env.AUTOMOCK_TARGET_PORT = 9998;
18
+ targetServer = http.createServer((_req, res) => {
19
+ res.writeHead(200, { 'Content-Type': 'text/plain' });
20
+ res.end('Hello World');
21
+ });
22
+ targetServer.listen(process.env.AUTOMOCK_TARGET_PORT, '127.0.0.1');
23
+ proxy = new ProxyServer();
24
+ });
25
+ after(() => {
26
+ targetServer.close();
27
+ });
28
+
29
+ context('has generated mock_data', () => {
30
+ beforeEach((done) => {
31
+ SelectedFile.create({ name: 'test.json', uri: '/test.json', method: 'GET' }).then(() => {
32
+ proxy.start().then(done);
33
+ });
34
+ });
35
+ it('receives mocked response data.', (done) => {
36
+ request.get('http://127.0.0.1:9999/test.json').
37
+ end((_err, res) => {
38
+ fs.readFile(`${process.env.AUTOMOCK_DATA_PATH}/test.json`, 'utf8', (__err, text) => {
39
+ const expected = JSON.parse(text);
40
+ assert.equal(res.text, expected.response_body);
41
+ assert.equal(res.header['Content-Length'], expected.response_header['content-length']);
42
+ done();
43
+ });
44
+ });
45
+ });
46
+ });
47
+ context("doesn't have generated mock_data", () => {
48
+ beforeEach((done) => {
49
+ proxy.start().then(done);
50
+ });
51
+ it('passes through response.', (done) => {
52
+ request.get('http://127.0.0.1:9999/test.json').
53
+ end((_err, res) => {
54
+ assert.equal(res.text, 'Hello World');
55
+ done();
56
+ });
57
+ });
58
+ });
59
+ });
@@ -11,7 +11,6 @@ describe('GET /selected_files', function () {
11
11
  beforeEach(function () {
12
12
  server = require('./../../dist/index');
13
13
  SelectedFile.create({ name: 'test.json' });
14
- console.log('create?');
15
14
  });
16
15
  it('get selectedFiles and receives 200', function testSlash(done) {
17
16
  request(server).
@@ -36,7 +35,6 @@ describe('GET /selected_files', function () {
36
35
  get('/selected_files').
37
36
  expect(200).
38
37
  end((_err, response) => {
39
- console.log(response.body);
40
38
  assert(response.body.length === 0);
41
39
  done();
42
40
  });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: automock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - joe-re
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-12 00:00:00.000000000 Z
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -155,6 +155,7 @@ files:
155
155
  - server/test/fixtures/mock/test.json
156
156
  - server/test/request/common_hooks.js
157
157
  - server/test/request/mock_files_test.js
158
+ - server/test/request/proxy_server_test.js
158
159
  - server/test/request/selected_files_test.js
159
160
  homepage: https://github.com/joe-re/automock
160
161
  licenses:
@@ -176,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
177
  version: '0'
177
178
  requirements: []
178
179
  rubyforge_project:
179
- rubygems_version: 2.2.5
180
+ rubygems_version: 2.4.5.1
180
181
  signing_key:
181
182
  specification_version: 4
182
183
  summary: Auto-generate mock_data of JSON API response from your request-specs.