Skip to content

Commit

Permalink
Add directly as mentor in Group (#234)
Browse files Browse the repository at this point in the history
* feat(api): add support to directly add as a mentor in the group

Signed-off-by: Aman <aman2@me.iitr.ac.in>

* bfix: fix ci

Signed-off-by: Aman <aman2@me.iitr.ac.in>
  • Loading branch information
aman-singh7 authored Jul 18, 2022
1 parent ea9a5b3 commit 0d56fa3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
# Setup the flutter environment.
- uses: subosito/flutter-action@v1
with:
channel: "stable"
# Temporary fix to failing CI
flutter-version: '3.0.4'
# channel: "stable"

# Get flutter dependencies.
- run: flutter pub get
Expand Down
6 changes: 3 additions & 3 deletions lib/services/API/group_members_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class GroupMembersApi {
Future<GroupMembers>? fetchGroupMembers(String groupId);

Future<AddGroupMembersResponse>? addGroupMembers(
String groupId, String listOfMails);
String groupId, String listOfMails, bool isMentor);

Future updateMemberRole(String memberId, bool isMentor);

Expand Down Expand Up @@ -43,10 +43,10 @@ class HttpGroupMembersApi implements GroupMembersApi {

@override
Future<AddGroupMembersResponse>? addGroupMembers(
String groupId, String listOfMails) async {
String groupId, String listOfMails, bool isMentor) async {
var endpoint = '/groups/$groupId/members';
var uri = EnvironmentConfig.CV_API_BASE_URL + endpoint;
var json = {'emails': listOfMails};
var json = {'emails': listOfMails, 'mentor': isMentor};

try {
ApiUtils.addTokenToHeaders(headers);
Expand Down
7 changes: 4 additions & 3 deletions lib/ui/views/groups/group_details_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ class _GroupDetailsViewState extends State<GroupDetailsView> {
);
}

Future<void> onAddMemberPressed(BuildContext context) async {
Future<void> onAddMemberPressed(BuildContext context, bool isMentor) async {
if (Validators.validateAndSaveForm(_formKey)) {
FocusScope.of(context).requestFocus(FocusNode());
Navigator.pop(context);

_dialogService.showCustomProgressDialog(title: 'Adding');

await _model.addMembers(_recievedGroup.id, _emails!);
await _model.addMembers(_recievedGroup.id, _emails!, isMentor);

_dialogService.popDialog();

Expand Down Expand Up @@ -189,7 +189,8 @@ class _GroupDetailsViewState extends State<GroupDetailsView> {
),
CVFlatButton(
key: addButtonGlobalKey,
triggerFunction: onAddMemberPressed,
triggerFunction: (context) =>
onAddMemberPressed(context, !member),
context: context,
buttonText: 'ADD',
),
Expand Down
4 changes: 2 additions & 2 deletions lib/viewmodels/groups/group_details_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ class GroupDetailsViewModel extends BaseModel {
}
}

Future addMembers(String groupId, String emails) async {
Future addMembers(String groupId, String emails, bool isMentor) async {
setStateFor(ADD_GROUP_MEMBERS, ViewState.Busy);
try {
var addGroupMembers =
await _groupMembersApi.addGroupMembers(groupId, emails);
await _groupMembersApi.addGroupMembers(groupId, emails, isMentor);

var _addedMembers = addGroupMembers!.added.join(', ');
var _pendingMembers = addGroupMembers.pending.join(', ');
Expand Down
9 changes: 5 additions & 4 deletions test/service_tests/group_members_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,24 @@ void main() {
Response(jsonEncode(mockAddGroupMembersResponse), 201)));
var _groupMembersApi = HttpGroupMembersApi();

expect((await _groupMembersApi.addGroupMembers('1', '')).toString(),
expect(
(await _groupMembersApi.addGroupMembers('1', '', false)).toString(),
_addGroupMembersResponse.toString());
});

test('When called & http client throws Exceptions', () async {
var _groupMembersApi = HttpGroupMembersApi();

ApiUtils.client = MockClient((_) => throw UnauthorizedException(''));
expect(_groupMembersApi.addGroupMembers('1', ''),
expect(_groupMembersApi.addGroupMembers('1', '', false),
throwsA(isInstanceOf<Failure>()));

ApiUtils.client = MockClient((_) => throw NotFoundException(''));
expect(_groupMembersApi.addGroupMembers('1', ''),
expect(_groupMembersApi.addGroupMembers('1', '', false),
throwsA(isInstanceOf<Failure>()));

ApiUtils.client = MockClient((_) => throw Exception(''));
expect(_groupMembersApi.addGroupMembers('1', ''),
expect(_groupMembersApi.addGroupMembers('1', '', false),
throwsA(isInstanceOf<Failure>()));
});
});
Expand Down
10 changes: 5 additions & 5 deletions test/viewmodel_tests/groups/group_details_viewmodel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ void main() {
test('When called & service returns success response', () async {
var _mockGroupMembersApi = getAndRegisterGroupMembersApiMock();
when(_mockGroupMembersApi.addGroupMembers(
'1', 'test@test.com,pending@test.com,invalid@test.com'))
'1', 'test@test.com,pending@test.com,invalid@test.com', false))
.thenAnswer((_) => Future.value(_addedMembers));

when(_mockGroupMembersApi.fetchGroupMembers('1'))
.thenAnswer((_) => Future.value(_groupMembers));

var _model = GroupDetailsViewModel();
await _model.addMembers(
'1', 'test@test.com,pending@test.com,invalid@test.com');
'1', 'test@test.com,pending@test.com,invalid@test.com', false);

// verify API call is made..
verify(_mockGroupMembersApi.addGroupMembers(
'1', 'test@test.com,pending@test.com,invalid@test.com'));
'1', 'test@test.com,pending@test.com,invalid@test.com', false));
verify(_mockGroupMembersApi.fetchGroupMembers('1'));
expect(_model.stateFor(_model.ADD_GROUP_MEMBERS), ViewState.Success);

Expand All @@ -88,12 +88,12 @@ void main() {
test('When called & service returns error', () async {
var _mockGroupMembersApi = getAndRegisterGroupMembersApiMock();
when(_mockGroupMembersApi.addGroupMembers(
'1', 'test@test.com,pending@test.com,invalid@test.com'))
'1', 'test@test.com,pending@test.com,invalid@test.com', false))
.thenThrow(Failure('Some Error Occurred!'));

var _model = GroupDetailsViewModel();
await _model.addMembers(
'1', 'test@test.com,pending@test.com,invalid@test.com');
'1', 'test@test.com,pending@test.com,invalid@test.com', false);

// verify Error ViewState with proper error message..
expect(_model.stateFor(_model.ADD_GROUP_MEMBERS), ViewState.Error);
Expand Down

0 comments on commit 0d56fa3

Please sign in to comment.