Skip to content

Commit 25c1c1a

Browse files
committed
fix: tests
1 parent 58329bc commit 25c1c1a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

api/src/unraid-api/auth/api-key.service.spec.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@ import { Logger } from '@nestjs/common';
22
import { readdir, readFile, writeFile } from 'fs/promises';
33
import { join } from 'path';
44

5+
6+
57
import { ensureDir, ensureDirSync } from 'fs-extra';
68
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
79
import { ZodError } from 'zod';
810

11+
12+
913
import type { ApiKey, ApiKeyWithSecret } from '@app/graphql/generated/api/types';
14+
import { environment } from '@app/environment';
1015
import { ApiKeySchema, ApiKeyWithSecretSchema } from '@app/graphql/generated/api/operations';
1116
import { Resource, Role } from '@app/graphql/generated/api/types';
1217
import { getters, store } from '@app/store';
1318
import { updateUserConfig } from '@app/store/modules/config';
1419
import { FileLoadStatus } from '@app/store/types';
1520

21+
22+
1623
import { ApiKeyService } from './api-key.service';
17-
import { environment } from '@app/environment';
24+
1825

1926
// Mock the store and its modules
2027
vi.mock('@app/store', () => ({
@@ -30,6 +37,7 @@ vi.mock('@app/store', () => ({
3037

3138
vi.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

Comments
 (0)