Skip to content

Instantly share code, notes, and snippets.

@danahartweg
danahartweg / helpers-firestore.ts
Created July 18, 2021 14:28
Firestore teardown - Unit testing Cloud Firestore
export async function teardown() {
useRealProjectId = false;
const appsToClean = [...apps(), ...adminApps];
return Promise.all(appsToClean.map((app) => app?.delete()));
}
@danahartweg
danahartweg / proposed-schema.graphql
Created June 26, 2021 17:21
Fauna ABAC - Proposed schema
type User {
name: String
email: String!
organizations: [Organization!] @relation
}
type Organization {
name: String!
description: String
@danahartweg
danahartweg / schema.graphql
Last active June 26, 2021 17:17
Fauna ABAC - Core schema
type User {
name: String
email: String!
organizations: [OrganizationMember!] @relation
}
enum OrganizationMemberRole {
OWNER
MEMBER
@danahartweg
danahartweg / item_list_bloc.dart
Last active July 27, 2020 04:23
Item list boolean filtering - Support boolean properties to flutter_bloc_list_manager
return items.where((item) => activeConditions.any((conditionKey) {
final parsedConditionKey = splitConditionKey(conditionKey);
final property = parsedConditionKey[0];
final itemValue = item[property];
final targetValue = parsedConditionKey[1];
if (itemValue is bool) {
return itemValue.toString() == targetValue.toLowerCase();
}
@danahartweg
danahartweg / item_list_bloc_test.dart
Created July 27, 2020 03:54
Item list test - Support boolean properties to flutter_bloc_list_manager
blocTest(
'returns source items matching a single active boolean condition key',
build: () async {
whenListen(
_filterConditionsBloc,
Stream.value(
ConditionsInitialized(
activeConditions: <String>{
generateConditionKey('conditional', 'True'),
},
@danahartweg
danahartweg / filter_conditions_bloc.dart
Created July 27, 2020 02:52
Boolean value condition - Support boolean properties to flutter_bloc_list_manager
if (value is bool) {
availableConditions[property].add('True');
availableConditions[property].add('False');
availableConditionKeys.add(generateConditionKey(property, 'True'));
availableConditionKeys.add(generateConditionKey(property, 'False'));
}
@danahartweg
danahartweg / filter_conditions_bloc_test.dart
Created July 27, 2020 02:15
Second filter conditions test - Support boolean properties to flutter_bloc_list_manager
blocTest(
'filtering one item on a boolean property should still add both items',
build: () async {
whenListen(
_sourceBloc,
Stream.value(MockSourceBlocClassItems([_mockItem1])),
);
return FilterConditionsBloc<MockSourceBlocClassItems>(
sourceBloc: _sourceBloc,
@danahartweg
danahartweg / filter_conditions_bloc_test.dart
Created July 27, 2020 02:15
First filter conditions test - Support boolean properties to flutter_bloc_list_manager
blocTest(
'formats boolean property values for display without repeating',
build: () async {
whenListen(
_sourceBloc,
Stream.value(
MockSourceBlocClassItems([_mockItem1, _mockItem2, _mockItem3])),
);
return FilterConditionsBloc<MockSourceBlocClassItems>(
@danahartweg
danahartweg / item_list_bloc.dart
Created June 20, 2020 22:45
ItemListBloc searchSource - Manage lists with Flutter Bloc
Iterable<I> _searchSource(String searchQuery, Iterable<I> items) {
if (searchQuery.isEmpty) {
return items;
}
// Search queries are stored lowercase, so we want to match
// against a lowercase value as well.
return items.where((item) => _searchProperties.any((property) {
final value = item[property];
return value is String
@danahartweg
danahartweg / item_list_bloc.dart
Created June 20, 2020 22:39
ItemListBloc filterSource - Manage lists with Flutter Bloc
Iterable<I> _filterSource(List<I> items) {
final activeConditions =
(_filterConditionsBloc.state as ConditionsInitialized).activeConditions;
if (activeConditions.isEmpty) {
return items;
}
// If any active condition matches we can immediately return that item.
return items.where((item) => activeConditions.any((conditionKey) {