mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
add test for unknown bootloader command
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
||||
disconnect,
|
||||
eraseRequest,
|
||||
eraseResponse,
|
||||
errorResponse,
|
||||
infoRequest,
|
||||
infoResponse,
|
||||
initRequest,
|
||||
@@ -40,7 +41,7 @@ import {
|
||||
rebootRequest,
|
||||
} from '../actions/lwp3-bootloader';
|
||||
import { didCompile, didFailToCompile } from '../actions/mpy';
|
||||
import { HubType, Result } from '../protocols/lwp3-bootloader';
|
||||
import { Command, HubType, Result } from '../protocols/lwp3-bootloader';
|
||||
import { BootloaderConnectionState } from '../reducers/bootloader';
|
||||
import { createCountFunc } from '../utils/iter';
|
||||
import flashFirmware from './flash-firmware';
|
||||
@@ -397,6 +398,79 @@ describe('flashFirmware', () => {
|
||||
await saga.end();
|
||||
});
|
||||
|
||||
test('info request is unknown command', async () => {
|
||||
const metadata: FirmwareMetadata = {
|
||||
'metadata-version': '1.0.0',
|
||||
'device-id': HubType.MoveHub,
|
||||
'checksum-type': 'sum',
|
||||
'firmware-version': '1.2.3',
|
||||
'max-firmware-size': 1024,
|
||||
'mpy-abi-version': 5,
|
||||
'mpy-cross-options': ['-mno-unicode'],
|
||||
'user-mpy-offset': 100,
|
||||
};
|
||||
|
||||
const zip = new JSZip();
|
||||
zip.file('firmware-base.bin', new Uint8Array(64));
|
||||
zip.file('firmware.metadata.json', JSON.stringify(metadata));
|
||||
zip.file('main.py', 'print("test")');
|
||||
zip.file('ReadMe_OSS.txt', 'test');
|
||||
|
||||
jest.spyOn(window, 'fetch').mockResolvedValueOnce(
|
||||
new Response(await zip.generateAsync({ type: 'blob' })),
|
||||
);
|
||||
|
||||
const saga = new AsyncSaga(
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
},
|
||||
);
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(flashFirmwareAction());
|
||||
|
||||
// first step is to connect to the hub bootloader
|
||||
|
||||
let action = await saga.take();
|
||||
expect(action).toEqual(connect());
|
||||
|
||||
saga.updateState({
|
||||
bootloader: { connection: BootloaderConnectionState.Connected },
|
||||
});
|
||||
saga.put(didConnect());
|
||||
|
||||
// then find out what kind of hub it is
|
||||
|
||||
action = await saga.take();
|
||||
expect(action).toEqual(infoRequest(0));
|
||||
|
||||
saga.put(didRequest(0));
|
||||
saga.put(errorResponse(Command.GetInfo));
|
||||
|
||||
// should get an unknown command failure
|
||||
|
||||
action = await saga.take();
|
||||
expect(action).toEqual(
|
||||
didFailToFinish(
|
||||
FailToFinishReasonType.HubError,
|
||||
HubError.UnknownCommand,
|
||||
),
|
||||
);
|
||||
|
||||
// should request to disconnect after failure
|
||||
|
||||
action = await saga.take();
|
||||
expect(action).toEqual(disconnect());
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
|
||||
test('timeout waiting for info response', async () => {
|
||||
const metadata: FirmwareMetadata = {
|
||||
'metadata-version': '1.0.0',
|
||||
|
||||
Reference in New Issue
Block a user