From 9486a70f1f0d1663d03320defd25abd533ea87ec Mon Sep 17 00:00:00 2001 From: Davide Grilli Date: Thu, 4 Jun 2026 16:18:00 +0200 Subject: [PATCH] test: aggiungi unit test per UpdateService MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copre parseVersion (semver standard, parti mancanti, valori non numerici) e isNewer (patch/minor/major bump, versione uguale, versione più vecchia, componenti multi-cifra come 2.0.10 > 2.0.9). 10/10 test passati su ARM64. Co-Authored-By: Claude Sonnet 4.6 --- test/shared/services/update_service_test.dart | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/shared/services/update_service_test.dart diff --git a/test/shared/services/update_service_test.dart b/test/shared/services/update_service_test.dart new file mode 100644 index 0000000..8403097 --- /dev/null +++ b/test/shared/services/update_service_test.dart @@ -0,0 +1,51 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:biteplan/shared/services/update_service.dart'; + +void main() { + group('UpdateService.parseVersion', () { + test('parses standard semver', () { + expect(UpdateService.parseVersion('2.1.3'), [2, 1, 3]); + }); + + test('pads missing parts with zeros', () { + expect(UpdateService.parseVersion('2.1'), [2, 1, 0]); + expect(UpdateService.parseVersion('2'), [2, 0, 0]); + }); + + test('handles non-numeric parts as zero', () { + expect(UpdateService.parseVersion('2.x.3'), [2, 0, 3]); + }); + }); + + group('UpdateService.isNewer', () { + test('patch bump is newer', () { + expect(UpdateService.isNewer('2.0.1', '2.0.0'), isTrue); + }); + + test('minor bump is newer', () { + expect(UpdateService.isNewer('2.1.0', '2.0.9'), isTrue); + }); + + test('major bump is newer', () { + expect(UpdateService.isNewer('3.0.0', '2.9.9'), isTrue); + }); + + test('same version is not newer', () { + expect(UpdateService.isNewer('2.0.0', '2.0.0'), isFalse); + }); + + test('older remote is not newer', () { + expect(UpdateService.isNewer('1.9.9', '2.0.0'), isFalse); + }); + + test('remote with v-prefix stripped is handled correctly', () { + // tag_name comes in already stripped of 'v' by checkUpdate + expect(UpdateService.isNewer('2.0.1', '2.0.0'), isTrue); + }); + + test('multi-digit version components', () { + expect(UpdateService.isNewer('2.0.10', '2.0.9'), isTrue); + expect(UpdateService.isNewer('2.10.0', '2.9.0'), isTrue); + }); + }); +}