-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict access to mutation ProgressParticipant
This commit implements role-based restrictions on the ProgressParticipant mutation. This effectively excludes Read-Only participants and non-participating users from using this mutation
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using Xunit; | ||
using System; | ||
using System.Linq; | ||
|
||
using api.Models; | ||
using api.Services; | ||
using api.GQL; | ||
|
||
|
||
namespace tests | ||
{ | ||
public class ProgressParticipantMutation : MutationTest | ||
{ | ||
private readonly Evaluation _evaluation; | ||
private readonly Participant _facilitator; | ||
private readonly Participant _organizationLead; | ||
private readonly Participant _participant; | ||
private readonly Participant _readonly; | ||
|
||
public ProgressParticipantMutation() { | ||
_evaluation = CreateEvaluation(); | ||
_facilitator = _evaluation.Participants.First(); | ||
_authService.LoginUser(_facilitator); | ||
|
||
_organizationLead = CreateParticipant(_evaluation, role: Role.OrganizationLead); | ||
_participant = CreateParticipant(_evaluation, role: Role.Participant); | ||
_readonly = CreateParticipant(_evaluation, role: Role.ReadOnly); | ||
} | ||
|
||
/* Tests */ | ||
|
||
[Fact] | ||
public void FacilitatorCanUseMutation() | ||
{ | ||
AssertCanProgress(_facilitator); | ||
} | ||
|
||
[Fact] | ||
public void OrganizationLeadCanUseMutation() | ||
{ | ||
AssertCanProgress(_organizationLead); | ||
} | ||
|
||
[Fact] | ||
public void ParticipantCanUseMutation() | ||
{ | ||
AssertCanProgress(_participant); | ||
} | ||
|
||
[Fact] | ||
public void ReadOnlyIsUnauthorized() | ||
{ | ||
AssertIsNotAuthorized(_readonly); | ||
} | ||
|
||
/* Helper methods */ | ||
|
||
private void AssertCanProgress(Participant user) | ||
{ | ||
_authService.LoginUser(user); | ||
Progression newProgression = Randomize.Progression(); | ||
|
||
_mutation.ProgressParticipant( | ||
evaluationId: _evaluation.Id, | ||
newProgression: newProgression | ||
); | ||
|
||
Assert.True(user.Progression == newProgression); | ||
} | ||
|
||
private void AssertIsNotAuthorized(Participant user) | ||
{ | ||
_authService.LoginUser(user.AzureUniqueId); | ||
Assert.Throws<UnauthorizedAccessException>(() => | ||
_mutation.ProgressParticipant( | ||
evaluationId: _evaluation.Id, | ||
newProgression: Randomize.Progression() | ||
) | ||
); | ||
} | ||
} | ||
} |