Skip to content

Commit

Permalink
Add ability to resubmit after error
Browse files Browse the repository at this point in the history
Thanks to @Tetr4 for this workaround:
lomsa-com/http-mock-adapter#145 (comment)
  • Loading branch information
backspace committed Aug 22, 2024
1 parent e55c37b commit 5c5eb3d
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 20 deletions.
8 changes: 5 additions & 3 deletions waydowntown_app/lib/routes/bluetooth_collector_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ class BluetoothCollectorGameState extends State<BluetoothCollectorGame> {
title: Text(detectedDevice.device.platformName),
leading: _getIconForState(detectedDevice.state,
detectedDevice.device.remoteId.toString()),
onTap: detectedDevice.state == DeviceSubmissionState.unsubmitted
? () => submitDevice(detectedDevice)
: null,
onTap:
detectedDevice.state == DeviceSubmissionState.unsubmitted ||
detectedDevice.state == DeviceSubmissionState.error
? () => submitDevice(detectedDevice)
: null,
);
},
)),
Expand Down
8 changes: 5 additions & 3 deletions waydowntown_app/lib/routes/code_collector_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,11 @@ class CodeCollectorGameState extends State<CodeCollectorGame>
title: Text(detectedCode.code),
leading:
_getIconForState(detectedCode.state, detectedCode.code),
onTap: detectedCode.state == CodeSubmissionState.unsubmitted
? () => submitCode(detectedCode)
: null,
onTap:
detectedCode.state == CodeSubmissionState.unsubmitted ||
detectedCode.state == CodeSubmissionState.error
? () => submitCode(detectedCode)
: null,
);
},
),
Expand Down
60 changes: 53 additions & 7 deletions waydowntown_app/test/bluetooth_collector_game_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,54 @@ void main() {
)
..onPost(
submitAnswerRoute,
(server) => server.throws(
500,
DioException(
requestOptions: RequestOptions(path: submitAnswerRoute),
error: 'Server error',
),
),
(server) {
server.reply(500, (request) {
// Override handler for resubmission after error
dioAdapter.onPost(
submitAnswerRoute,
(server) => server.reply(201, {
"data": {
"id": "48cf441e-ab98-4da6-8980-69fba3b4417d",
"type": "answers",
"attributes": {
"answer": "Device 3",
"correct": false,
},
"relationships": {
"game": {
"data": {
"type": "games",
"id": "22261813-2171-453f-a669-db08edc70d6d"
}
}
}
},
"meta": {}
}),
data: {
'data': {
'type': 'answers',
'attributes': {
'answer': 'Device 3',
},
'relationships': {
'game': {
'data': {
'type': 'games',
'id': '22261813-2171-453f-a669-db08edc70d6d'
}
}
}
}
},
);

throw DioException(
requestOptions: RequestOptions(path: submitAnswerRoute),
error: 'Server error',
);
});
},
data: {
'data': {
'type': 'answers',
Expand Down Expand Up @@ -289,5 +330,10 @@ void main() {
await tester.pumpAndSettle();

expect(find.text('Error'), findsNothing);

await tester.tap(find.text('Device 3'));
await tester.pumpAndSettle();

expect(errorIcon, findsNothing);
});
}
60 changes: 53 additions & 7 deletions waydowntown_app/test/code_collector_game_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,54 @@ void main() {
)
..onPost(
submitAnswerRoute,
(server) => server.throws(
500,
DioException(
requestOptions: RequestOptions(path: submitAnswerRoute),
error: 'Server error',
),
),
(server) {
server.reply(500, (request) {
// Override handler for resubmission after error
dioAdapter.onPost(
submitAnswerRoute,
(server) => server.reply(201, {
"data": {
"id": "48cf441e-ab98-4da6-8980-69fba3b4417d",
"type": "answers",
"attributes": {
"answer": "Code3",
"correct": false,
},
"relationships": {
"game": {
"data": {
"type": "games",
"id": "22261813-2171-453f-a669-db08edc70d6d"
}
}
}
},
"meta": {}
}),
data: {
'data': {
'type': 'answers',
'attributes': {
'answer': 'Code3',
},
'relationships': {
'game': {
'data': {
'type': 'games',
'id': '22261813-2171-453f-a669-db08edc70d6d'
}
}
}
}
},
);

throw DioException(
requestOptions: RequestOptions(path: submitAnswerRoute),
error: 'Server error',
);
});
},
data: {
'data': {
'type': 'answers',
Expand Down Expand Up @@ -285,5 +326,10 @@ void main() {
await tester.pumpAndSettle();

expect(find.text('Error'), findsNothing);

await tester.tap(find.text('Code3'));
await tester.pumpAndSettle();

expect(errorIcon, findsNothing);
});
}

0 comments on commit 5c5eb3d

Please sign in to comment.