Skip to content

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srieteja committed Sep 12, 2024
1 parent 508f766 commit d33ef11
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/at_commons/lib/src/verb/syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class VerbSyntax {
static const notifyRemove = r'notify:remove:(?<id>[\w\d\-\_]+)';
static const enroll =
// The non-capturing group (?::)? matches ":" if the operation is request|approve|deny|revoke
r'^enroll:(?<operation>(?:(request|approve|deny|revoke|list|fetch|delete)))(:(?<force>force))?(?::)?((?<enrollParams>.+)|(<=list:)<enrollParams>.?)?$';
r'^enroll:(?<operation>(?:(request|approve|deny|revoke|list|fetch|unrevoke|delete)))(:(?<force>force))?(?::)?((?<enrollParams>.+)|(<=list:)<enrollParams>.?)?$';
static const otp =
r'^otp:(?<operation>get|put)(:(?<otp>(?<=put:)\w{6,}))?(:(?:ttl:(?<ttl>\d+)))?$';
static const keys = r'^keys:((?<operation>put|get|delete):?)'
Expand Down
8 changes: 8 additions & 0 deletions packages/at_commons/test/enroll_verb_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,13 @@ void main() {
expect(enrollVerbBuilder.buildCommand(),
'enroll:unrevoke:{"enrollmentId":"123"}\n');
});

test('A test to validate enroll delete command', () {
EnrollVerbBuilder enrollVerbBuilder = EnrollVerbBuilder()
..operation = EnrollOperationEnum.delete
..enrollmentId = '4785';
expect(enrollVerbBuilder.buildCommand(),
'enroll:delete:{"enrollmentId":"4785"}\n');
});
});
}
9 changes: 9 additions & 0 deletions packages/at_commons/test/syntax_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ void main() {
e is InvalidSyntaxException &&
e.message == 'command does not match the regex')));
});

test('A test to validate enroll delete command', () {
String command = 'enroll:delete:{"enrollmentId":"4567"}\n';
var enrollVerbParams =
VerbUtil.getVerbParam(VerbSyntax.enroll, command.trim());
expect(enrollVerbParams!['operation'], 'delete');
var enrollmentInfo = jsonDecode(enrollVerbParams['enrollParams']!);
expect(enrollmentInfo['enrollmentId'], '4567');
});
});

group('A group of tests related to otp verb', () {
Expand Down

0 comments on commit d33ef11

Please sign in to comment.