|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const path = require('path') |
| 4 | +const chai = require('chai') |
| 5 | +const lt = require('loopback-testing') |
| 6 | +const request = require('supertest') |
| 7 | + |
| 8 | +chai.use(require('dirty-chai')) |
| 9 | +chai.use(require('sinon-chai')) |
| 10 | + |
| 11 | +const { expect } = chai |
| 12 | + |
| 13 | +const TEST_APP = path.join(__dirname, 'fullcube-state-machine') |
| 14 | +const app = require(path.join(TEST_APP, 'server/server.js')) |
| 15 | + |
| 16 | +chai.use(require('dirty-chai')) |
| 17 | + |
| 18 | +// Helper function to make api requests. |
| 19 | +function json(verb, reqUrl) { |
| 20 | + return request(app)[verb](reqUrl) |
| 21 | + .set('Content-Type', 'application/json') |
| 22 | + .set('Accept', 'application/json') |
| 23 | +} |
| 24 | + |
| 25 | +describe('REST', function() { |
| 26 | + |
| 27 | + lt.beforeEach.withApp(app) |
| 28 | + |
| 29 | + describe('Basic handling', function() { |
| 30 | + lt.beforeEach.givenModel('Order', {}, 'order') |
| 31 | + it('Should return the updated order', function() { |
| 32 | + return json('put', `/api/orders/${this.order.id}/cancel`) |
| 33 | + .send() |
| 34 | + .expect(200) |
| 35 | + .then(res => expect(res.body.status).to.equal('canceled')) |
| 36 | + }) |
| 37 | + }) |
| 38 | + |
| 39 | + describe('Error handling', function() { |
| 40 | + lt.beforeEach.givenModel('Order', {}, 'order') |
| 41 | + it('Should return the rejected error', function() { |
| 42 | + return json('put', `/api/orders/${this.order.id}/disable`) |
| 43 | + .send() |
| 44 | + .expect(405) |
| 45 | + .then(res => { |
| 46 | + expect(res.error).to.have.property('message') |
| 47 | + expect(res.body.error).to.have.property('message', 'Disable method is not yet allowed') |
| 48 | + }) |
| 49 | + }) |
| 50 | + }) |
| 51 | + |
| 52 | +}) |
0 commit comments