@@ -8,26 +8,32 @@ vi.mock('../../gen/service/motion/v1/motion_pb_service');
8
8
vi . mock ( '../../robot' ) ;
9
9
10
10
import { Struct , Timestamp } from '@bufbuild/protobuf' ;
11
- import {
12
- createPromiseClient ,
13
- createRouterTransport ,
14
- } from '@connectrpc/connect' ;
11
+ import { createClient , createRouterTransport } from '@connectrpc/connect' ;
15
12
import { MotionService } from '../../gen/service/motion/v1/motion_connect' ;
16
13
import {
17
14
GetPlanRequest ,
18
15
ListPlanStatusesRequest ,
19
16
MoveOnGlobeRequest ,
20
17
MoveOnGlobeResponse ,
18
+ MoveRequest ,
21
19
StopPlanRequest ,
22
20
} from '../../gen/service/motion/v1/motion_pb' ;
23
- import { GeoGeometry , GeoPoint , ResourceName } from '../../types' ;
21
+ import {
22
+ GeoGeometry ,
23
+ GeoPoint ,
24
+ Pose ,
25
+ PoseInFrame ,
26
+ ResourceName ,
27
+ } from '../../types' ;
24
28
import { MotionClient } from './client' ;
25
29
import {
30
+ Constraints ,
26
31
GetPlanResponse ,
27
32
ListPlanStatusesResponse ,
28
33
MotionConfiguration ,
29
34
ObstacleDetector ,
30
35
PlanState ,
36
+ PseudolinearConstraint ,
31
37
} from './types' ;
32
38
33
39
const motionClientName = 'test-motion' ;
@@ -76,9 +82,7 @@ describe('moveOnGlobe', () => {
76
82
77
83
RobotClient . prototype . createServiceClient = vi
78
84
. fn ( )
79
- . mockImplementation ( ( ) =>
80
- createPromiseClient ( MotionService , mockTransport )
81
- ) ;
85
+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
82
86
83
87
motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
84
88
@@ -226,9 +230,7 @@ describe('moveOnGlobe', () => {
226
230
227
231
RobotClient . prototype . createServiceClient = vi
228
232
. fn ( )
229
- . mockImplementation ( ( ) =>
230
- createPromiseClient ( MotionService , mockTransport )
231
- ) ;
233
+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
232
234
233
235
motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
234
236
@@ -263,6 +265,64 @@ describe('moveOnGlobe', () => {
263
265
} ) ;
264
266
} ) ;
265
267
268
+ describe ( 'move' , ( ) => {
269
+ it ( 'sends a move request with pseudolinear constraints' , async ( ) => {
270
+ const expectedComponentName = new ResourceName ( {
271
+ namespace : 'viam' ,
272
+ type : 'component' ,
273
+ subtype : 'base' ,
274
+ name : 'myBase' ,
275
+ } ) ;
276
+ const expectedDestination = new PoseInFrame ( {
277
+ referenceFrame : 'world' ,
278
+ pose : new Pose ( {
279
+ x : 1 ,
280
+ y : 2 ,
281
+ z : 3 ,
282
+ oX : 0 ,
283
+ oY : 0 ,
284
+ oZ : 1 ,
285
+ theta : 90 ,
286
+ } ) ,
287
+ } ) ;
288
+ const expectedPseudolinearConstraint = new PseudolinearConstraint ( {
289
+ lineToleranceFactor : 5 ,
290
+ orientationToleranceFactor : 10 ,
291
+ } ) ;
292
+ const expectedConstraints = new Constraints ( {
293
+ pseudolinearConstraint : [ expectedPseudolinearConstraint ] ,
294
+ } ) ;
295
+ const expectedExtra = { some : 'extra' } ;
296
+ let capturedReq : MoveRequest | undefined ;
297
+ const mockTransport = createRouterTransport ( ( { service } ) => {
298
+ service ( MotionService , {
299
+ move : ( req ) => {
300
+ capturedReq = req ;
301
+ return { success : true } ;
302
+ } ,
303
+ } ) ;
304
+ } ) ;
305
+ RobotClient . prototype . createServiceClient = vi
306
+ . fn ( )
307
+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
308
+ motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
309
+ await expect (
310
+ motion . move (
311
+ expectedDestination ,
312
+ expectedComponentName ,
313
+ undefined ,
314
+ expectedConstraints ,
315
+ expectedExtra
316
+ )
317
+ ) . resolves . toStrictEqual ( true ) ;
318
+ expect ( capturedReq ?. name ) . toStrictEqual ( motionClientName ) ;
319
+ expect ( capturedReq ?. destination ) . toStrictEqual ( expectedDestination ) ;
320
+ expect ( capturedReq ?. componentName ) . toStrictEqual ( expectedComponentName ) ;
321
+ expect ( capturedReq ?. constraints ) . toStrictEqual ( expectedConstraints ) ;
322
+ expect ( capturedReq ?. extra ) . toStrictEqual ( Struct . fromJson ( expectedExtra ) ) ;
323
+ } ) ;
324
+ } ) ;
325
+
266
326
describe ( 'stopPlan' , ( ) => {
267
327
it ( 'return null' , async ( ) => {
268
328
const expectedComponentName = new ResourceName ( {
@@ -285,9 +345,7 @@ describe('stopPlan', () => {
285
345
286
346
RobotClient . prototype . createServiceClient = vi
287
347
. fn ( )
288
- . mockImplementation ( ( ) =>
289
- createPromiseClient ( MotionService , mockTransport )
290
- ) ;
348
+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
291
349
292
350
motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
293
351
@@ -318,9 +376,7 @@ describe('stopPlan', () => {
318
376
319
377
RobotClient . prototype . createServiceClient = vi
320
378
. fn ( )
321
- . mockImplementation ( ( ) =>
322
- createPromiseClient ( MotionService , mockTransport )
323
- ) ;
379
+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
324
380
325
381
motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
326
382
@@ -393,9 +449,7 @@ describe('getPlan', () => {
393
449
394
450
RobotClient . prototype . createServiceClient = vi
395
451
. fn ( )
396
- . mockImplementation ( ( ) =>
397
- createPromiseClient ( MotionService , mockTransport )
398
- ) ;
452
+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
399
453
400
454
motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
401
455
@@ -430,9 +484,7 @@ describe('getPlan', () => {
430
484
431
485
RobotClient . prototype . createServiceClient = vi
432
486
. fn ( )
433
- . mockImplementation ( ( ) =>
434
- createPromiseClient ( MotionService , mockTransport )
435
- ) ;
487
+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
436
488
437
489
motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
438
490
@@ -485,9 +537,7 @@ describe('listPlanStatuses', () => {
485
537
486
538
RobotClient . prototype . createServiceClient = vi
487
539
. fn ( )
488
- . mockImplementation ( ( ) =>
489
- createPromiseClient ( MotionService , mockTransport )
490
- ) ;
540
+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
491
541
492
542
motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
493
543
@@ -513,9 +563,7 @@ describe('listPlanStatuses', () => {
513
563
514
564
RobotClient . prototype . createServiceClient = vi
515
565
. fn ( )
516
- . mockImplementation ( ( ) =>
517
- createPromiseClient ( MotionService , mockTransport )
518
- ) ;
566
+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
519
567
520
568
motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
521
569
0 commit comments