1- import {
2- Notification ,
3- fetchNotificationsInBackground ,
4- filterNotifications ,
5- showNotificationsIfNeeded ,
6- } from './notifications-system.js'
1+ import { Notification , filterNotifications , showNotificationsIfNeeded } from './notifications-system.js'
72import { renderError , renderInfo , renderWarning } from './ui.js'
83import { sniffForJson } from './path.js'
9- import { exec } from './system.js'
10- import { cacheRetrieve } from '../../private/node/conf-store.js'
4+ import { cacheRetrieve , cacheRetrieveOrRepopulate } from '../../private/node/conf-store.js'
115import { afterEach , describe , expect , test , vi } from 'vitest'
126
137vi . mock ( './ui.js' )
148vi . mock ( '../../private/node/conf-store.js' )
159vi . mock ( './path.js' )
16- vi . mock ( './system.js' )
1710
1811const betweenVersins1and2 : Notification = {
1912 id : 'betweenVersins1and2' ,
@@ -340,7 +333,7 @@ describe('showNotificationsIfNeeded', () => {
340333 test ( 'an info notification triggers a renderInfo call' , async ( ) => {
341334 // Given
342335 const notifications = [ infoNotification ]
343- vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
336+ vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
344337
345338 // When
346339 await showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'false' } )
@@ -352,7 +345,7 @@ describe('showNotificationsIfNeeded', () => {
352345 test ( 'a warning notification triggers a renderWarning call' , async ( ) => {
353346 // Given
354347 const notifications = [ warningNotification ]
355- vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
348+ vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
356349
357350 // When
358351 await showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'false' } )
@@ -364,7 +357,7 @@ describe('showNotificationsIfNeeded', () => {
364357 test ( 'an error notification triggers a renderError call and throws an error' , async ( ) => {
365358 // Given
366359 const notifications = [ errorNotification ]
367- vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
360+ vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
368361
369362 // When
370363 await expect ( showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'false' } ) ) . rejects . toThrowError ( )
@@ -376,7 +369,7 @@ describe('showNotificationsIfNeeded', () => {
376369 test ( 'notifications are skipped on CI' , async ( ) => {
377370 // Given
378371 const notifications = [ infoNotification ]
379- vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
372+ vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
380373
381374 // When
382375 await showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'false' , CI : 'true' } )
@@ -388,7 +381,7 @@ describe('showNotificationsIfNeeded', () => {
388381 test ( 'notifications are skipped on tests' , async ( ) => {
389382 // Given
390383 const notifications = [ infoNotification ]
391- vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
384+ vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
392385
393386 // When
394387 await showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'true' } )
@@ -400,7 +393,7 @@ describe('showNotificationsIfNeeded', () => {
400393 test ( 'notifications are skipped when using --json flag' , async ( ) => {
401394 // Given
402395 const notifications = [ infoNotification ]
403- vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
396+ vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
404397 vi . mocked ( sniffForJson ) . mockReturnValue ( true )
405398
406399 // When
@@ -413,7 +406,7 @@ describe('showNotificationsIfNeeded', () => {
413406 test ( 'notifications are skipped when using SHOPIFY_FLAG_JSON' , async ( ) => {
414407 // Given
415408 const notifications = [ infoNotification ]
416- vi . mocked ( cacheRetrieve ) . mockReturnValue ( { value : JSON . stringify ( { notifications} ) , timestamp : 0 } )
409+ vi . mocked ( cacheRetrieveOrRepopulate ) . mockResolvedValue ( JSON . stringify ( { notifications} ) )
417410
418411 // When
419412 await showNotificationsIfNeeded ( undefined , { SHOPIFY_UNIT_TEST : 'false' , SHOPIFY_FLAG_JSON : 'true' } )
@@ -422,33 +415,3 @@ describe('showNotificationsIfNeeded', () => {
422415 expect ( renderInfo ) . not . toHaveBeenCalled ( )
423416 } )
424417} )
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