@@ -7,7 +7,7 @@ import * as sinon from "sinon";
77import * as tmp from "tmp" ;
88
99import { AppDistributionClient } from "./client" ;
10- import { BatchRemoveTestersResponse , Group , TestDevice } from "./types" ;
10+ import { BatchRemoveTestersResponse , Group , TestCase , TestDevice } from "./types" ;
1111import { appDistributionOrigin } from "../api" ;
1212import { Distribution } from "./distribution" ;
1313import { FirebaseError } from "../error" ;
@@ -501,4 +501,91 @@ describe("distribution", () => {
501501 expect ( nock . isDone ( ) ) . to . be . true ;
502502 } ) ;
503503 } ) ;
504+
505+ describe ( "listTestCases" , ( ) => {
506+ it ( "should throw error if request fails" , async ( ) => {
507+ nock ( appDistributionOrigin ( ) )
508+ . get ( `/v1alpha/${ appName } /testCases` )
509+ . reply ( 400 , { error : { status : "FAILED_PRECONDITION" } } ) ;
510+ await expect ( appDistributionClient . listTestCases ( appName ) ) . to . be . rejectedWith (
511+ FirebaseError ,
512+ "Client failed to list test cases" ,
513+ ) ;
514+ expect ( nock . isDone ( ) ) . to . be . true ;
515+ } ) ;
516+
517+ it ( "should resolve with array of test cases when request succeeds" , async ( ) => {
518+ const testCases : TestCase [ ] = [
519+ {
520+ name : `$appName/testCases/tc_1` ,
521+ displayName : "Test Case 1" ,
522+ aiInstructions : {
523+ steps : [
524+ {
525+ goal : "Win at all costs" ,
526+ } ,
527+ ] ,
528+ } ,
529+ } ,
530+ {
531+ name : `$appName/testCases/tc_2` ,
532+ displayName : "Test Case 2" ,
533+ aiInstructions : { steps : [ ] } ,
534+ } ,
535+ ] ;
536+
537+ nock ( appDistributionOrigin ( ) ) . get ( `/v1alpha/${ appName } /testCases` ) . reply ( 200 , {
538+ testCases : testCases ,
539+ } ) ;
540+ await expect ( appDistributionClient . listTestCases ( appName ) ) . to . eventually . deep . eq ( testCases ) ;
541+ expect ( nock . isDone ( ) ) . to . be . true ;
542+ } ) ;
543+ } ) ;
544+
545+ describe ( "createTestCase" , ( ) => {
546+ const mockTestCase = { displayName : "Case" , aiInstructions : { steps : [ ] } } ;
547+
548+ it ( "should throw error if request fails" , async ( ) => {
549+ nock ( appDistributionOrigin ( ) )
550+ . post ( `/v1alpha/${ appName } /testCases` )
551+ . reply ( 400 , { error : { status : "FAILED_PRECONDITION" } } ) ;
552+ await expect ( appDistributionClient . createTestCase ( appName , mockTestCase ) ) . to . be . rejectedWith (
553+ FirebaseError ,
554+ "Failed to create test case" ,
555+ ) ;
556+ expect ( nock . isDone ( ) ) . to . be . true ;
557+ } ) ;
558+
559+ it ( "should resolve with TestCase when request succeeds" , async ( ) => {
560+ nock ( appDistributionOrigin ( ) ) . post ( `/v1alpha/${ appName } /testCases` ) . reply ( 200 , mockTestCase ) ;
561+ await expect (
562+ appDistributionClient . createTestCase ( appName , mockTestCase ) ,
563+ ) . to . be . eventually . deep . eq ( mockTestCase ) ;
564+ expect ( nock . isDone ( ) ) . to . be . true ;
565+ } ) ;
566+ } ) ;
567+
568+ describe ( "batchUpsertTestCases" , ( ) => {
569+ const mockTestCase = { displayName : "Case" , aiInstructions : { steps : [ ] } } ;
570+
571+ it ( "should throw error if request fails" , async ( ) => {
572+ nock ( appDistributionOrigin ( ) )
573+ . post ( `/v1alpha/${ appName } /testCases:batchUpdate` )
574+ . reply ( 400 , { error : { status : "FAILED_PRECONDITION" } } ) ;
575+ await expect (
576+ appDistributionClient . batchUpsertTestCases ( appName , [ mockTestCase ] ) ,
577+ ) . to . be . rejectedWith ( FirebaseError , "Failed to upsert test cases" ) ;
578+ expect ( nock . isDone ( ) ) . to . be . true ;
579+ } ) ;
580+
581+ it ( "should resolve with TestCase when request succeeds" , async ( ) => {
582+ nock ( appDistributionOrigin ( ) )
583+ . post ( `/v1alpha/${ appName } /testCases:batchUpdate` )
584+ . reply ( 200 , { testCases : [ mockTestCase ] } ) ;
585+ await expect (
586+ appDistributionClient . batchUpsertTestCases ( appName , [ mockTestCase ] ) ,
587+ ) . to . be . eventually . deep . eq ( [ mockTestCase ] ) ;
588+ expect ( nock . isDone ( ) ) . to . be . true ;
589+ } ) ;
590+ } ) ;
504591} ) ;
0 commit comments