Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joyja committed May 22, 2020
1 parent 1d6117f commit e51161f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ test('delete modbus with valid arguments and credentials returns deleted device'
throw error
})
expect(ModbusRTU.prototype.connectTCP).toBeCalledTimes(0)
expect(ModbusRTU.prototype.close).toBeCalledTimes(0)
expect(ModbusRTU.prototype.close).toBeCalledTimes(1)
expect(deleteModbus.id).toEqual(modbus.id)
const { devices } = await client.request(query.devices).catch((error) => {
error
Expand All @@ -648,7 +648,7 @@ test('delete ethernetip with valid arguments and credentials returns deleted dev
throw error
})
expect(Controller.prototype.connect).toBeCalledTimes(0)
expect(Controller.prototype.destroy).toBeCalledTimes(0)
expect(Controller.prototype.destroy).toBeCalledTimes(1)
expect(deleteEthernetIP.id).toEqual(ethernetip.id)
const { devices } = await client.request(query.devices).catch((error) => {
error
Expand Down
12 changes: 8 additions & 4 deletions src/device/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ class Device extends Model {
return super.create(fields)
}
static async delete(selector) {
for (device of Device.instances) {
await instance.config.disconnect()
for (const instance of this.instances) {
if (instance.config) {
await instance.config.disconnect()
}
}
const deleted = await super.delete(selector)
await ModbusSource.getAll()
await Modbus.getAll()
await EthernetIPSource.getAll()
await EthernetIP.getAll()
for (device of Device.instances) {
await instance.config.connect()
for (const instance of this.instances) {
if (instance.config) {
await instance.config.connect()
}
}
return deleted
}
Expand Down

0 comments on commit e51161f

Please sign in to comment.