use of nl.knaw.huygens.timbuctoo.v5.graphql.security.PermissionBasedFieldVisibility in project timbuctoo by HuygensING.
the class PermissionBasedFieldVisibilityTest method getFieldDefinitionsShowsOnlyDataSetsThatUserHasAccessTo.
@Test
public void getFieldDefinitionsShowsOnlyDataSetsThatUserHasAccessTo() throws Exception {
final DataSetRepository dataSetRepository = mock(DataSetRepository.class);
DataSet dataSet = createDataSetWithUserPermissions("user__dataSetUserHasAccessTo", Sets.newHashSet(Permission.READ));
DataSet dataSet2 = createDataSetWithUserPermissions("user__dataSetUserDoesNotHasAccessTo", Sets.newHashSet());
Collection<DataSet> dataSetCollection = Sets.newHashSet(dataSet, dataSet2);
given(dataSetRepository.getDataSets()).willReturn(dataSetCollection);
final PermissionBasedFieldVisibility permissionBasedFieldVisibility = new PermissionBasedFieldVisibility(userPermissionCheck, dataSetRepository);
final GraphQLFieldsContainer graphQlFieldsContainer = createGraphQlFieldsContainer("user__dataSetUserHasAccessTo", "user__dataSetUserDoesNotHasAccessTo");
List<GraphQLFieldDefinition> retrievedGraphQlFieldDefinitions = permissionBasedFieldVisibility.getFieldDefinitions(graphQlFieldsContainer);
assertThat(retrievedGraphQlFieldDefinitions, contains(hasProperty("name", is("user__dataSetUserHasAccessTo"))));
}
Aggregations