payload_test.dart 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import 'package:flutter_test/flutter_test.dart';
  2. import 'package:rackpeek_mobile/data/payload.dart';
  3. void main() {
  4. group('resourcePatch', () {
  5. test('always carries kind and name', () {
  6. final patch = resourcePatch(kind: 'Server', name: 'srv01');
  7. expect(patch['kind'], 'Server');
  8. expect(patch['name'], 'srv01');
  9. expect(patch.length, 2);
  10. });
  11. test('omits null tags/labels/notes so merge leaves them untouched', () {
  12. final patch = resourcePatch(
  13. kind: 'System',
  14. name: 'pve01',
  15. fields: {'os': 'Debian 13'},
  16. );
  17. expect(patch['os'], 'Debian 13');
  18. expect(patch.containsKey('tags'), isFalse);
  19. expect(patch.containsKey('labels'), isFalse);
  20. expect(patch.containsKey('notes'), isFalse);
  21. });
  22. test('includes changed collections', () {
  23. final patch = resourcePatch(
  24. kind: 'Service',
  25. name: 'svc',
  26. tags: ['a', 'b'],
  27. labels: {'env': 'prod'},
  28. notes: 'hello',
  29. );
  30. expect(patch['tags'], ['a', 'b']);
  31. expect(patch['labels'], {'env': 'prod'});
  32. expect(patch['notes'], 'hello');
  33. });
  34. test('nested network patch passes through fields', () {
  35. final patch = resourcePatch(
  36. kind: 'Service',
  37. name: 'svc',
  38. fields: {
  39. 'network': {'ip': '10.0.0.5', 'port': 8080}
  40. },
  41. );
  42. expect((patch['network'] as Map)['port'], 8080);
  43. });
  44. });
  45. group('buildUpsertPayload', () {
  46. test('wraps resources with the document version', () {
  47. final payload = buildUpsertPayload(version: 4, resources: [
  48. {'kind': 'Server', 'name': 'a'}
  49. ]);
  50. expect(payload['version'], 4);
  51. expect((payload['resources'] as List).length, 1);
  52. expect(payload.containsKey('connections'), isFalse);
  53. });
  54. });
  55. }