// 观看计费响应模型解析单测(《03-接口文档》5.3 cost_type 0/1/2/3) import 'package:flutter_test/flutter_test.dart'; import 'package:video_app/models/watch_result.dart'; void main() { group('WatchResult.fromJson', () { test('cost_type=0 占用免费额度', () { final r = WatchResult.fromJson(const { 'cost_type': 0, 'cost_points': 0, 'remaining_points': 86, 'free_remaining_today': 7, }); expect(r.costType, 0); expect(r.isPointsCost, isFalse); expect(r.freeRemainingToday, 7); expect(r.remainingPoints, 86); }); test('cost_type=1 积分扣减,isPointsCost 为 true', () { final r = WatchResult.fromJson(const { 'cost_type': 1, 'cost_points': 1, 'remaining_points': 85, 'free_remaining_today': 0, }); expect(r.isPointsCost, isTrue); expect(r.costPoints, 1); expect(r.remainingPoints, 85); }); test('cost_type=2 会员免费', () { final r = WatchResult.fromJson(const { 'cost_type': 2, 'cost_points': 0, 'remaining_points': 86, 'free_remaining_today': 10, }); expect(r.isPointsCost, isFalse); }); test('cost_type=3 重复观看或本人作品', () { final r = WatchResult.fromJson(const { 'cost_type': 3, 'cost_points': 0, 'remaining_points': 86, 'free_remaining_today': 10, }); expect(r.isPointsCost, isFalse); }); test('字段缺失时按 0 兜底', () { final r = WatchResult.fromJson(const {}); expect(r.costType, 0); expect(r.costPoints, 0); expect(r.remainingPoints, 0); expect(r.freeRemainingToday, 0); }); }); }