@@ -2,19 +2,26 @@ import { Logger } from '@nestjs/common';
22import { readdir , readFile , writeFile } from 'fs/promises' ;
33import { join } from 'path' ;
44
5+
6+
57import { ensureDir , ensureDirSync } from 'fs-extra' ;
68import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
79import { ZodError } from 'zod' ;
810
11+
12+
913import type { ApiKey , ApiKeyWithSecret } from '@app/graphql/generated/api/types' ;
14+ import { environment } from '@app/environment' ;
1015import { ApiKeySchema , ApiKeyWithSecretSchema } from '@app/graphql/generated/api/operations' ;
1116import { Resource , Role } from '@app/graphql/generated/api/types' ;
1217import { getters , store } from '@app/store' ;
1318import { updateUserConfig } from '@app/store/modules/config' ;
1419import { FileLoadStatus } from '@app/store/types' ;
1520
21+
22+
1623import { ApiKeyService } from './api-key.service' ;
17- import { environment } from '@app/environment' ;
24+
1825
1926// Mock the store and its modules
2027vi . mock ( '@app/store' , ( ) => ( {
@@ -30,6 +37,7 @@ vi.mock('@app/store', () => ({
3037
3138vi . mock ( '@app/store/modules/config' , ( ) => ( {
3239 updateUserConfig : vi . fn ( ) ,
40+ setLocalApiKey : vi . fn ( ) ,
3341} ) ) ;
3442
3543// Mock fs/promises
@@ -242,12 +250,12 @@ describe('ApiKeyService', () => {
242250 expect ( store . dispatch ) . not . toHaveBeenCalled ( ) ;
243251 } ) ;
244252
245- it ( 'should not create key if Connect key already exists' , async ( ) => {
253+ it ( 'should dispatch to update config if Connect key already exists' , async ( ) => {
246254 vi . spyOn ( apiKeyService , 'findByField' ) . mockReturnValue ( mockApiKeyWithSecret ) ;
247255
248256 await apiKeyService [ 'createLocalApiKeyForConnectIfNecessary' ] ( ) ;
249257
250- expect ( store . dispatch ) . not . toHaveBeenCalled ( ) ;
258+ expect ( store . dispatch ) . toHaveBeenCalled ( ) ;
251259 } ) ;
252260
253261 it ( 'should create new Connect key and update config' , async ( ) => {
@@ -607,4 +615,4 @@ describe('ApiKeyService', () => {
607615 ) ;
608616 } ) ;
609617 } ) ;
610- } ) ;
618+ } ) ;
0 commit comments