import test from 'node:test'; import assert from 'node:assert/strict'; import repositoryModule from '../src/main/repository-service.cjs'; const { RepositoryService } = repositoryModule; function status(head = 'a'.repeat(40)) { return { head, shortHead: head.slice(0, 7), clean: true, counts: { changed: 0, conflicts: 0 }, branch: { head: 'main', upstream: 'origin/main', ahead: 0, behind: 0 } }; } const remote = { id: 1, name: 'Portfolio', full_name: 'Jens/Portfolio', owner: { login: 'Jens' }, private: true, default_branch: 'main', html_url: 'https://gitea.example/Jens/Portfolio', clone_url: 'https://gitea.example/Jens/Portfolio.git', ssh_url: 'git@gitea.example:Jens/Portfolio.git' }; function service() { return new RepositoryService({ data: { preferences: { preferredCloneProtocol: 'ssh' }, favorites: [] } }, {}, {}); } test('a synchronized commit is deployable when the server is unknown or older', () => { const current = status(); const unknown = service().decorate(remote, { localPath: 'C:/Projects/Portfolio', status: current }, [ { id: 'prod', branch: 'main', state: { liveSha: null, healthy: null } } ]); assert.equal(unknown.readyToDeploy, true); const older = service().decorate(remote, { localPath: 'C:/Projects/Portfolio', status: current }, [ { id: 'prod', branch: 'main', state: { liveSha: 'b'.repeat(40), healthy: true } } ]); assert.equal(older.readyToDeploy, true); }); test('a healthy commit already live on the server is not offered for deployment again', () => { const current = status(); const repository = service().decorate(remote, { localPath: 'C:/Projects/Portfolio', status: current }, [ { id: 'prod', branch: 'main', state: { liveSha: current.head, healthy: true } } ]); assert.equal(repository.readyToDeploy, false); }); test('an unhealthy live commit remains eligible for a controlled redeploy', () => { const current = status(); const repository = service().decorate(remote, { localPath: 'C:/Projects/Portfolio', status: current }, [ { id: 'prod', branch: 'main', state: { liveSha: current.head, healthy: false } } ]); assert.equal(repository.readyToDeploy, true); });