Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/providers/history_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ class HistoryMetaStateNotifier
void addHistoryRequest(HistoryRequestModel model) async {
final id = model.historyId;
state = {...state ?? {}, id: model.metaData};
final List<String> updatedHistoryKeys = state == null
? [id]
: [...state!.keys, id];
final List<String> updatedHistoryKeys = state?.keys.toList() ?? <String>[];
hiveHandler.setHistoryIds(updatedHistoryKeys);
hiveHandler.setHistoryMeta(id, model.metaData.toJson());
await hiveHandler.setHistoryRequest(id, model.toJson());
Expand Down
41 changes: 41 additions & 0 deletions test/providers/history_providers_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:apidash/models/models.dart';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/services/services.dart';
import 'package:apidash_core/apidash_core.dart';
import 'package:flutter_test/flutter_test.dart';
import 'helpers.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

setUp(() async {
await testSetUpTempDirForHive();
});

test('addHistoryRequest persists unique history ids only', () async {
final container = createContainer();
final notifier = container.read(historyMetaStateNotifier.notifier);

final historyId = getNewUuid();
final model = HistoryRequestModel(
historyId: historyId,
metaData: HistoryMetaModel(
historyId: historyId,
requestId: getNewUuid(),
apiType: APIType.rest,
url: 'https://api.apidash.dev',
method: HTTPVerb.get,
responseStatus: 200,
timeStamp: DateTime.now(),
),
httpResponseModel: const HttpResponseModel(),
);

notifier.addHistoryRequest(model);
await Future<void>.delayed(const Duration(milliseconds: 50));

final historyIds = hiveHandler.getHistoryIds() as List<String>?;
expect(historyIds, isNotNull);
expect(historyIds, [historyId]);
});
}