From ec86232f2a575aff45b58934412a021643c8d66f Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Tue, 10 Jul 2018 17:06:00 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20test=20=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9=20task=20=E5=88=AA=E9=99=A4=E4=B9=8B=20API=20spec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/integration/user-creation-api.test.js | 38 +++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/test/integration/user-creation-api.test.js b/test/integration/user-creation-api.test.js index 1b497a0..3e525bd 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(); }); @@ -84,6 +84,42 @@ describe.only('user creation page', function () { .and.to.have.property("completed"); expect(result.task.completed).to.equal(true); }); + it.only('透過 api 提供刪除 task 功能', async function () { + let username = 'frank test delete'; + let user = await this.models.User.create({ + username + }); + + let task = await this.models.Task.create({ + title: 'frank test delete', + UserId: user.id, + completed: false + }); + + user = await this.models.User.findOne({ + where: {username}, + include: this.models.Task + }); + expect(user.Tasks).to.be.an('array') + expect(user.Tasks.length).to.be.equal(1); + + let response = await request(app) + .del(`/api/task/${task.id}`); + let result = response.body; + expect(result.task) + .to.be.an('object') + .and.to.have.property("title") + .and.to.have.property("completed"); + user = await this.models.User.findOne({ + where: {username}, + include: this.models.Task + }); + + expect(user.Tasks).to.be.an('array') + expect(user.Tasks.length).to.be.equal(0); + + + }); }); From 6204f5d742aaceb2aa21084c7db86ed89c4167d5 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Tue, 10 Jul 2018 17:08:19 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=AF=A6=E4=BD=9C=20task=20=E5=88=AA?= =?UTF-8?q?=E9=99=A4=E4=B9=8B=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/routes/index.js b/routes/index.js index 4d3a12c..7e5bea4 100644 --- a/routes/index.js +++ b/routes/index.js @@ -58,4 +58,21 @@ router.put('/api/task/:id', async function (req, res) { res.json({task}); }); +router.delete('/api/task/:id', async function (req, res) { + let id = req.params.id; + + + let task = await models.Task.findOne({ + where: { + id + } + }); + + task = await task.destroy(); + + res.json({ + task + }); +}); + module.exports = router; From ec0fb2be62b83cf410323613cf893bf137e8b656 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Fri, 13 Jul 2018 18:50:54 +0800 Subject: [PATCH 3/4] 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 fd82419f1974f2e3bc020490f635fe98fda19cd7 Mon Sep 17 00:00:00 2001 From: smlsunxie Date: Fri, 13 Jul 2018 18:52:22 +0800 Subject: [PATCH 4/4] 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 3e525bd..88cfaf9 100644 --- a/test/integration/user-creation-api.test.js +++ b/test/integration/user-creation-api.test.js @@ -84,7 +84,7 @@ describe('user creation page', function () { .and.to.have.property("completed"); expect(result.task.completed).to.equal(true); }); - it.only('透過 api 提供刪除 task 功能', async function () { + it('透過 api 提供刪除 task 功能', async function () { let username = 'frank test delete'; let user = await this.models.User.create({ username