@@ -2,8 +2,14 @@ import { fail } from 'assert';
22import { expect } from 'chai' ;
33import * as sinon from 'sinon' ;
44import { Credentials } from '../../../../authentication' ;
5- import { cancelRemoteQuery , getRepositoriesMetadata } from '../../../../remote-queries/gh-api/gh-actions-api-client' ;
5+ import {
6+ cancelRemoteQuery ,
7+ cancelVariantAnalysis ,
8+ getRepositoriesMetadata
9+ } from '../../../../remote-queries/gh-api/gh-actions-api-client' ;
610import { RemoteQuery } from '../../../../remote-queries/remote-query' ;
11+ import { createMockVariantAnalysis } from '../../../factories/remote-queries/shared/variant-analysis' ;
12+ import { VariantAnalysis } from '../../../../remote-queries/shared/variant-analysis' ;
713
814describe ( 'gh-actions-api-client mock responses' , ( ) => {
915 let sandbox : sinon . SinonSandbox ;
@@ -50,6 +56,29 @@ describe('gh-actions-api-client mock responses', () => {
5056 } as unknown as RemoteQuery ;
5157 }
5258 } ) ;
59+
60+ describe ( 'cancelVariantAnalysis' , ( ) => {
61+ let variantAnalysis : VariantAnalysis ;
62+ before ( ( ) => {
63+ variantAnalysis = createMockVariantAnalysis ( { } ) ;
64+ } ) ;
65+
66+ it ( 'should cancel a variant analysis' , async ( ) => {
67+ mockResponse = sinon . stub ( ) . resolves ( { status : 202 } ) ;
68+ await cancelVariantAnalysis ( mockCredentials , variantAnalysis ) ;
69+
70+ expect ( mockResponse . calledOnce ) . to . be . true ;
71+ expect ( mockResponse . firstCall . args [ 0 ] ) . to . equal ( `POST /repos/${ variantAnalysis . controllerRepo . fullName } /actions/runs/${ variantAnalysis . actionsWorkflowRunId } /cancel` ) ;
72+ } ) ;
73+
74+ it ( 'should fail to cancel a variant analysis' , async ( ) => {
75+ mockResponse = sinon . stub ( ) . resolves ( { status : 409 , data : { message : 'Uh oh!' } } ) ;
76+
77+ await expect ( cancelVariantAnalysis ( mockCredentials , variantAnalysis ) ) . to . be . rejectedWith ( / E r r o r c a n c e l l i n g v a r i a n t a n a l y s i s : 4 0 9 U h o h ! / ) ;
78+ expect ( mockResponse . calledOnce ) . to . be . true ;
79+ expect ( mockResponse . firstCall . args [ 0 ] ) . to . equal ( `POST /repos/${ variantAnalysis . controllerRepo . fullName } /actions/runs/${ variantAnalysis . actionsWorkflowRunId } /cancel` ) ;
80+ } ) ;
81+ } ) ;
5382} ) ;
5483
5584describe ( 'gh-actions-api-client real responses' , function ( ) {
0 commit comments