archy/neode-ui/src/composables/__tests__/useMarketplaceApp.test.ts
Dorian f07ce10b1a refactor: update dependencies and remove unused code
- Added new dependencies: `adler2`, `crc32fast`, `flate2`, `miniz_oxide`, and `libredox`.
- Updated existing dependencies: `tokio-rustls` to version 0.26.4 and `filetime` to version 0.2.27.
- Removed the `backup.rs` file as it is no longer needed.
- Introduced tests for configuration and credential management.
- Enhanced the `identity` module to generate W3C compliant DID documents.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 00:19:30 +00:00

98 lines
3.1 KiB
TypeScript

import { describe, it, expect, beforeEach } from 'vitest'
import { useMarketplaceApp } from '../useMarketplaceApp'
describe('useMarketplaceApp', () => {
beforeEach(() => {
const { clearCurrentApp } = useMarketplaceApp()
clearCurrentApp()
})
it('getCurrentApp returns null initially', () => {
const { getCurrentApp } = useMarketplaceApp()
expect(getCurrentApp()).toBeNull()
})
it('setCurrentApp stores a full app', () => {
const { setCurrentApp, getCurrentApp } = useMarketplaceApp()
setCurrentApp({
id: 'bitcoin',
title: 'Bitcoin Core',
version: '25.0',
icon: '/icons/btc.png',
category: 'Finance',
description: 'Bitcoin node',
author: 'Satoshi',
source: 'github',
manifestUrl: 'https://example.com/manifest',
url: 'https://example.com',
repoUrl: 'https://github.com/bitcoin/bitcoin',
s9pkUrl: '',
dockerImage: 'bitcoin:25.0',
})
const app = getCurrentApp()
expect(app).not.toBeNull()
expect(app!.id).toBe('bitcoin')
expect(app!.title).toBe('Bitcoin Core')
expect(app!.version).toBe('25.0')
})
it('setCurrentApp with partial app fills defaults', () => {
const { setCurrentApp, getCurrentApp } = useMarketplaceApp()
setCurrentApp({ id: 'lnd' })
const app = getCurrentApp()
expect(app).not.toBeNull()
expect(app!.id).toBe('lnd')
expect(app!.title).toBe('')
expect(app!.version).toBe('')
expect(app!.icon).toBe('')
expect(app!.dockerImage).toBe('')
})
it('manifestUrl falls back to s9pkUrl then url', () => {
const { setCurrentApp, getCurrentApp } = useMarketplaceApp()
setCurrentApp({ id: 'test', s9pkUrl: 'https://s9pk.example.com/app.s9pk' })
const app = getCurrentApp()
expect(app!.manifestUrl).toBe('https://s9pk.example.com/app.s9pk')
expect(app!.url).toBe('https://s9pk.example.com/app.s9pk')
})
it('url falls back to s9pkUrl then manifestUrl', () => {
const { setCurrentApp, getCurrentApp } = useMarketplaceApp()
setCurrentApp({ id: 'test', manifestUrl: 'https://manifest.example.com' })
const app = getCurrentApp()
expect(app!.url).toBe('https://manifest.example.com')
})
it('clearCurrentApp sets app to null', () => {
const { setCurrentApp, clearCurrentApp, getCurrentApp } = useMarketplaceApp()
setCurrentApp({ id: 'bitcoin' })
expect(getCurrentApp()).not.toBeNull()
clearCurrentApp()
expect(getCurrentApp()).toBeNull()
})
it('shared state across multiple useMarketplaceApp calls', () => {
const instance1 = useMarketplaceApp()
const instance2 = useMarketplaceApp()
instance1.setCurrentApp({ id: 'mempool', title: 'Mempool' })
const app = instance2.getCurrentApp()
expect(app!.id).toBe('mempool')
expect(app!.title).toBe('Mempool')
})
it('handles description as object', () => {
const { setCurrentApp, getCurrentApp } = useMarketplaceApp()
setCurrentApp({
id: 'test',
description: { short: 'Short desc', long: 'Long description' },
})
const app = getCurrentApp()
expect(app!.description).toEqual({ short: 'Short desc', long: 'Long description' })
})
})