|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +const { mocha, expect, testDB, app, testUser } = require('../common'); |
| 6 | +const chai = require('chai'); |
| 7 | +const Unit = require('../../models/Unit'); |
| 8 | + |
| 9 | +mocha.describe('Units Route', () => { |
| 10 | + let token; |
| 11 | + |
| 12 | + mocha.before(async () => { |
| 13 | + const res = await chai.request(app).post('/api/login') |
| 14 | + .send({ username: testUser.username, password: testUser.password }); |
| 15 | + token = res.body.token; |
| 16 | + }); |
| 17 | + |
| 18 | + mocha.describe('Edit endpoint', () => { |
| 19 | + |
| 20 | + mocha.it('returns 200 and updates the database for valid request', async () => { |
| 21 | + const conn = testDB.getConnection(); |
| 22 | + const unit = new Unit(undefined, 'Unit', 'Unit Id', Unit.unitRepresentType.QUANTITY, |
| 23 | + 1000, Unit.unitType.UNIT, 'Suffix', Unit.displayableType.ALL, true, 'Note'); |
| 24 | + await unit.insert(conn); |
| 25 | + const beforeNote = unit.note; |
| 26 | + const res = await chai.request(app).post('/api/units/edit').set('token', token).send({ |
| 27 | + id: unit.id, |
| 28 | + name: 'New name', |
| 29 | + identifier: unit.identifier, |
| 30 | + }); |
| 31 | + expect(res).to.have.status(200); |
| 32 | + const updatedUnit = await Unit.getById(unit.id, conn); |
| 33 | + expect(updatedUnit.name).to.equal('New name'); |
| 34 | + expect(updatedUnit.note).to.equal(beforeNote); |
| 35 | + }); |
| 36 | + |
| 37 | + }); |
| 38 | + |
| 39 | +}); |
0 commit comments