Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new method to fetch enrollment requests #1200

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
233c040
feat: add new method fetchEnrollmentRequests() to AtClientImpl
srieteja Jan 10, 2024
07ef40f
test: add unit test
srieteja Jan 10, 2024
5a724a8
refactor: minor refactoring in RemoteSecondary
srieteja Jan 10, 2024
dfa6750
refactor: run dart formatter
srieteja Jan 11, 2024
d4bc099
Merge branch 'trunk' into enroll_list_client
srieteja Jan 11, 2024
bda846a
test: add functional test
srieteja Jan 11, 2024
d557101
Merge remote-tracking branch 'origin/enroll_list_client' into enroll_…
srieteja Jan 11, 2024
3d16f43
test: fix functional tests
srieteja Jan 11, 2024
3dfaaff
test: fix functional tests
srieteja Jan 11, 2024
d751c84
test: change the atsign used in the new test
srieteja Jan 11, 2024
68b5662
test: fix functional tests
srieteja Jan 11, 2024
c4cca0c
test: run dart formatter
srieteja Jan 11, 2024
17f342a
feat: introduced two classes for input and output of fetchEnrollmentR…
srieteja Jan 16, 2024
1816b39
tests: updated tests w.r.t. EnrollRequestParam and EnrollmentRequest …
srieteja Jan 16, 2024
3c669f7
Merge branch 'trunk' into enroll_list_client
srieteja Jan 16, 2024
17863da
fix: introduce toJson(), fromJson() and get enrollmentId for Enrollme…
srieteja Jan 17, 2024
3e01557
fix: make enrollRequestParams mandatory; and update tests
srieteja Jan 17, 2024
27081c1
Merge remote-tracking branch 'origin/enroll_list_client' into enroll_…
srieteja Jan 17, 2024
265f306
Merge branch 'trunk' into enroll_list_client
srieteja Jan 17, 2024
d6accd7
reformat: run the dart formatter
srieteja Jan 17, 2024
ff55915
Merge remote-tracking branch 'origin/enroll_list_client' into enroll_…
srieteja Jan 17, 2024
ffa9aec
reformat: address review comments
srieteja Jan 17, 2024
d0a0f0a
Merge branch 'trunk' into enroll_list_client
srieteja Jan 17, 2024
a6f3d28
reformat: run dart formatter
srieteja Jan 17, 2024
e20d2eb
Merge remote-tracking branch 'origin/enroll_list_client' into enroll_…
srieteja Jan 17, 2024
decb706
docs: updated changelog
srieteja Jan 18, 2024
adb23f2
Merge branch 'trunk' into enroll_list_client
srieteja Jan 22, 2024
8a17438
Merge branch 'trunk' into enroll_list_client
srieteja Jan 24, 2024
8f1b820
Merge branch 'trunk' into enroll_list_client
murali-shris Jan 24, 2024
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
27 changes: 14 additions & 13 deletions packages/at_client/lib/src/client/at_client_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -651,29 +651,30 @@ class AtClientImpl implements AtClient, AtSignChangeListener {

@override
Future<List<EnrollmentRequest>> fetchEnrollmentRequests(
{EnrollListRequestParam? enrollmentListRequest}) async {
EnrollListRequestParam enrollmentListRequestParams) async {
// enrollmentListRequestParams for now is not used
// A server side enhancement request is created. https://github.com/atsign-foundation/at_server/issues/1748
// On implementation of this enhancement/feature, the enrollListRequestParam object can be made use of
EnrollVerbBuilder enrollBuilder = EnrollVerbBuilder()
..operation = EnrollOperationEnum.list
..appName = enrollmentListRequest?.appName
..deviceName = enrollmentListRequest?.deviceName;
..appName = enrollmentListRequestParams.appName
..deviceName = enrollmentListRequestParams.deviceName;

var response = await getRemoteSecondary()
?.executeCommand(enrollBuilder.buildCommand(), auth: true);
srieteja marked this conversation as resolved.
Show resolved Hide resolved
response = response?.replaceFirst('data:', '');
Map<String, dynamic> enrollRequests = jsonDecode(response!);
stdout.writeln('enrollment lis req response: $response');
return _formatEnrollListResponse(enrollRequests);

return _formatEnrollListResponse(response);
}

List<EnrollmentRequest> _formatEnrollListResponse(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add fromJson and toJson to "EnrollmentRequest" class instead of setting in for loop.

EnrollmentRequest enrollmentRequest = EnrollmentRequest.fromJson(enrollRequest);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these methods have been introduced as part of 17863da

Map<String, dynamic> enrollRequests) {
response) {
response = response?.replaceFirst('data:', '');
Map<String, dynamic> enrollRequests = jsonDecode(response!);
List<EnrollmentRequest> enrollRequestsFormatted = [];

for (var request in enrollRequests.entries) {
enrollRequestsFormatted.add(EnrollmentRequest()
..enrollmentKey = request.key
..appName = request.value['appName']
..deviceName = request.value['deviceName']
..namespace = request.value['namespace']);
enrollRequestsFormatted.add(EnrollmentRequest.fromJson(request.value,
jsonIncludesKey: false, enrollmentKey: request.key));
}
return enrollRequestsFormatted;
}
Expand Down
13 changes: 9 additions & 4 deletions packages/at_client/lib/src/client/at_client_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,13 @@ abstract class AtClient {
/// Fetches all enrollment requests from the corresponding atServer; Formats the requests into a
/// List<[EnrollmentResponse]>
///
/// The optional param [EnrollListRequestParam] is present to avoid future compatibility issues over backwards compatibility
/// [enrollListRequest] for now does not have any functionality
Future<List<EnrollmentRequest>> fetchEnrollmentRequests(
{EnrollListRequestParam? enrollmentListRequest});
/// Responses can be filtered using params provided through [EnrollListRequestParam]
/// ```
/// e.g.
/// List<EnrollmentRequest> enrollmentRequests = fetchEnrollmentRequests(EnrollRequestParams());
/// enrollmentRequests now contains all the enrollment requests fetched from the server in the for of
/// EnrollmentRequest objects
/// ```
@experimental
Future<List<EnrollmentRequest>> fetchEnrollmentRequests(EnrollListRequestParam enrollmentListRequest);
}
39 changes: 39 additions & 0 deletions packages/at_client/lib/src/util/enrollment_request.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
import 'dart:collection';
import 'dart:convert';

import 'package:at_client/at_client.dart';

class EnrollmentRequest {
late String enrollmentKey;
late String appName;
late String deviceName;
late Map<String, dynamic> namespace;

String get enrollmentId {
return extractEnrollmentId(enrollmentKey);
}

@override
String toString() {
return 'Enrollment Request: enrollmentKey: $enrollmentKey | appName: $appName | deviceName: $deviceName | namespace: ${namespace.toString()}';
}

String toJson() {
srieteja marked this conversation as resolved.
Show resolved Hide resolved
Map jsonMap = HashMap();
jsonMap['enrollmentKey'] = enrollmentKey;
jsonMap['appName'] = appName;
jsonMap['deviceName'] = deviceName;
jsonMap['namespace'] = jsonEncode(namespace);

return jsonEncode(jsonMap);
}

static EnrollmentRequest fromJson(Map<String, dynamic> json,
{bool jsonIncludesKey = true, String? enrollmentKey}) {
EnrollmentRequest enrollmentRequest = EnrollmentRequest();
if (jsonIncludesKey) {
srieteja marked this conversation as resolved.
Show resolved Hide resolved
enrollmentRequest.enrollmentKey = json['enrollmentKey'];
} else if (!jsonIncludesKey && enrollmentKey != null) {
enrollmentRequest.enrollmentKey = enrollmentKey;
} else {
throw IllegalArgumentException('enrollment key not set');
}
return enrollmentRequest
..appName = json['appName']
..deviceName = json['deviceName']
..namespace = json['namespace'];
}

static String extractEnrollmentId(String enrollmentKey) {
return enrollmentKey.split('.')[0];
}
}
13 changes: 12 additions & 1 deletion packages/at_client/test/at_client_impl_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,28 @@ void main() {
AtClientImpl? clientImpl = client as AtClientImpl;

List<EnrollmentRequest> requests =
await clientImpl.fetchEnrollmentRequests();
await clientImpl.fetchEnrollmentRequests(EnrollListRequestParam());
expect(requests.length, 3);
expect(requests[0].appName, jsonDecode(enrollValue1)['appName']);
expect(requests[0].deviceName, jsonDecode(enrollValue1)['deviceName']);
expect(requests[0].namespace, jsonDecode(enrollValue1)['namespace']);

expect(requests[1].appName, jsonDecode(enrollValue2)['appName']);
expect(requests[1].deviceName, jsonDecode(enrollValue2)['deviceName']);
expect(requests[1].namespace, jsonDecode(enrollValue2)['namespace']);

expect(requests[2].appName, jsonDecode(enrollValue3)['appName']);
expect(requests[2].deviceName, jsonDecode(enrollValue3)['deviceName']);
expect(requests[2].namespace, jsonDecode(enrollValue3)['namespace']);
});

