mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* add: hide apikeys tab on start * make use of store method * added hiding of apikeys tab for new org creation * missing err check * removed unused files * implemennted fake to make tests run * move check for globalHideApikeys from org to admin * refactor to remove the fake * removed unused method calls for interface * Update pkg/services/serviceaccounts/manager/service.go Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com> * Update pkg/services/serviceaccounts/manager/service.go Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com> * remove the checkglobal method * removed duplicate global set const * add count of apikeys for performance * remove apikeys adding in UI * added back deleted file * added comment on component * changed wording and copy for hiding and migrating service accounts * refactor: remove migrationstatus in front/backend This removes the migrationstatus state from the UI in favor of only looking at the number of API keys to determine what to show to the user. This simplifies the logic and makes less calls to the backend with each page load. This was called both on the API keys page and the Service accounts page. - removes the state of migrationstatus from the UI - removes the backend call - removes the backend endpoint for migrationstatus * Update pkg/services/apikey/apikeyimpl/xorm_store.go Co-authored-by: Karl Persson <kalle.persson@grafana.com> * changes the contet to also be primary * change id of version for footer component --------- Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com> Co-authored-by: Karl Persson <kalle.persson@grafana.com>
143 lines
4.4 KiB
TypeScript
143 lines
4.4 KiB
TypeScript
import { ApiKeysState } from 'app/types';
|
|
|
|
import { getMultipleMockKeys } from '../__mocks__/apiKeysMock';
|
|
|
|
import { getApiKeys, getApiKeysCount, getIncludeExpired, getIncludeExpiredDisabled } from './selectors';
|
|
|
|
describe('API Keys selectors', () => {
|
|
const mockKeys = getMultipleMockKeys(5);
|
|
const mockKeysIncludingExpired = getMultipleMockKeys(8);
|
|
|
|
describe('getApiKeysCount', () => {
|
|
it('returns the correct count when includeExpired is false', () => {
|
|
const mockState: ApiKeysState = {
|
|
keys: mockKeys,
|
|
keysIncludingExpired: mockKeysIncludingExpired,
|
|
searchQuery: '',
|
|
hasFetched: true,
|
|
includeExpired: false,
|
|
};
|
|
const keyCount = getApiKeysCount(mockState);
|
|
expect(keyCount).toBe(5);
|
|
});
|
|
|
|
it('returns the correct count when includeExpired is true', () => {
|
|
const mockState: ApiKeysState = {
|
|
keys: mockKeys,
|
|
keysIncludingExpired: mockKeysIncludingExpired,
|
|
searchQuery: '',
|
|
hasFetched: true,
|
|
includeExpired: true,
|
|
};
|
|
const keyCount = getApiKeysCount(mockState);
|
|
expect(keyCount).toBe(8);
|
|
});
|
|
});
|
|
|
|
describe('getApiKeys', () => {
|
|
describe('when includeExpired is false', () => {
|
|
it('should return all keys if no search query', () => {
|
|
const mockState: ApiKeysState = {
|
|
keys: mockKeys,
|
|
keysIncludingExpired: mockKeysIncludingExpired,
|
|
searchQuery: '',
|
|
hasFetched: true,
|
|
includeExpired: false,
|
|
};
|
|
const keys = getApiKeys(mockState);
|
|
expect(keys).toEqual(mockKeys);
|
|
});
|
|
|
|
it('should filter keys if search query exists', () => {
|
|
const mockState: ApiKeysState = {
|
|
keys: mockKeys,
|
|
keysIncludingExpired: mockKeysIncludingExpired,
|
|
searchQuery: '5',
|
|
hasFetched: true,
|
|
includeExpired: false,
|
|
};
|
|
const keys = getApiKeys(mockState);
|
|
expect(keys.length).toEqual(1);
|
|
});
|
|
});
|
|
|
|
describe('when includeExpired is true', () => {
|
|
it('should return all keys if no search query', () => {
|
|
const mockState: ApiKeysState = {
|
|
keys: mockKeys,
|
|
keysIncludingExpired: mockKeysIncludingExpired,
|
|
searchQuery: '',
|
|
hasFetched: true,
|
|
includeExpired: true,
|
|
};
|
|
const keys = getApiKeys(mockState);
|
|
expect(keys).toEqual(mockKeysIncludingExpired);
|
|
});
|
|
|
|
it('should filter keys if search query exists', () => {
|
|
const mockState: ApiKeysState = {
|
|
keys: mockKeys,
|
|
keysIncludingExpired: mockKeysIncludingExpired,
|
|
searchQuery: '5',
|
|
hasFetched: true,
|
|
includeExpired: true,
|
|
};
|
|
const keys = getApiKeys(mockState);
|
|
expect(keys.length).toEqual(1);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('getIncludeExpired', () => {
|
|
it('returns true if includeExpired is true', () => {
|
|
const mockState: ApiKeysState = {
|
|
keys: mockKeys,
|
|
keysIncludingExpired: mockKeysIncludingExpired,
|
|
searchQuery: '',
|
|
hasFetched: true,
|
|
includeExpired: true,
|
|
};
|
|
const includeExpired = getIncludeExpired(mockState);
|
|
expect(includeExpired).toBe(true);
|
|
});
|
|
|
|
it('returns false if includeExpired is false', () => {
|
|
const mockState: ApiKeysState = {
|
|
keys: mockKeys,
|
|
keysIncludingExpired: mockKeysIncludingExpired,
|
|
searchQuery: '',
|
|
hasFetched: true,
|
|
includeExpired: false,
|
|
};
|
|
const includeExpired = getIncludeExpired(mockState);
|
|
expect(includeExpired).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('getIncludeExpiredDisabled', () => {
|
|
it('returns true if there are no active keys but there are expired keys', () => {
|
|
const mockState: ApiKeysState = {
|
|
keys: [],
|
|
keysIncludingExpired: mockKeysIncludingExpired,
|
|
searchQuery: '',
|
|
hasFetched: true,
|
|
includeExpired: true,
|
|
};
|
|
const includeExpiredDisabled = getIncludeExpiredDisabled(mockState);
|
|
expect(includeExpiredDisabled).toBe(true);
|
|
});
|
|
|
|
it('returns false otherwise', () => {
|
|
const mockState: ApiKeysState = {
|
|
keys: mockKeys,
|
|
keysIncludingExpired: mockKeysIncludingExpired,
|
|
searchQuery: '',
|
|
hasFetched: true,
|
|
includeExpired: false,
|
|
};
|
|
const includeExpiredDisabled = getIncludeExpired(mockState);
|
|
expect(includeExpiredDisabled).toBe(false);
|
|
});
|
|
});
|
|
});
|