@@ -2543,3 +2543,132 @@ test('activeAppDeployments returns error for invalid date filter', async () => {
25432543 expect ( result . rawBody . errors ) . toBeDefined ( ) ;
25442544 expect ( result . rawBody . errors ?. [ 0 ] ?. message ) . toMatch ( / D a t e T i m e | I n v a l i d | d a t e / i) ;
25452545} ) ;
2546+
2547+ test ( 'activeAppDeployments filters by name combined with lastUsedBefore' , async ( ) => {
2548+ const { createOrg, ownerToken } = await initSeed ( ) . createOwner ( ) ;
2549+ const { createProject, setFeatureFlag, organization } = await createOrg ( ) ;
2550+ await setFeatureFlag ( 'appDeployments' , true ) ;
2551+ const { createTargetAccessToken, project, target, waitForOperationsCollected } =
2552+ await createProject ( ) ;
2553+ const token = await createTargetAccessToken ( { } ) ;
2554+
2555+ const sdl = /* GraphQL */ `
2556+ type Query {
2557+ hello: String
2558+ }
2559+ ` ;
2560+
2561+ await token . publishSchema ( { sdl } ) ;
2562+
2563+ // Create frontend-app
2564+ await execute ( {
2565+ document : CreateAppDeployment ,
2566+ variables : { input : { appName : 'frontend-app' , appVersion : '1.0.0' } } ,
2567+ authToken : token . secret ,
2568+ } ) . then ( res => res . expectNoGraphQLErrors ( ) ) ;
2569+
2570+ await execute ( {
2571+ document : AddDocumentsToAppDeployment ,
2572+ variables : {
2573+ input : {
2574+ appName : 'frontend-app' ,
2575+ appVersion : '1.0.0' ,
2576+ documents : [ { hash : 'hash1' , body : 'query { hello }' } ] ,
2577+ } ,
2578+ } ,
2579+ authToken : token . secret ,
2580+ } ) . then ( res => res . expectNoGraphQLErrors ( ) ) ;
2581+
2582+ await execute ( {
2583+ document : ActivateAppDeployment ,
2584+ variables : { input : { appName : 'frontend-app' , appVersion : '1.0.0' } } ,
2585+ authToken : token . secret ,
2586+ } ) . then ( res => res . expectNoGraphQLErrors ( ) ) ;
2587+
2588+ // Create backend-app
2589+ await execute ( {
2590+ document : CreateAppDeployment ,
2591+ variables : { input : { appName : 'backend-app' , appVersion : '1.0.0' } } ,
2592+ authToken : token . secret ,
2593+ } ) . then ( res => res . expectNoGraphQLErrors ( ) ) ;
2594+
2595+ await execute ( {
2596+ document : AddDocumentsToAppDeployment ,
2597+ variables : {
2598+ input : {
2599+ appName : 'backend-app' ,
2600+ appVersion : '1.0.0' ,
2601+ documents : [ { hash : 'hash2' , body : 'query { hello }' } ] ,
2602+ } ,
2603+ } ,
2604+ authToken : token . secret ,
2605+ } ) . then ( res => res . expectNoGraphQLErrors ( ) ) ;
2606+
2607+ await execute ( {
2608+ document : ActivateAppDeployment ,
2609+ variables : { input : { appName : 'backend-app' , appVersion : '1.0.0' } } ,
2610+ authToken : token . secret ,
2611+ } ) . then ( res => res . expectNoGraphQLErrors ( ) ) ;
2612+
2613+ // Report usage for frontend-app only
2614+ const usageAddress = await getServiceHost ( 'usage' , 8081 ) ;
2615+
2616+ const client = createHive ( {
2617+ enabled : true ,
2618+ token : token . secret ,
2619+ usage : true ,
2620+ debug : false ,
2621+ agent : {
2622+ logger : createLogger ( 'debug' ) ,
2623+ maxSize : 1 ,
2624+ } ,
2625+ selfHosting : {
2626+ usageEndpoint : 'http://' + usageAddress ,
2627+ graphqlEndpoint : 'http://noop/' ,
2628+ applicationUrl : 'http://noop/' ,
2629+ } ,
2630+ } ) ;
2631+
2632+ const request = new Request ( 'http://localhost:4000/graphql' , {
2633+ method : 'POST' ,
2634+ headers : {
2635+ 'x-graphql-client-name' : 'frontend-app' ,
2636+ 'x-graphql-client-version' : '1.0.0' ,
2637+ } ,
2638+ } ) ;
2639+
2640+ await client . collectUsage ( ) (
2641+ {
2642+ document : parse ( `query { hello }` ) ,
2643+ schema : buildASTSchema ( parse ( sdl ) ) ,
2644+ contextValue : { request } ,
2645+ } ,
2646+ { } ,
2647+ 'frontend-app~1.0.0~hash1' ,
2648+ ) ;
2649+
2650+ await waitForOperationsCollected ( 1 ) ;
2651+
2652+ const tomorrow = new Date ( ) ;
2653+ tomorrow . setDate ( tomorrow . getDate ( ) + 1 ) ;
2654+
2655+ // Filter by name "frontend" AND lastUsedBefore tomorrow should get frontend-app
2656+ const result = await execute ( {
2657+ document : GetActiveAppDeployments ,
2658+ variables : {
2659+ targetSelector : {
2660+ organizationSlug : organization . slug ,
2661+ projectSlug : project . slug ,
2662+ targetSlug : target . slug ,
2663+ } ,
2664+ filter : {
2665+ name : 'frontend' ,
2666+ lastUsedBefore : tomorrow . toISOString ( ) ,
2667+ } ,
2668+ } ,
2669+ authToken : ownerToken ,
2670+ } ) . then ( res => res . expectNoGraphQLErrors ( ) ) ;
2671+
2672+ expect ( result . target ?. activeAppDeployments . edges ) . toHaveLength ( 1 ) ;
2673+ expect ( result . target ?. activeAppDeployments . edges [ 0 ] ?. node . name ) . toBe ( 'frontend-app' ) ;
2674+ } ) ;
0 commit comments