test('validate EnrollRequest.extractEnrollmentId()', () {
String enrollmentKey =
'0acdeb4d-1a2e-43e4-93bd-378f1d366ea7.new.enrollments.__manage@random';
String enrollmentId = '0acdeb4d-1a2e-43e4-93bd-378f1d366ea7';

expect(
EnrollmentRequest.extractEnrollmentId(enrollmentKey), enrollmentId);
});
});
}
18 changes: 8 additions & 10 deletions tests/at_functional_test/test/enrollment_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,23 @@ void main() {

// fetch enrollment requests through client
List<EnrollmentRequest> enrollmentRequests =
await client.fetchEnrollmentRequests();
for(var request in enrollmentRequests){
print(request);
}
expect(
enrollmentRequests.length, 4); // 4 entries - 2 entries from this test
await client.fetchEnrollmentRequests(EnrollListRequestParam());

expect(enrollmentRequests.length, 4);
// 4 entries - 2 entries from this test
// + 2 entries from the other test in this file.

String firstEnrollmentKey =
getEnrollmentKey(enrollResponse1JsonDecoded['enrollmentId'], atSign);
String secondEnrollmentKey =
getEnrollmentKey(enrollResponse2JsonDecoded['enrollmentId'], atSign);
int matchCount = 0;
for (var request in enrollmentRequests){
if(request.enrollmentKey == firstEnrollmentKey){
for (var request in enrollmentRequests) {
if (request.enrollmentKey == firstEnrollmentKey) {
expect(request.namespace['new_app'], 'rw');
expect(request.deviceName, 'pixel');
matchCount ++;
} else if (request.enrollmentKey == secondEnrollmentKey){
matchCount++;
} else if (request.enrollmentKey == secondEnrollmentKey) {
expect(request.namespace['new_app'], 'rw');
expect(request.namespace['wavi'], 'r');
expect(request.deviceName, 'pixel7');
Expand Down
Loading