Skip to content

Commit

Permalink
Merge pull request #232 from atsign-foundation/notify_fetch
Browse files Browse the repository at this point in the history
feat: Introduce notifyFetch verb
  • Loading branch information
sitaram-kalluri authored Sep 26, 2022
2 parents 591b897 + d266f35 commit e20db04
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
2 changes: 2 additions & 0 deletions at_commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 3.0.26
* feat: Introduce notifyFetch verb
## 3.0.25
* fix: update regex to correctly parse negative values in ttl and ttb
* feat: add clientConfig to from verb syntax
Expand Down
1 change: 1 addition & 0 deletions at_commons/lib/at_builders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export 'package:at_commons/src/verb/syntax.dart';
export 'package:at_commons/src/verb/update_verb_builder.dart';
export 'package:at_commons/src/verb/verb_builder.dart';
export 'package:at_commons/src/verb/from_verb_builder.dart';
export 'package:at_commons/src/verb/notify_fetch_verb_builder.dart';
43 changes: 43 additions & 0 deletions at_commons/lib/src/verb/notify_fetch_verb_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:at_commons/at_commons.dart';
import 'package:at_commons/src/verb/verb_builder.dart';

/// NotifyFetchVerbBuilder generated the command to fetches the notification
/// with the given notification-id
///
/// ```
/// e.g. To fetch the notification with the notification-id - '21d617cd-fb8a-43e4-98df-7e1536818d59'
///
/// var notifyFetchVerbBuilder = NotifyFetchVerbBuilder()
/// ..notificationId = '21d617cd-fb8a-43e4-98df-7e1536818d59';
///
/// Throws InvalidSyntaxException if notification id is not set or initialized to empty string
/// ```
class NotifyFetchVerbBuilder implements VerbBuilder {
/// Notification Id to fetch the notification
late String notificationId;

@override
String buildCommand() {
var command = 'notify:fetch:';
try {
if (notificationId.isEmpty) {
throw InvalidSyntaxException(
'Notification-id is empty. Notification-id is mandatory');
}
} on Error {
throw InvalidSyntaxException(
'Notification-id is not set. Notification-id is mandatory');
}
command += '$notificationId\n';
return command;
}

@override
bool checkParams() {
var isValid = true;
if (notificationId.isEmpty) {
isValid = false;
}
return isValid;
}
}
1 change: 1 addition & 0 deletions at_commons/lib/src/verb/syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class VerbSyntax {
static const notifyList =
r'^notify:list(:(?<fromDate>\d{4}-[01]?\d?-[0123]?\d?))?(:(?<toDate>\d{4}-[01]?\d?-[0123]?\d?))?(:(?<regex>[^:]+))?';
static const notifyStatus = r'^notify:status:(?<notificationId>\S+)$';
static const notifyFetch = r'^notify:fetch:(?<notificationId>\S+)$';
static const notifyAll =
r'^notify:all:((?<operation>update|delete):)?(messageType:((?<messageType>key|text):))?(?:ttl:(?<ttl>\d+):)?(?:ttb:(?<ttb>\d+):)?(?:ttr:(?<ttr>-?\d+):)?(?:ccd:(?<ccd>true|false+):)?(?<forAtSign>(([^:\s])+)?(,([^:\s]+))*)(:(?<atKey>[^@:\s]+))(@(?<atSign>[^@:\s]+))?(:(?<value>.+))?$';
static const batch = r'^batch:(?<json>.+)$';
Expand Down
2 changes: 1 addition & 1 deletion at_commons/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: at_commons
description: A library of Dart and Flutter utility classes that are used across other components of the atPlatform.
version: 3.0.25
version: 3.0.26
repository: https://github.com/atsign-foundation/at_tools
homepage: https://atsign.dev

Expand Down
23 changes: 23 additions & 0 deletions at_commons/test/notify_verb_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,27 @@ void main() {
} catch (e, s) {
print(s);
}

group('A group of test to validate notify fetch verb', () {
test('Test to verify to notify:fetch', () {
var notifyFetch = NotifyFetchVerbBuilder()..notificationId = '123';
var notifyFetchCommand = notifyFetch.buildCommand();
expect(notifyFetchCommand, 'notify:fetch:123\n');
var verbParams =
getVerbParams(VerbSyntax.notifyFetch, notifyFetchCommand.trim());
expect(verbParams['notificationId'], '123');
});

test('Negative test to verify to notify:fetch when notification id not set', () {
var notifyFetch = NotifyFetchVerbBuilder();
expect(() => notifyFetch.buildCommand(),
throwsA(predicate((dynamic e) => e is InvalidSyntaxException)));
});

test('Negative test to verify to notify:fetch when empty string is set', () {
var notifyFetch = NotifyFetchVerbBuilder()..notificationId = '';
expect(() => notifyFetch.buildCommand(),
throwsA(predicate((dynamic e) => e is InvalidSyntaxException)));
});
});
}

0 comments on commit e20db04

Please sign in to comment.