|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { Port } from '../../node/cli-protocol/cc/arduino/cli/commands/v1/port_pb'; |
| 3 | +import { CoreServiceImpl } from '../../node/core-service-impl'; |
| 4 | + |
| 5 | +describe('core-service-impl', () => { |
| 6 | + describe('createPort', () => { |
| 7 | + it("should map the 'undefined' port object to an 'undefined' gRPC port value", () => { |
| 8 | + const actual = new CoreServiceImpl()['createPort'](undefined); |
| 9 | + expect(actual).to.be.undefined; |
| 10 | + }); |
| 11 | + |
| 12 | + it('should map a port object to the appropriate gRPC port object', () => { |
| 13 | + const properties = { |
| 14 | + alma: 'false', |
| 15 | + korte: '36', |
| 16 | + }; |
| 17 | + const port = { |
| 18 | + address: 'address', |
| 19 | + addressLabel: 'address label', |
| 20 | + hardwareId: '1730323', |
| 21 | + protocol: 'serial', |
| 22 | + protocolLabel: 'serial port', |
| 23 | + properties, |
| 24 | + } as const; |
| 25 | + const actual = new CoreServiceImpl()['createPort'](port); |
| 26 | + expect(actual).to.be.not.undefined; |
| 27 | + const expected = new Port() |
| 28 | + .setAddress(port.address) |
| 29 | + .setHardwareId(port.hardwareId) |
| 30 | + .setLabel(port.addressLabel) |
| 31 | + .setProtocol(port.protocol) |
| 32 | + .setProtocolLabel(port.protocolLabel); |
| 33 | + Object.entries(properties).forEach(([key, value]) => |
| 34 | + expected.getPropertiesMap().set(key, value) |
| 35 | + ); |
| 36 | + expect((<Port>actual).toObject(false)).to.be.deep.equal( |
| 37 | + expected.toObject(false) |
| 38 | + ); |
| 39 | + }); |
| 40 | + }); |
| 41 | +}); |
0 commit comments