1- import { Notification , filterNotifications , showNotificationsIfNeeded } from './notifications-system.js'
1+ import {
2+ Notification ,
3+ fetchNotificationsInBackground ,
4+ filterNotifications ,
5+ showNotificationsIfNeeded ,
6+ } from './notifications-system.js'
27import { renderError , renderInfo , renderWarning } from './ui.js'
38import { sniffForJson } from './path.js'
4- import { cacheRetrieve , cacheRetrieveOrRepopulate } from '../../private/node/conf-store.js'
9+ import { exec } from './system.js'
10+ import { cacheRetrieve } from '../../private/node/conf-store.js'
511import { afterEach , describe , expect , test , vi } from 'vitest'
612
713vi . mock ( './ui.js' )
814vi . mock ( '../../private/node/conf-store.js' )
915vi . mock ( './path.js' )
16+ vi . mock ( './system.js' )
1017
1118const betweenVersins1and2 : Notification = {
1219 id : 'betweenVersins1and2' ,
@@ -333,7 +340,7 @@ describe('showNotificationsIfNeeded', () => {
333340 test ( 'an info notification triggers a renderInfo call' , async ( ) => {
334341 // Given
335342 const notifications = [ infoNotification ]
336- vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
343+ vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
337344
338345 // When
339346 await showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'false' } )
@@ -345,7 +352,7 @@ describe('showNotificationsIfNeeded', () => {
345352 test ( 'a warning notification triggers a renderWarning call' , async ( ) => {
346353 // Given
347354 const notifications = [ warningNotification ]
348- vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
355+ vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
349356
350357 // When
351358 await showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'false' } )
@@ -357,7 +364,7 @@ describe('showNotificationsIfNeeded', () => {
357364 test ( 'an error notification triggers a renderError call and throws an error' , async ( ) => {
358365 // Given
359366 const notifications = [ errorNotification ]
360- vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
367+ vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
361368
362369 // When
363370 await expect ( showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'false' } ) ) . rejects . toThrowError ( )
@@ -369,7 +376,7 @@ describe('showNotificationsIfNeeded', () => {
369376 test ( 'notifications are skipped on CI' , async ( ) => {
370377 // Given
371378 const notifications = [ infoNotification ]
372- vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
379+ vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
373380
374381 // When
375382 await showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'false' , CI : 'true' } )
@@ -381,7 +388,7 @@ describe('showNotificationsIfNeeded', () => {
381388 test ( 'notifications are skipped on tests' , async ( ) => {
382389 // Given
383390 const notifications = [ infoNotification ]
384- vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
391+ vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
385392
386393 // When
387394 await showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'true' } )
@@ -393,7 +400,7 @@ describe('showNotificationsIfNeeded', () => {
393400 test ( 'notifications are skipped when using --json flag' , async ( ) => {
394401 // Given
395402 const notifications = [ infoNotification ]
396- vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
403+ vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
397404 vi . mocked ( sniffForJson ) . mockReturnValue ( true )
398405
399406 // When
@@ -406,7 +413,7 @@ describe('showNotificationsIfNeeded', () => {
406413 test ( 'notifications are skipped when using SHOPIFY_FLAG_JSON' , async ( ) => {
407414 // Given
408415 const notifications = [ infoNotification ]
409- vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
416+ vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
410417
411418 // When
412419 await showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'false' , SHOPIFY_FLAG_JSON : 'true' } )
@@ -415,3 +422,33 @@ describe('showNotificationsIfNeeded', () => {
415422 expect ( renderInfo ) . not . toHaveBeenCalled ( )
416423 } )
417424} )
425+
426+ describe ( 'fetchNotificationsInBackground' , ( ) => {
427+ test ( 'calls the expected Shopify binary for global installation' , async ( ) => {
428+ // Given / When
429+ fetchNotificationsInBackground ( 'theme:init' , [ 'shopify' , 'theme' , 'init' ] , { SHOPIFY_UNIT_TEST : 'false' } )
430+
431+ // Then
432+ expect ( exec ) . toHaveBeenCalledWith ( 'shopify' , [ 'notifications' , 'list' ] , expect . anything ( ) )
433+ } )
434+
435+ test ( 'calls the expected Shopify binary for local installation' , async ( ) => {
436+ // Given / When
437+ fetchNotificationsInBackground ( 'theme:init' , [ 'npm' , 'run' , 'shopify' , 'theme' , 'init' ] , {
438+ SHOPIFY_UNIT_TEST : 'false' ,
439+ } )
440+
441+ // Then
442+ expect ( exec ) . toHaveBeenCalledWith ( 'npm' , [ 'run' , 'shopify' , 'notifications' , 'list' ] , expect . anything ( ) )
443+ } )
444+
445+ test ( 'calls the expected Shopify binary for dev environment' , async ( ) => {
446+ // Given / When
447+ fetchNotificationsInBackground ( 'theme:init' , [ 'node' , 'packages/cli/bin/dev.js' , 'theme' , 'init' ] , {
448+ SHOPIFY_UNIT_TEST : 'false' ,
449+ } )
450+
451+ // Then
452+ expect ( exec ) . toHaveBeenCalledWith ( 'node' , [ 'packages/cli/bin/dev.js' , 'notifications' , 'list' ] , expect . anything ( ) )
453+ } )
454+ } )
0 commit comments