@@ -8,26 +8,32 @@ vi.mock('../../gen/service/motion/v1/motion_pb_service');
88vi . mock ( '../../robot' ) ;
99
1010import { Struct , Timestamp } from '@bufbuild/protobuf' ;
11- import {
12- createPromiseClient ,
13- createRouterTransport ,
14- } from '@connectrpc/connect' ;
11+ import { createClient , createRouterTransport } from '@connectrpc/connect' ;
1512import { MotionService } from '../../gen/service/motion/v1/motion_connect' ;
1613import {
1714 GetPlanRequest ,
1815 ListPlanStatusesRequest ,
1916 MoveOnGlobeRequest ,
2017 MoveOnGlobeResponse ,
18+ MoveRequest ,
2119 StopPlanRequest ,
2220} 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' ;
2428import { MotionClient } from './client' ;
2529import {
30+ Constraints ,
2631 GetPlanResponse ,
2732 ListPlanStatusesResponse ,
2833 MotionConfiguration ,
2934 ObstacleDetector ,
3035 PlanState ,
36+ PseudolinearConstraint ,
3137} from './types' ;
3238
3339const motionClientName = 'test-motion' ;
@@ -76,9 +82,7 @@ describe('moveOnGlobe', () => {
7682
7783 RobotClient . prototype . createServiceClient = vi
7884 . fn ( )
79- . mockImplementation ( ( ) =>
80- createPromiseClient ( MotionService , mockTransport )
81- ) ;
85+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
8286
8387 motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
8488
@@ -226,9 +230,7 @@ describe('moveOnGlobe', () => {
226230
227231 RobotClient . prototype . createServiceClient = vi
228232 . fn ( )
229- . mockImplementation ( ( ) =>
230- createPromiseClient ( MotionService , mockTransport )
231- ) ;
233+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
232234
233235 motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
234236
@@ -263,6 +265,64 @@ describe('moveOnGlobe', () => {
263265 } ) ;
264266} ) ;
265267
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+
266326describe ( 'stopPlan' , ( ) => {
267327 it ( 'return null' , async ( ) => {
268328 const expectedComponentName = new ResourceName ( {
@@ -285,9 +345,7 @@ describe('stopPlan', () => {
285345
286346 RobotClient . prototype . createServiceClient = vi
287347 . fn ( )
288- . mockImplementation ( ( ) =>
289- createPromiseClient ( MotionService , mockTransport )
290- ) ;
348+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
291349
292350 motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
293351
@@ -318,9 +376,7 @@ describe('stopPlan', () => {
318376
319377 RobotClient . prototype . createServiceClient = vi
320378 . fn ( )
321- . mockImplementation ( ( ) =>
322- createPromiseClient ( MotionService , mockTransport )
323- ) ;
379+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
324380
325381 motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
326382
@@ -393,9 +449,7 @@ describe('getPlan', () => {
393449
394450 RobotClient . prototype . createServiceClient = vi
395451 . fn ( )
396- . mockImplementation ( ( ) =>
397- createPromiseClient ( MotionService , mockTransport )
398- ) ;
452+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
399453
400454 motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
401455
@@ -430,9 +484,7 @@ describe('getPlan', () => {
430484
431485 RobotClient . prototype . createServiceClient = vi
432486 . fn ( )
433- . mockImplementation ( ( ) =>
434- createPromiseClient ( MotionService , mockTransport )
435- ) ;
487+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
436488
437489 motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
438490
@@ -485,9 +537,7 @@ describe('listPlanStatuses', () => {
485537
486538 RobotClient . prototype . createServiceClient = vi
487539 . fn ( )
488- . mockImplementation ( ( ) =>
489- createPromiseClient ( MotionService , mockTransport )
490- ) ;
540+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
491541
492542 motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
493543
@@ -513,9 +563,7 @@ describe('listPlanStatuses', () => {
513563
514564 RobotClient . prototype . createServiceClient = vi
515565 . fn ( )
516- . mockImplementation ( ( ) =>
517- createPromiseClient ( MotionService , mockTransport )
518- ) ;
566+ . mockImplementation ( ( ) => createClient ( MotionService , mockTransport ) ) ;
519567
520568 motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
521569
0 commit comments