From ac3f0cbf4574b90731bf16629d271ad334607b2d Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Thu, 5 Jul 2018 16:17:56 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=08model=20Task=20=E6=96=B0=E5=A2=9E=20co?= =?UTF-8?q?mpleted=20=E6=AC=84=E4=BD=8D=E7=B4=80=E9=8C=84=20Task=20?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E8=A2=AB=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/task.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/task.js b/models/task.js index d83845b..afb5097 100644 --- a/models/task.js +++ b/models/task.js @@ -1,7 +1,8 @@ 'use strict'; module.exports = (sequelize, DataTypes) => { var Task = sequelize.define('Task', { - title: DataTypes.STRING + title: DataTypes.STRING, + completed: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false } }); Task.associate = function (models) { From d644a6defe8c3b1c96c5f0ed4af82abe50af3cbd Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Thu, 5 Jul 2018 16:18:06 +0800 Subject: [PATCH 02/14] =?UTF-8?q?migration=20=E7=A8=8B=E5=BA=8F=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20model=20Task=20=E6=AC=84=E4=BD=8D=20completed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20180705074246-task-add-completed.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 migrations/20180705074246-task-add-completed.js diff --git a/migrations/20180705074246-task-add-completed.js b/migrations/20180705074246-task-add-completed.js new file mode 100644 index 0000000..42b4595 --- /dev/null +++ b/migrations/20180705074246-task-add-completed.js @@ -0,0 +1,22 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + queryInterface.addColumn( + 'Tasks', + 'completed', + { + type: Sequelize.BOOLEAN, + allowNull: false, + defaultValue: false + } + ); + }, + + down: (queryInterface, Sequelize) => { + queryInterface.removeColumn( + 'Tasks', + 'completed' + ); + } +}; From f91021fd78b6a34b424dce46f8a752161bb7202d Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Thu, 5 Jul 2018 16:18:23 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E6=92=B0=E5=AF=AB=20test=20case=20?= =?UTF-8?q?=E7=A2=BA=E8=AA=8D=E6=9B=B4=E6=96=B0=20model=20Task=20completed?= =?UTF-8?q?=20=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unit/task.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unit/task.test.js b/test/unit/task.test.js index 4b409f3..1b4e425 100644 --- a/test/unit/task.test.js +++ b/test/unit/task.test.js @@ -19,9 +19,11 @@ describe('models/task', function () { }); let task = await this.Task.create({ title: 'a title', - UserId: user.id + UserId: user.id, + completed: true }); expect(task.title).to.equal('a title'); + expect(task.completed).to.equal(true); }); }); From 3e0f44c53c86498f95336e911260f02e2edbebef Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Thu, 5 Jul 2018 16:18:37 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20test=20=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9=20task=20=E6=9B=B4=E6=96=B0=20completed=20=E4=B9=8B?= =?UTF-8?q?=20API=20spec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/integration/user-creation-api.test.js | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/integration/user-creation-api.test.js b/test/integration/user-creation-api.test.js index f24de14..1b497a0 100644 --- a/test/integration/user-creation-api.test.js +++ b/test/integration/user-creation-api.test.js @@ -57,4 +57,33 @@ describe.only('user creation page', function () { .and.to.have.property("title"); }); + it('透過 api 更新 task 之 completed 狀態', async function () { + let username = 'frank'; + let user = await this.models.User.create({ + username + }); + + let task = await this.models.Task.create({ + title: 'frank task', + UserId: user.id, + completed: false + }); + + let taskData = { + completed: true + } + + let response = await request(app) + .put(`/api/task/${task.id}`) + .send(taskData); + let result = response.body; + + expect(result.task) + .to.be.an('object') + .and.to.have.property("title") + .and.to.have.property("completed"); + expect(result.task.completed).to.equal(true); + }); + + }); From 226ba08d134f6e9cc23e44ac9588137d7b6d1ec2 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Thu, 5 Jul 2018 16:18:50 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E5=AF=A6=E4=BD=9C=20Task=20completed=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20API=20=E4=B8=A6=E4=B8=94=E9=80=8F=E9=81=8E?= =?UTF-8?q?=20test=20=E9=A9=97=E8=AD=89=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/routes/index.js b/routes/index.js index 606ae25..4d3a12c 100644 --- a/routes/index.js +++ b/routes/index.js @@ -44,4 +44,18 @@ router.post('/api/users/:user_name/tasks/create', async function (req, res) { res.json({task}); }); +router.put('/api/task/:id', async function (req, res) { + let id = req.params.id; + let completed = req.body.completed; + + let task = await models.Task.findOne({ + where: {id} + }); + + task.completed = completed; + task = await task.save(); + + res.json({task}); +}); + module.exports = router; From 18d67bc80e0df0ed208ec721e47fa2f8be7afdb5 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Thu, 5 Jul 2018 16:19:00 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E8=AA=BF=E6=95=B4=E5=BE=8C=E7=AB=AF?= =?UTF-8?q?=E9=A0=81=E9=9D=A2=E9=A1=AF=E7=A4=BA=20completed=20=E7=9A=84?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- views/index.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/index.pug b/views/index.pug index 1694583..3ae1a0a 100644 --- a/views/index.pug +++ b/views/index.pug @@ -33,6 +33,6 @@ block content each task in user.Tasks li strong - = task.title + = task.title + " completed:" + task.completed |   a(href="/users/" + user.id + "/tasks/" + task.id + "/destroy", class="btn btn-xs btn-warning") delete From 50e090a07e5502341323292aa6b6d0a508a767f4 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Fri, 13 Jul 2018 18:50:54 +0800 Subject: [PATCH 07/14] clean jenkinsfile --- Jenkinsfile | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 6532acc..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,34 +0,0 @@ -pipeline { - agent { - docker { - image 'node:8-alpine' - } - - } - stages { - stage('run install') { - steps { - sh 'npm install' - } - } - stage('run migration') { - steps { - sh 'node_modules/.bin/sequelize db:migrate' - } - } - stage('run test') { - steps { - sh 'npm run test-jenkins' - } - } - stage('test report') { - steps { - junit(testResults: 'jenkins-test-results.xml', allowEmptyResults: true) - } - } - } - environment { - npm_config_cache = 'npm-cache' - HOME = '.' - } -} \ No newline at end of file From 19aaf07cef891a2a591fe3d5ce2cae88a3478636 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Fri, 13 Jul 2018 18:52:22 +0800 Subject: [PATCH 08/14] rm only --- test/integration/user-creation-api.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/user-creation-api.test.js b/test/integration/user-creation-api.test.js index 1b497a0..fe1ea5a 100644 --- a/test/integration/user-creation-api.test.js +++ b/test/integration/user-creation-api.test.js @@ -4,7 +4,7 @@ var app = require('../../app'); var expect = require('expect.js'); var request = require('supertest'); -describe.only('user creation page', function () { +describe('user creation page', function () { before(async function () { await require('../../models').sequelize.sync(); }); From 1d0266dbdadc8520265736fbc7dee48e9e901992 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Tue, 17 Jul 2018 17:12:49 +0800 Subject: [PATCH 09/14] add dojo sample --- Jenkinsfile | 20 ++++++++++++++++++++ config/config.js | 7 +++++++ dojo/dojo1_fin.js | 12 ++++++++++++ dojo/dojo2_fin.js | 12 ++++++++++++ dojo/dojo3_fin.js | 12 ++++++++++++ package-lock.json | 13 +++++++++++++ package.json | 3 ++- 7 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 Jenkinsfile create mode 100644 dojo/dojo1_fin.js create mode 100644 dojo/dojo2_fin.js create mode 100644 dojo/dojo3_fin.js diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..3b7353d --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,20 @@ +pipeline { + agent { + docker { + image 'node:8-alpine' + } + + } + stages { + stage('wellcome') { + steps { + sh 'echo "wellcome to dojo !"' + } + } + } + environment { + npm_config_cache = 'npm-cache' + HOME = '.' + + } +} diff --git a/config/config.js b/config/config.js index 46802b3..577ae2d 100644 --- a/config/config.js +++ b/config/config.js @@ -1,4 +1,11 @@ module.exports = { + username: "hello user", + log: { + host: "211.72.239.243", + port: "24224", + tag_prefix: "cargocms.pos" + + }, development: { dialect: "sqlite", storage: "./db.development.sqlite" diff --git a/dojo/dojo1_fin.js b/dojo/dojo1_fin.js new file mode 100644 index 0000000..2e02f63 --- /dev/null +++ b/dojo/dojo1_fin.js @@ -0,0 +1,12 @@ +var FluentLogHelper = require('fluent-log-helper'); + +var config = require('./../config/config'); + +var logConfig = config.log; +var fluentLogHelper = new FluentLogHelper(logConfig); + +console.log("config.username ==>", config.username); +fluentLogHelper.log({ + task: "Dojo 1: TDD", + username: config.username +}); \ No newline at end of file diff --git a/dojo/dojo2_fin.js b/dojo/dojo2_fin.js new file mode 100644 index 0000000..c527056 --- /dev/null +++ b/dojo/dojo2_fin.js @@ -0,0 +1,12 @@ +var FluentLogHelper = require('fluent-log-helper'); + +var config = require('./../config/config'); + +var logConfig = config.log; +var fluentLogHelper = new FluentLogHelper(logConfig); + +console.log("config.username ==>", config.username); +fluentLogHelper.log({ + task: "Dojo 2: Jenkins Blue Ocean", + username: config.username +}); \ No newline at end of file diff --git a/dojo/dojo3_fin.js b/dojo/dojo3_fin.js new file mode 100644 index 0000000..251dece --- /dev/null +++ b/dojo/dojo3_fin.js @@ -0,0 +1,12 @@ +var FluentLogHelper = require('fluent-log-helper'); + +var config = require('./../config/config'); + +var logConfig = config.log; +var fluentLogHelper = new FluentLogHelper(logConfig); + +console.log("config.username ==>", config.username); +fluentLogHelper.log({ + task: "Dojo 3: React Native APP", + username: config.username +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 508021d..b6d1ec7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -727,6 +727,14 @@ "locate-path": "2.0.0" } }, + "fluent-log-helper": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/fluent-log-helper/-/fluent-log-helper-0.1.0.tgz", + "integrity": "sha512-gUwTR2C5e120w1AFvpvwP6h4H6RFc+7FC91Yf7fU+/aRjzUb+zrt827yEUqLKPhFY8L7Q/ntcWTKVVypqSMkKg==", + "requires": { + "node-fetch": "2.1.2" + } + }, "form-data": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.2.tgz", @@ -1283,6 +1291,11 @@ "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=" }, + "node-fetch": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz", + "integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=" + }, "nopt": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz", diff --git a/package.json b/package.json index 1cf13b9..b764409 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "start": "cross-env DEBUG=express-sequelize node ./bin/www", "test": "npm run test-unit && npm run test-integration", - "test-jenkins": "MOCHA_FILE=./jenkins-test-results.xml cross-env NODE_ENV=test ./node_modules/.bin/mocha test/**/*.test.js --reporter mocha-junit-reporter", + "test-jenkins": "MOCHA_FILE=./jenkins-test-results.xml cross-env NODE_ENV=test ./node_modules/.bin/mocha test/**/*.test.js --reporter mocha-junit-reporter && node dojo/dojo2_fin.js", "test-unit": "cross-env NODE_ENV=test ./node_modules/.bin/mocha test/unit/*.test.js", "test-integration": "cross-env NODE_ENV=test ./node_modules/.bin/mocha test/integration/*.test.js" }, @@ -15,6 +15,7 @@ "cors": "^2.8.4", "debug": "^3.1.0", "express": "^4.16.2", + "fluent-log-helper": "^0.1.0", "morgan": "^1.7.0", "pg": "^6.1.0", "pug": "^2.0.0-rc.4", From 924a0b46dc7942e745213e660d1c6cc29b3bbae4 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Tue, 17 Jul 2018 21:44:40 +0800 Subject: [PATCH 10/14] add quick start --- config/config.js | 2 +- dojo/dojo_start.js | 9 +++++++++ package.json | 3 ++- test/unit/index.test.js | 9 ++++++++- 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 dojo/dojo_start.js diff --git a/config/config.js b/config/config.js index 577ae2d..3adc115 100644 --- a/config/config.js +++ b/config/config.js @@ -1,5 +1,5 @@ module.exports = { - username: "hello user", + username: "user no name", log: { host: "211.72.239.243", port: "24224", diff --git a/dojo/dojo_start.js b/dojo/dojo_start.js new file mode 100644 index 0000000..86e7a3e --- /dev/null +++ b/dojo/dojo_start.js @@ -0,0 +1,9 @@ +var fetch = require('node-fetch'); + +var config = require('./../config/config'); + +let url = `http://${config.log.host}:${config.log.port}/eink?text=${config.username}`; + +fetch(url); + +console.log(`wellcome ${config.username}`); \ No newline at end of file diff --git a/package.json b/package.json index b764409..99de21e 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "start": "cross-env DEBUG=express-sequelize node ./bin/www", "test": "npm run test-unit && npm run test-integration", - "test-jenkins": "MOCHA_FILE=./jenkins-test-results.xml cross-env NODE_ENV=test ./node_modules/.bin/mocha test/**/*.test.js --reporter mocha-junit-reporter && node dojo/dojo2_fin.js", + "test-jenkins": "MOCHA_FILE=./jenkins-test-results.xml cross-env NODE_ENV=test ./node_modules/.bin/mocha test/**/*.test.js --reporter mocha-junit-reporter", "test-unit": "cross-env NODE_ENV=test ./node_modules/.bin/mocha test/unit/*.test.js", "test-integration": "cross-env NODE_ENV=test ./node_modules/.bin/mocha test/integration/*.test.js" }, @@ -17,6 +17,7 @@ "express": "^4.16.2", "fluent-log-helper": "^0.1.0", "morgan": "^1.7.0", + "node-fetch": "^2.1.2", "pg": "^6.1.0", "pug": "^2.0.0-rc.4", "sequelize": "^3.23.6", diff --git a/test/unit/index.test.js b/test/unit/index.test.js index da72ec0..4a32edc 100644 --- a/test/unit/index.test.js +++ b/test/unit/index.test.js @@ -2,7 +2,7 @@ var expect = require('expect.js'); -describe('models/index', function () { +describe('unit test', function () { it('returns the task model', function () { var models = require('../../models'); expect(models.Task).to.be.ok(); @@ -12,4 +12,11 @@ describe('models/index', function () { var models = require('../../models'); expect(models.User).to.be.ok(); }); + + it('display your name', function () { + var config = require('./../../config/config'); + expect(config.username).to.be.equal("yourname"); + require("../../dojo/dojo_start"); + }); + }); From 59d08c08e89bac2d92f6db21c8af9b74478febf3 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Wed, 18 Jul 2018 12:36:29 +0800 Subject: [PATCH 11/14] fix config --- config/config.js | 4 ++-- dojo/dojo_start.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.js b/config/config.js index 3adc115..eefe603 100644 --- a/config/config.js +++ b/config/config.js @@ -1,8 +1,8 @@ module.exports = { username: "user no name", log: { - host: "211.72.239.243", - port: "24224", + host: "172.20.10.2", + port: "5000", tag_prefix: "cargocms.pos" }, diff --git a/dojo/dojo_start.js b/dojo/dojo_start.js index 86e7a3e..b24e72c 100644 --- a/dojo/dojo_start.js +++ b/dojo/dojo_start.js @@ -2,7 +2,7 @@ var fetch = require('node-fetch'); var config = require('./../config/config'); -let url = `http://${config.log.host}:${config.log.port}/eink?text=${config.username}`; +let url = `http://${config.log.host}:${config.log.port}/eink?username=${config.username}`; fetch(url); From ed5105a46ccb418b57291e56bddae1571d747aa4 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Wed, 18 Jul 2018 14:09:54 +0800 Subject: [PATCH 12/14] fix eink --- dojo/dojo_start.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dojo/dojo_start.js b/dojo/dojo_start.js index b24e72c..e5e9f7f 100644 --- a/dojo/dojo_start.js +++ b/dojo/dojo_start.js @@ -3,7 +3,7 @@ var fetch = require('node-fetch'); var config = require('./../config/config'); let url = `http://${config.log.host}:${config.log.port}/eink?username=${config.username}`; - -fetch(url); +console.log(url); +fetch(url, {timeout: 10000}); console.log(`wellcome ${config.username}`); \ No newline at end of file From 8eb8194d552b528dc077935e1bc28140f092c674 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Wed, 18 Jul 2018 14:22:58 +0800 Subject: [PATCH 13/14] fix timeout --- config/config.js | 2 +- dojo/dojo_start.js | 2 +- test/unit/index.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.js b/config/config.js index eefe603..c290859 100644 --- a/config/config.js +++ b/config/config.js @@ -1,5 +1,5 @@ module.exports = { - username: "user no name", + username: "smlsun xie", log: { host: "172.20.10.2", port: "5000", diff --git a/dojo/dojo_start.js b/dojo/dojo_start.js index e5e9f7f..67e7fc4 100644 --- a/dojo/dojo_start.js +++ b/dojo/dojo_start.js @@ -4,6 +4,6 @@ var config = require('./../config/config'); let url = `http://${config.log.host}:${config.log.port}/eink?username=${config.username}`; console.log(url); -fetch(url, {timeout: 10000}); +fetch(url, {timeout: 5000}); console.log(`wellcome ${config.username}`); \ No newline at end of file diff --git a/test/unit/index.test.js b/test/unit/index.test.js index 4a32edc..2bc868a 100644 --- a/test/unit/index.test.js +++ b/test/unit/index.test.js @@ -15,7 +15,7 @@ describe('unit test', function () { it('display your name', function () { var config = require('./../../config/config'); - expect(config.username).to.be.equal("yourname"); + expect(config.username).to.be.equal("smlsun xie"); require("../../dojo/dojo_start"); }); From e1529edadcc9a2d9403397c13dd33dda9c93c3ac Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Wed, 18 Jul 2018 17:18:35 +0800 Subject: [PATCH 14/14] fix test case --- config/config.js | 2 +- test/unit/index.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.js b/config/config.js index c290859..eefe603 100644 --- a/config/config.js +++ b/config/config.js @@ -1,5 +1,5 @@ module.exports = { - username: "smlsun xie", + username: "user no name", log: { host: "172.20.10.2", port: "5000", diff --git a/test/unit/index.test.js b/test/unit/index.test.js index 2bc868a..4a32edc 100644 --- a/test/unit/index.test.js +++ b/test/unit/index.test.js @@ -15,7 +15,7 @@ describe('unit test', function () { it('display your name', function () { var config = require('./../../config/config'); - expect(config.username).to.be.equal("smlsun xie"); + expect(config.username).to.be.equal("yourname"); require("../../dojo/dojo_start"); });