diff --git a/Jenkinsfile b/Jenkinsfile index 6532acc..3b7353d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,30 +5,16 @@ pipeline { } } - stages { - stage('run install') { + stages { + stage('wellcome') { 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) + sh 'echo "wellcome to dojo !"' } } } environment { npm_config_cache = 'npm-cache' HOME = '.' + } -} \ No newline at end of file +} diff --git a/config/config.js b/config/config.js index 46802b3..eefe603 100644 --- a/config/config.js +++ b/config/config.js @@ -1,4 +1,11 @@ module.exports = { + username: "user no name", + log: { + host: "172.20.10.2", + port: "5000", + 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/dojo/dojo_start.js b/dojo/dojo_start.js new file mode 100644 index 0000000..67e7fc4 --- /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?username=${config.username}`; +console.log(url); +fetch(url, {timeout: 5000}); + +console.log(`wellcome ${config.username}`); \ No newline at end of file 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) { 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..99de21e 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "cors": "^2.8.4", "debug": "^3.1.0", "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/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; diff --git a/test/integration/user-creation-api.test.js b/test/integration/user-creation-api.test.js index f24de14..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(); }); @@ -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); + }); + + }); 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"); + }); + }); 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); }); }); 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