feat: kboot package (#894)
* feat: kboot package * feat: kboot package * fix: wait 1 sec after device is available * test: fix unit test * refactor: clean unused codes * doc: improve readme.md * doc: improve readme.md * test: fix unit test * chore: fix lint settings * style: fix linting issues
This commit is contained in:
committed by
László Monda
parent
bfc08edfce
commit
3964698cf7
36
packages/kboot/test/kboot.spec.ts
Normal file
36
packages/kboot/test/kboot.spec.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { BootloaderVersion, CommandResponse, Commands, KBoot, Peripheral, Properties, ResponseCodes, ResponseTags } from '../src';
|
||||
import { TestPeripheral } from './test-peripheral';
|
||||
|
||||
describe('kboot', () => {
|
||||
let kboot: KBoot;
|
||||
let testPeripheral: Peripheral;
|
||||
|
||||
beforeEach(() => {
|
||||
testPeripheral = new TestPeripheral();
|
||||
kboot = new KBoot(testPeripheral);
|
||||
});
|
||||
|
||||
describe('getBootloaderVersion', () => {
|
||||
it('should works', async () => {
|
||||
const sendCommandResponse: CommandResponse = {
|
||||
code: ResponseCodes.Success,
|
||||
tag: ResponseTags.Property,
|
||||
// tslint:disable-next-line:max-line-length
|
||||
raw: Buffer.from([0x03, 0x00, 0x0c, 0x00, 0xa7, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
|
||||
};
|
||||
spyOn(testPeripheral, 'sendCommand').and.returnValue(Promise.resolve(sendCommandResponse));
|
||||
const version = await kboot.getBootloaderVersion();
|
||||
const expectedVersion: BootloaderVersion = {
|
||||
protocolName: 'K',
|
||||
major: 2,
|
||||
minor: 0,
|
||||
bugfix: 0
|
||||
};
|
||||
expect(version).toEqual(expectedVersion);
|
||||
expect(testPeripheral.sendCommand).toHaveBeenCalledWith({
|
||||
command: Commands.GetProperty,
|
||||
params: [1, 0, 0, 0, 0, 0, 0, 0]
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user