Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
B0berman committed Mar 21, 2024
2 parents 11ae3f3 + c1a0e56 commit 7902716
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 12 deletions.
20 changes: 16 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,35 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch development",
"name": "Web local",
"request": "launch",
"type": "dart",
"program": "lib/main_local.dart",
"args": [
"--target",
"lib/main_local.dart",
"--web-port",
"24514"
]
},
{
"name": "Web development",
"request": "launch",
"type": "dart",
"program": "lib/main_development.dart",
"args": [
"--flavor",
"development",
"--target",
"lib/main_development.dart"
]
},
{
"name": "web development",
"name": "Launch development",
"request": "launch",
"type": "dart",
"program": "lib/main_development.dart",
"args": [
"--flavor",
"development",
"--target",
"lib/main_development.dart"
]
Expand Down
2 changes: 1 addition & 1 deletion lib/crossword/game/components/section_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class SectionComponent extends Component with HasGameRef<CrosswordGame> {
final boardSection = gameRef.state.sections[index];
if (boardSection != null) {
_boardSection = boardSection;
_loadBoardSection();
_loadWithCurrentRenderMode();
} else {
gameRef.bloc.add(
BoardSectionRequested(index),
Expand Down
46 changes: 46 additions & 0 deletions lib/main_local.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'dart:async';

import 'package:api_client/api_client.dart';
import 'package:authentication_repository/authentication_repository.dart';
import 'package:board_info_repository/board_info_repository.dart';
import 'package:crossword_repository/crossword_repository.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/widgets.dart';
import 'package:io_crossword/app/app.dart';
import 'package:io_crossword/bootstrap.dart';
import 'package:io_crossword/firebase_options_development.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();

await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);

unawaited(
bootstrap(
(firestore, firebaseAuth) async {
final authenticationRepository = AuthenticationRepository(
firebaseAuth: firebaseAuth,
);

await authenticationRepository.signInAnonymously();
await authenticationRepository.idToken.first;

final apiClient = ApiClient(
baseUrl: 'http://localhost:8080',
idTokenStream: authenticationRepository.idToken,
refreshIdToken: authenticationRepository.refreshIdToken,
// TODO(any): implement app check
appCheckTokenStream: const Stream.empty(),
);

return App(
apiClient: apiClient,
crosswordRepository: CrosswordRepository(db: firestore),
boardInfoRepository: BoardInfoRepository(firestore: firestore),
);
},
),
);
}
17 changes: 15 additions & 2 deletions packages/board_info_repository/lib/src/board_info_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BoardInfoRepository {
/// The [CollectionReference] for the config.
late final CollectionReference<Map<String, dynamic>> boardInfoCollection;

/// Return the total words count available in the crossword.
/// Returns the total words count available in the crossword.
Future<int> getTotalWordsCount() async {
try {
final results = await boardInfoCollection
Expand All @@ -48,7 +48,7 @@ class BoardInfoRepository {
}
}

/// Return the solved words count in the crossword.
/// Returns the solved words count in the crossword.
Future<int> getSolvedWordsCount() async {
try {
final results = await boardInfoCollection
Expand All @@ -75,4 +75,17 @@ class BoardInfoRepository {
throw BoardInfoException(error, stackStrace);
}
}

/// Returns the limit at which the render mode should switch
Future<List<double>> getRenderModeZoomLimits() async {
try {
final results = await boardInfoCollection
.where('type', isEqualTo: 'render_mode_limit')
.get();

return results.docs.map((e) => e.data()['value'] as double).toList();
} catch (error, stackStrace) {
throw BoardInfoException(error, stackStrace);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ void main() {
when(
() => collection.where('type', isEqualTo: 'solved_words_count'),
).thenReturn(collection);
when(
() => collection.where('type', isEqualTo: 'render_mode_limit'),
).thenReturn(collection);
when(
() => collection.where('type', isEqualTo: 'section_size'),
).thenReturn(collection);

when(collection.get).thenAnswer((_) async => query);
when(() => query.docs).thenReturn([doc]);
Expand Down Expand Up @@ -90,21 +96,39 @@ void main() {

group('getSectionSize', () {
test('returns the section size value from firebase', () async {
mockQueryResult(66000);
mockQueryResult(20);
final result = await boardInfoRepository.getSectionSize();
expect(result, equals(66000));
expect(result, equals(20));
});

test('throws BoardInfoException when fetching the info fails', () {
when(
() => collection.where('type', isEqualTo: 'solved_words_count'),
() => collection.where('type', isEqualTo: 'section_size'),
).thenThrow(Exception('oops'));
expect(
() => boardInfoRepository.getSectionSize(),
throwsA(isA<BoardInfoException>()),
);
});
});

group('getRenderModeZoomLimit', () {
test('returns render mode limit from firebase', () async {
mockQueryResult(0.6);
final result = await boardInfoRepository.getRenderModeZoomLimits();
expect(result, equals([0.6]));
});

test('throws BoardInfoException when fetching the info fails', () {
when(
() => collection.where('type', isEqualTo: 'solved_words_count'),
).thenThrow(Exception('oops'));
expect(
() => boardInfoRepository.getRenderModeZoomLimits(),
throwsA(isA<BoardInfoException>()),
);
});
});
});

group('BoardInfoException', () {
Expand Down
4 changes: 2 additions & 2 deletions scripts/start_local_api.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

export FB_APP_ID=io-crossword-dev
export GAME_URL=http://localhost:8080/
export USE_EMULATOR=true
export GAME_URL=http://localhost:24514
export USE_EMULATOR=false
export ENCRYPTION_KEY=X9YTchZdcnyZTNBSBgzj29p7RMBAIubD
export ENCRYPTION_IV=FxC21ctRg9SgiXuZ
export INITIALS_BLACKLIST_ID=T1ilfCwjDpLS7iaFzenA
Expand Down

0 comments on commit 7902716

Please sign in to comment.