-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
22 changed files
with
239 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
.coverage | ||
coverage.lcov | ||
|
||
# Version file | ||
/VERSION | ||
|
||
# Environment variables | ||
.env | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import { describe, it, expect } from 'vitest' | ||
|
||
import { API_BASE_PREFIX } from '../common' | ||
import { API_BASE_PREFIX, API_PROXY_BASE_PREFIX } from '../common' | ||
|
||
describe('API_BASE_PREFIX constant', () => { | ||
it('returns the correct API base prefix in production mode', () => { | ||
describe('constants', () => { | ||
it('returns the correct proxy API base prefix in production mode', () => { | ||
const originalMode = import.meta.env.MODE | ||
expect(API_BASE_PREFIX).toBe('/proxy/annonars') | ||
expect(API_BASE_PREFIX).toBe('/') | ||
import.meta.env.MODE = originalMode | ||
}) | ||
|
||
it('returns the correct proxy API base prefix in production mode', () => { | ||
const originalMode = import.meta.env.MODE | ||
expect(API_PROXY_BASE_PREFIX).toBe('/proxy/') | ||
import.meta.env.MODE = originalMode | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { beforeEach, describe, it, expect, vi } from 'vitest' | ||
import createFetchMock from 'vitest-fetch-mock' | ||
|
||
import { MiscClient } from '../misc' | ||
|
||
const fetchMocker = createFetchMock(vi) | ||
|
||
describe('Misc Client', () => { | ||
beforeEach(() => { | ||
fetchMocker.enableMocks() | ||
fetchMocker.resetMocks() | ||
}) | ||
|
||
it('fetches version info correctly', async () => { | ||
fetchMocker.mockResponseOnce('v0.0.0') | ||
|
||
const client = new MiscClient() | ||
const result = await client.fetchVersion() | ||
expect(result).toEqual('v0.0.0') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const API_BASE_PREFIX = | ||
import.meta.env.MODE == 'development' ? '//localhost:8080/proxy/annonars' : '/proxy/annonars' | ||
export const API_BASE_PREFIX = import.meta.env.MODE == 'development' ? '//localhost:8080/' : '/' | ||
|
||
export const API_PROXY_BASE_PREFIX = `${API_BASE_PREFIX}proxy/` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { API_BASE_PREFIX } from '@/api/common' | ||
|
||
const API_BASE_URL = API_BASE_PREFIX | ||
|
||
export class MiscClient { | ||
private apiBaseUrl: string | ||
private csrfToken: string | null | ||
|
||
constructor(apiBaseUrl?: string, csrfToken?: string) { | ||
this.apiBaseUrl = apiBaseUrl ?? API_BASE_URL | ||
this.csrfToken = csrfToken ?? null | ||
} | ||
|
||
async fetchVersion(): Promise<any> { | ||
const response = await fetch(`${this.apiBaseUrl}version`, { | ||
method: 'GET' | ||
}) | ||
return await response.text() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { beforeEach, describe, it, expect, vi } from 'vitest' | ||
import createFetchMock from 'vitest-fetch-mock' | ||
|
||
import { setActivePinia, createPinia } from 'pinia' | ||
|
||
import { StoreState, useMiscStore } from '../misc' | ||
|
||
const fetchMocker = createFetchMock(vi) | ||
|
||
describe('miscInfo Store', () => { | ||
beforeEach(() => { | ||
setActivePinia(createPinia()) | ||
fetchMocker.enableMocks() | ||
fetchMocker.resetMocks() | ||
}) | ||
|
||
it('should have initial state', () => { | ||
const store = useMiscStore() | ||
|
||
expect(store.storeState).toBe(StoreState.Initial) | ||
expect(store.appVersion).toBe(null) | ||
}) | ||
|
||
it('should load data', async () => { | ||
const store = useMiscStore() | ||
fetchMocker.mockResponseOnce('v0.0.0') | ||
|
||
await store.initialize() | ||
|
||
expect(store.storeState).toBe(StoreState.Active) | ||
expect(store.appVersion).toBe('v0.0.0') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Store for misc info such as the current version. | ||
*/ | ||
|
||
import { defineStore } from 'pinia' | ||
import { ref } from 'vue' | ||
|
||
import { MiscClient } from '@/api/misc' | ||
|
||
export enum StoreState { | ||
Initial = 'initial', | ||
Loading = 'loading', | ||
Active = 'active', | ||
Error = 'error' | ||
} | ||
|
||
export const useMiscStore = defineStore('misc', () => { | ||
// The current store state | ||
const storeState = ref<StoreState>(StoreState.Initial) | ||
|
||
// The app version. | ||
const appVersion = ref<string | null>(null) | ||
|
||
// Initialize store, load version. | ||
const initialize = async () => { | ||
storeState.value = StoreState.Loading | ||
try { | ||
const client = new MiscClient() | ||
appVersion.value = await client.fetchVersion() | ||
|
||
storeState.value = StoreState.Active | ||
} catch (e) { | ||
console.error('There was an error loading the app version.', e) | ||
storeState.value = StoreState.Error | ||
} | ||
} | ||
|
||
return { | ||
storeState, | ||
appVersion, | ||
initialize | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.