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 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; diff --git a/test/integration/user-creation-api.test.js b/test/integration/user-creation-api.test.js index 1b497a0..88cfaf9 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('透過 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); + + + }); });