- Updated OAuth endpoints for Challonge and Discord in platforms configuration. - Implemented session and CSRF cookie initialization in main application entry. - Enhanced Challonge API client to avoid sending sensitive API keys from the browser. - Modified tournament querying to handle new state definitions and improved error handling. - Updated UI components to reflect server-side storage of authentication tokens. - Improved user experience in API Key Manager and Authentication Hub with clearer messaging. - Refactored client credentials management to support asynchronous operations. - Adjusted API client tests to validate new request configurations. - Updated Vite configuration to support session and CSRF handling through proxies.
123 lines
3.2 KiB
JavaScript
123 lines
3.2 KiB
JavaScript
/**
|
|
* useChallongeClient Composable Tests
|
|
*/
|
|
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
import { ref } from 'vue';
|
|
import { ScopeType } from '../../../src/services/challonge.service.js';
|
|
|
|
// Mock dependencies before importing composable
|
|
vi.mock('../../../src/composables/useChallongeApiKey.js', () => ({
|
|
useChallongeApiKey: () => ({
|
|
isKeyStored: ref(true),
|
|
getApiKey: () => null
|
|
})
|
|
}));
|
|
|
|
vi.mock('../../../src/composables/useChallongeOAuth.js', () => ({
|
|
useChallongeOAuth: () => ({
|
|
isAuthenticated: ref(false),
|
|
accessToken: ref(null)
|
|
})
|
|
}));
|
|
|
|
vi.mock('../../../src/composables/useChallongeClientCredentials.js', () => ({
|
|
useChallongeClientCredentials: () => ({
|
|
isAuthenticated: ref(false),
|
|
accessToken: ref(null)
|
|
})
|
|
}));
|
|
|
|
vi.mock('../../../src/services/challonge.service.js', async () => {
|
|
const actual = await vi.importActual(
|
|
'../../../src/services/challonge.service.js'
|
|
);
|
|
return {
|
|
...actual,
|
|
createChallongeV1Client: vi.fn(() => ({ version: 'v1', mock: true })),
|
|
createChallongeV2Client: vi.fn(() => ({ version: 'v2.1', mock: true }))
|
|
};
|
|
});
|
|
|
|
import { useChallongeClient } from '../../../src/composables/useChallongeClient.js';
|
|
|
|
describe('useChallongeClient', () => {
|
|
it('creates composable with default values', () => {
|
|
const { apiVersion, tournamentScope, debugMode } = useChallongeClient();
|
|
|
|
expect(apiVersion.value).toBe('v2.1');
|
|
expect(tournamentScope.value).toBe(ScopeType.USER);
|
|
expect(debugMode.value).toBe(false);
|
|
});
|
|
|
|
it('creates client successfully', () => {
|
|
const { client } = useChallongeClient();
|
|
|
|
expect(client.value).toBeDefined();
|
|
expect(client.value).toHaveProperty('version');
|
|
});
|
|
|
|
it('switches API version', () => {
|
|
const { apiVersion, switchVersion } = useChallongeClient();
|
|
|
|
expect(apiVersion.value).toBe('v2.1');
|
|
|
|
switchVersion('v1');
|
|
|
|
expect(apiVersion.value).toBe('v1');
|
|
});
|
|
|
|
it('throws error for invalid API version', () => {
|
|
const { switchVersion } = useChallongeClient();
|
|
|
|
expect(() => switchVersion('v3')).toThrow('Invalid API version');
|
|
});
|
|
|
|
it('changes tournament scope', () => {
|
|
const { tournamentScope, setScope } = useChallongeClient();
|
|
|
|
expect(tournamentScope.value).toBe(ScopeType.USER);
|
|
|
|
setScope(ScopeType.APPLICATION);
|
|
|
|
expect(tournamentScope.value).toBe(ScopeType.APPLICATION);
|
|
});
|
|
|
|
it('throws error for invalid scope', () => {
|
|
const { setScope } = useChallongeClient();
|
|
|
|
expect(() => setScope('invalid')).toThrow('Invalid scope type');
|
|
});
|
|
|
|
it('masks API key correctly', () => {
|
|
const { maskedApiKey } = useChallongeClient();
|
|
|
|
expect(maskedApiKey.value).toBe('stored on server');
|
|
});
|
|
|
|
it('returns auth type', () => {
|
|
const { authType } = useChallongeClient();
|
|
|
|
expect(authType.value).toBe('API Key');
|
|
});
|
|
|
|
it('toggles debug mode', () => {
|
|
const { debugMode, setDebugMode } = useChallongeClient();
|
|
|
|
expect(debugMode.value).toBe(false);
|
|
|
|
setDebugMode(true);
|
|
|
|
expect(debugMode.value).toBe(true);
|
|
});
|
|
|
|
it('exposes constants', () => {
|
|
const { ScopeType: ST, AuthType: AT } = useChallongeClient();
|
|
|
|
expect(ST).toBeDefined();
|
|
expect(AT).toBeDefined();
|
|
expect(ST.USER).toBeDefined();
|
|
expect(ST.APPLICATION).toBeDefined();
|
|
});
|
|
});
|