Contrat IPC typé, stockage JSON atomique, journal fichier et validation des entrées
Some checks are pending
CI / windows (push) Waiting to run

This commit is contained in:
yasder5 2026-09-28 11:40:31 +02:00
parent afb305b3e8
commit 835f8cbbbb
11 changed files with 487 additions and 15 deletions

View file

@ -1,5 +0,0 @@
import { describe, expect, it } from 'vitest'
describe('projet', () => {
it('lance les tests', () => expect(1 + 1).toBe(2))
})

33
tests/store.test.ts Normal file
View file

@ -0,0 +1,33 @@
import { mkdtempSync, readFileSync, writeFileSync, readdirSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { Store } from '../src/main/store'
import { DEFAULT_SETTINGS } from '../src/shared/types'
const tmp = () => mkdtempSync(join(tmpdir(), 'orbe-'))
describe('Store', () => {
it('part des réglages par défaut et sauvegarde', () => {
const d = tmp(), s = new Store(d)
expect(s.settings).toEqual(DEFAULT_SETTINGS)
s.settings.volume = 0.2
s.flush()
expect(JSON.parse(readFileSync(join(d, 'settings.json'), 'utf8')).volume).toBe(0.2)
expect(new Store(d).settings.volume).toBe(0.2)
})
it('met de côté un fichier abîmé sans planter', () => {
const d = tmp()
writeFileSync(join(d, 'library.json'), '{pas du json')
const s = new Store(d)
expect(s.list()).toEqual([])
expect(readdirSync(d).some((f) => f.startsWith('library.json.bad-'))).toBe(true)
})
it('complète les scanners manquants', () => {
const d = tmp()
writeFileSync(join(d, 'settings.json'), JSON.stringify({ scanners: { steam: false } }))
expect(new Store(d).settings.scanners).toEqual({ ...DEFAULT_SETTINGS.scanners, steam: false })
})
})

16
tests/validate.test.ts Normal file
View file

@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest'
import { gamePatch, InvalidInput, settingsPatch } from '../src/main/validate'
describe('validation IPC', () => {
it('ignore les champs inconnus', () => {
expect(settingsPatch({ volume: 0.5, evil: 1 })).toEqual({ volume: 0.5 })
})
it('refuse les mauvais types', () => {
expect(() => settingsPatch({ volume: 3 })).toThrow(InvalidInput)
expect(() => settingsPatch({ language: 'de' })).toThrow(InvalidInput)
expect(() => gamePatch({ name: 'x'.repeat(500) })).toThrow(InvalidInput)
})
it('remplace un nom vide', () => {
expect(gamePatch({ name: ' ' }).name).toBe('Sans nom')
})
})