@@ -9,7 +9,7 @@ vi.mock('../../lib/auth.js', async (importOriginal) => {
99 const actual = await importOriginal < typeof import ( '../../lib/auth.js' ) > ( )
1010 return {
1111 ...actual ,
12- getAuthMetadata : vi . fn ( ) ,
12+ getApiTokenSnapshot : vi . fn ( ) ,
1313 probeApiToken : vi . fn ( ) ,
1414 }
1515} )
@@ -88,15 +88,15 @@ import { attachLoginCommand } from '@doist/cli-core/auth'
8888import { CommsRequestError, type User } from '@doist/comms-sdk'
8989import { createWrappedCommsClient } from '../../lib/api.js'
9090import { type CommsAccount , type CommsTokenStore } from '../../lib/auth-provider.js'
91- import { getAuthMetadata , TOKEN_ENV_VAR } from '../../lib/auth.js'
91+ import { getApiTokenSnapshot , TOKEN_ENV_VAR } from '../../lib/auth.js'
9292import { getConfig , updateConfig } from '../../lib/config.js'
9393import { resetGlobalArgs } from '../../lib/global-args.js'
9494import { registerAuthCommand } from './index.js'
9595import { attachCommsStatusCommand } from './status.js'
9696
9797const mockCreateInterface = vi . mocked ( createInterface )
9898
99- const mockGetAuthMetadata = vi . mocked ( getAuthMetadata )
99+ const mockGetApiTokenSnapshot = vi . mocked ( getApiTokenSnapshot )
100100const mockCreateWrappedCommsClient = vi . mocked ( createWrappedCommsClient )
101101const mockAttachLoginCommand = vi . mocked ( attachLoginCommand )
102102const mockGetConfig = vi . mocked ( getConfig )
@@ -392,22 +392,27 @@ describe('auth command', () => {
392392 vi . stubEnv ( TOKEN_ENV_VAR , '' )
393393 storeMocks . list . mockResolvedValue ( STORED_RECORDS )
394394 storeMocks . active . mockResolvedValue ( STORED_SNAPSHOT )
395+ mockGetApiTokenSnapshot . mockResolvedValue ( {
396+ token : 'tk_refreshed_1234567890' ,
397+ account : {
398+ ...STORED_ACCOUNT ,
399+ authResource : 'https://comms.staging.todoist.com' ,
400+ } ,
401+ } )
395402 mockCreateWrappedCommsClient . mockReturnValue ( {
396403 users : { getSessionUser : vi . fn ( ) . mockResolvedValue ( TEST_USER ) } ,
397404 // biome-ignore lint/suspicious/noExplicitAny: only the methods used in this test matter
398405 } as any )
399- mockGetAuthMetadata . mockResolvedValue ( {
400- authMode : 'read-write' ,
401- authScope : 'user:read' ,
402- source : 'config' ,
403- } )
404406 process . argv = [ 'node' , 'tdc' , '--user' , '1' , 'auth' , 'status' ]
405407 resetGlobalArgs ( )
406408
407409 await createProgram ( ) . parseAsync ( [ 'node' , 'tdc' , 'auth' , 'status' ] )
408410
409411 expect ( storeMocks . active ) . toHaveBeenCalledWith ( '1' )
410- expect ( mockCreateWrappedCommsClient ) . toHaveBeenCalledWith ( 'tk_stored_1234567890' )
412+ expect ( mockGetApiTokenSnapshot ) . toHaveBeenCalledWith ( '1' )
413+ expect ( mockCreateWrappedCommsClient ) . toHaveBeenCalledWith ( 'tk_refreshed_1234567890' , {
414+ baseUrl : 'https://comms.staging.todoist.com' ,
415+ } )
411416 expect ( consoleSpy ) . toHaveBeenCalledWith ( '✓ Authenticated' )
412417 } )
413418
@@ -449,6 +454,7 @@ describe('auth command', () => {
449454 label : TEST_USER . fullName ,
450455 authMode : 'read-write' ,
451456 authScope : COMMS_SCOPE ,
457+ authResource : 'https://comms.staging.todoist.com' ,
452458 }
453459
454460 function programWithSnapshot ( ) : Command {
@@ -482,21 +488,22 @@ describe('auth command', () => {
482488 }
483489
484490 beforeEach ( ( ) => {
491+ mockGetApiTokenSnapshot . mockResolvedValue ( {
492+ token : 'snapshot_token' ,
493+ account : SNAPSHOT_ACCOUNT ,
494+ } )
485495 mockCreateWrappedCommsClient . mockReturnValue ( {
486496 users : { getSessionUser : vi . fn ( ) . mockResolvedValue ( TEST_USER ) } ,
487497 // biome-ignore lint/suspicious/noExplicitAny: only the methods used in this test matter
488498 } as any )
489- mockGetAuthMetadata . mockResolvedValue ( {
490- authMode : 'read-write' ,
491- authScope : COMMS_SCOPE ,
492- source : 'config' ,
493- } )
494499 } )
495500
496501 it ( 'renders text status from the snapshot' , async ( ) => {
497502 await programWithSnapshot ( ) . parseAsync ( [ 'node' , 'tdc' , 'auth' , 'status' ] )
498503
499- expect ( mockCreateWrappedCommsClient ) . toHaveBeenCalledWith ( 'snapshot_token' )
504+ expect ( mockCreateWrappedCommsClient ) . toHaveBeenCalledWith ( 'snapshot_token' , {
505+ baseUrl : 'https://comms.staging.todoist.com' ,
506+ } )
500507 expect ( consoleSpy ) . toHaveBeenCalledWith ( '✓ Authenticated' )
501508 expect ( consoleSpy ) . toHaveBeenCalledWith ( ' Email: test@example.com' )
502509 expect ( consoleSpy ) . toHaveBeenCalledWith ( ' Name: Test User' )
0 commit comments