Skip to content

Commit

Permalink
dev deps: Upgrade checks to 0.3.0, handling breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbobbe committed Feb 2, 2024
1 parent d413ffd commit 92e9478
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 45 deletions.
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ packages:
dependency: "direct dev"
description:
name: checks
sha256: "03c1a2e4a4d3341ce0512f1401204ecdcdca8cc035e373820a73929cc0bf4fd3"
sha256: aad431b45a8ae2fa26db8c22e385b9cdec73f72986a1d9d9f2017f4c39ecf5c9
url: "https://pub.dev"
source: hosted
version: "0.2.2"
version: "0.3.0"
cli_util:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ dev_dependencies:
json_serializable: ^6.5.4
build_runner: ^2.3.3
test: ^1.23.1
checks: ^0.2.2
checks: ^0.3.0
drift_dev: ^2.5.2
fake_async: ^1.3.1

Expand Down
27 changes: 13 additions & 14 deletions test/api/core_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:convert';
import 'dart:io';

import 'package:checks/checks.dart';
import 'package:checks/context.dart';
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
import 'package:http/http.dart' as http;
import 'package:test/scaffolding.dart';
Expand Down Expand Up @@ -85,12 +84,12 @@ void main() {
..url.asString.equals('${eg.realmUrl.origin}/api/v1/example/route')
..headers.deepEquals(authHeader(email: eg.selfAccount.email, apiKey: eg.selfAccount.apiKey))
..fields.deepEquals({})
..files.single.which(it()
..files.single.which((it) => it
..field.equals('file')
..length.equals(length)
..filename.equals(filename)
..has<Future<List<int>>>((f) => f.finalize().toBytes(), 'contents')
.completes(it()..deepEquals(content.expand((l) => l)))
.completes((it) => it..deepEquals(content.expand((l) => l)))
);
});
}
Expand Down Expand Up @@ -148,16 +147,16 @@ void main() {
Future<void> checkRequest<T extends Object>(
T exception, Condition<NetworkException> condition) {
return check(tryRequest(exception: exception))
.throws<NetworkException>(it()
.throws<NetworkException>((it) => it
..routeName.equals(kExampleRouteName)
..cause.equals(exception)
..which(condition));
}

final zulipLocalizations = lookupZulipLocalizations(ZulipLocalizations.supportedLocales.first);
checkRequest(http.ClientException('Oops'), it()..message.equals('Oops'));
checkRequest(const TlsException('Oops'), it()..message.equals('Oops'));
checkRequest((foo: 'bar'), it()
checkRequest(http.ClientException('Oops'), (it) => it..message.equals('Oops'));
checkRequest(const TlsException('Oops'), (it) => it..message.equals('Oops'));
checkRequest((foo: 'bar'), (it) => it
..message.equals(zulipLocalizations.errorNetworkRequestFailed));
});

Expand All @@ -176,7 +175,7 @@ void main() {
...data,
};
await check(tryRequest(httpStatus: httpStatus, json: json))
.throws<ZulipApiException>(it()
.throws<ZulipApiException>((it) => it
..routeName.equals(kExampleRouteName)
..httpStatus.equals(httpStatus)
..code.equals(expectedCode ?? code!)
Expand All @@ -197,7 +196,7 @@ void main() {
int httpStatus = 400, Map<String, dynamic>? json, String? body}) async {
assert((json == null) != (body == null));
await check(tryRequest(httpStatus: httpStatus, json: json, body: body))
.throws<MalformedServerResponseException>(it()
.throws<MalformedServerResponseException>((it) => it
..routeName.equals(kExampleRouteName)
..httpStatus.equals(httpStatus)
..data.deepEquals(json));
Expand All @@ -224,7 +223,7 @@ void main() {
Future<void> check5xx({
required int httpStatus, Map<String, dynamic>? json, String? body}) {
return check(tryRequest(httpStatus: httpStatus, json: json, body: body))
.throws<Server5xxException>(it()
.throws<Server5xxException>((it) => it
..routeName.equals(kExampleRouteName)
..httpStatus.equals(httpStatus)
..data.deepEquals(json));
Expand All @@ -241,7 +240,7 @@ void main() {
Future<void> checkMalformed({
required int httpStatus, Map<String, dynamic>? json, String? body}) {
return check(tryRequest(httpStatus: httpStatus, json: json, body: body))
.throws<MalformedServerResponseException>(it()
.throws<MalformedServerResponseException>((it) => it
..routeName.equals(kExampleRouteName)
..httpStatus.equals(httpStatus)
..data.deepEquals(json));
Expand All @@ -260,13 +259,13 @@ void main() {
Object? Function(Map<String, dynamic>)? fromJson,
}) {
return check(tryRequest(json: json, body: body, fromJson: fromJson))
.throws<MalformedServerResponseException>(it()
.throws<MalformedServerResponseException>((it) => it
..routeName.equals(kExampleRouteName)
..httpStatus.equals(200)
..data.deepEquals(json));
}

await check(tryRequest<Map>(json: {})).completes(it()..deepEquals({}));
await check(tryRequest<Map>(json: {})).completes((it) => it..deepEquals({}));

await checkMalformed(body: jsonEncode([]));
await checkMalformed(body: jsonEncode(null));
Expand All @@ -275,7 +274,7 @@ void main() {
await checkMalformed(body: 'not JSON');

await check(tryRequest(json: {'x': 'y'}, fromJson: (json) => json['x'] as String))
.completes(it()..equals('y'));
.completes((it) => it..equals('y'));
await checkMalformed( json: {}, fromJson: (json) => json['x'] as String);
await checkMalformed( json: {'x': 3}, fromJson: (json) => json['x'] as String);
});
Expand Down
2 changes: 1 addition & 1 deletion test/api/model/model_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extension ReactionWithVotesChecks on Subject<ReactionWithVotes> {
// No double-votes from one person (we don't expect this from servers)
assert(userIds.length == reactions.length);

return which(it()
return which((it) => it
..reactionType.equals(first.reactionType)
..emojiCode.equals(first.emojiCode)
..userIds.deepEquals(userIds)
Expand Down
2 changes: 1 addition & 1 deletion test/api/model/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void main() {
check(mkUser({'profile_data': <String, dynamic>{}}).profileData).isNull();
check(mkUser({'profile_data': null}).profileData).isNull();
check(mkUser({'profile_data': {'1': {'value': 'foo'}}}).profileData)
.isNotNull().deepEquals({1: it()});
.isNotNull().deepEquals({1: (it) => it});
});

test('is_system_bot', () {
Expand Down
5 changes: 2 additions & 3 deletions test/api/model/reaction_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:checks/checks.dart';
import 'package:checks/context.dart';
import 'package:test/scaffolding.dart';
import 'package:zulip/api/model/reaction.dart';

Expand All @@ -8,8 +7,8 @@ import 'model_checks.dart';
void main() {
group('Reactions', () {
// helper to cut out "it()..isA<ReactionWithVotes>()" goo for callers
ConditionSubject matchesReactions(List<Reaction> reactions) {
return it()..isA<ReactionWithVotes>().matchesReactions(reactions);
matchesReactions(List<Reaction> reactions) {
return (Subject<Object?> it) => it..isA<ReactionWithVotes>().matchesReactions(reactions);
}

test('fromJson', () {
Expand Down
4 changes: 2 additions & 2 deletions test/api/notifications_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void main() {
..senderAvatarUrl.equals(Uri.parse(streamJson['sender_avatar_url']!))
..senderFullName.equals(streamJson['sender_full_name']!)
..zulipMessageId.equals(12345)
..recipient.isA<FcmMessageStreamRecipient>().which(it()
..recipient.isA<FcmMessageStreamRecipient>().which((it) => it
..streamId.equals(42)
..streamName.equals(streamJson['stream']!)
..topic.equals(streamJson['topic']!))
Expand All @@ -94,7 +94,7 @@ void main() {

test('optional fields missing cause no error', () {
check(parse({ ...streamJson }..remove('stream')))
.recipient.isA<FcmMessageStreamRecipient>().which(it()
.recipient.isA<FcmMessageStreamRecipient>().which((it) => it
..streamId.equals(42)
..streamName.isNull());
});
Expand Down
2 changes: 1 addition & 1 deletion test/model/database_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void main() {
.first;
check(account.toCompanion(false).toJson()).deepEquals({
...accountData.toJson(),
'id': it(),
'id': (it) => it,
'acked_push_token': null,
});
});
Expand Down
32 changes: 16 additions & 16 deletions test/model/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ void main() async {

final message = model.messages.single;
check(message)
..content.not(it()..equals(updateEvent.renderedContent!))
..content.not((it) => it..equals(updateEvent.renderedContent!))
..lastEditTimestamp.isNull()
..flags.not(it()..deepEquals(updateEvent.flags))
..isMeMessage.not(it()..equals(updateEvent.isMeMessage!));
..flags.not((it) => it..deepEquals(updateEvent.flags))
..isMeMessage.not((it) => it..equals(updateEvent.isMeMessage!));

model.maybeUpdateMessage(updateEvent);
checkNotifiedOnce();
Expand All @@ -310,7 +310,7 @@ void main() async {
checkNotNotified();
check(model).messages.single
..content.equals(originalMessage.content)
..content.not(it()..equals(updateEvent.renderedContent!));
..content.not((it) => it..equals(updateEvent.renderedContent!));
});

// TODO(server-5): Cut legacy case for rendering-only message update
Expand All @@ -336,7 +336,7 @@ void main() async {
..content.equals(updateEvent.renderedContent!)
// ... edit timestamp is not.
..lastEditTimestamp.equals(originalMessage.lastEditTimestamp)
..lastEditTimestamp.not(it()..equals(updateEvent.editTimestamp));
..lastEditTimestamp.not((it) => it..equals(updateEvent.editTimestamp));
}

test('rendering-only update does not change timestamp', () async {
Expand Down Expand Up @@ -545,7 +545,7 @@ void main() async {
model.contents[0] = const ZulipContent(nodes: [
ParagraphNode(links: null, nodes: [TextNode('something outdated')])
]);
check(model.contents[0]).not(it()..equalsNode(correctContent));
check(model.contents[0]).not((it) => it..equalsNode(correctContent));

model.reassemble();
checkNotifiedOnce();
Expand Down Expand Up @@ -802,16 +802,16 @@ void main() async {

// We check showSender has the right values in [checkInvariants],
// but to make this test explicit:
check(model.items).deepEquals([
it()..isA<MessageListHistoryStartItem>(),
it()..isA<MessageListRecipientHeaderItem>(),
it()..isA<MessageListMessageItem>().showSender.isTrue(),
it()..isA<MessageListMessageItem>().showSender.isFalse(),
it()..isA<MessageListMessageItem>().showSender.isTrue(),
it()..isA<MessageListRecipientHeaderItem>(),
it()..isA<MessageListMessageItem>().showSender.isTrue(),
it()..isA<MessageListDateSeparatorItem>(),
it()..isA<MessageListMessageItem>().showSender.isTrue(),
check(model.items).deepEquals(<void Function(Subject<Object?>)>[
(it) => it..isA<MessageListHistoryStartItem>(),
(it) => it..isA<MessageListRecipientHeaderItem>(),
(it) => it..isA<MessageListMessageItem>().showSender.isTrue(),
(it) => it..isA<MessageListMessageItem>().showSender.isFalse(),
(it) => it..isA<MessageListMessageItem>().showSender.isTrue(),
(it) => it..isA<MessageListRecipientHeaderItem>(),
(it) => it..isA<MessageListMessageItem>().showSender.isTrue(),
(it) => it..isA<MessageListDateSeparatorItem>(),
(it) => it..isA<MessageListMessageItem>().showSender.isTrue(),
]);
});

Expand Down
2 changes: 1 addition & 1 deletion test/model/store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void main() {
await Future.delayed(Duration.zero);

// The global store has a new store.
check(globalStore.perAccountSync(store.account.id)).not(it()..identicalTo(store));
check(globalStore.perAccountSync(store.account.id)).not((it) => it..identicalTo(store));
updateFromGlobalStore();

// The new UpdateMachine updates the new store.
Expand Down
2 changes: 1 addition & 1 deletion test/notifications_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void main() {
..title.equals(expectedTitle)
..body.equals(data.content)
..payload.equals(jsonEncode(data.toJson()))
..notificationDetails.isNotNull().android.isNotNull().which(it()
..notificationDetails.isNotNull().android.isNotNull().which((it) => it
..channelId.equals(NotificationChannelManager.kChannelId)
..tag.equals(expectedTag)
..color.equals(kZulipBrandColor)
Expand Down
2 changes: 1 addition & 1 deletion test/widgets/action_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void main() {
builder.selection = TextSelection.collapsed(offset: builder.text.length);
}
check(contentController).value.equals(builder.value);
check(contentController).not(it()..validationErrors.contains(ContentValidationError.quoteAndReplyInProgress));
check(contentController).not((it) => it..validationErrors.contains(ContentValidationError.quoteAndReplyInProgress));
}

testWidgets('in stream narrow', (WidgetTester tester) async {
Expand Down
2 changes: 1 addition & 1 deletion test/widgets/store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void main() {

// (... even one that really is separate, with its own fresh state node ...)
check(tester.state(find.byType(PerAccountStoreWidget)))
.not(it()..identicalTo(oldState));
.not((it) => it..identicalTo(oldState));

// ... then its child appears immediately, without waiting to load.
check(tester.any(find.textContaining('found store'))).isTrue();
Expand Down

0 comments on commit 92e9478

Please sign in to comment.