unit test
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||
import 'package:fotodocumentation/controller/customer_controller.dart';
|
||||
import 'package:fotodocumentation/controller/foto_customer_controller.dart';
|
||||
import 'package:fotodocumentation/dto/customer_dto.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
import 'package:fotodocumentation/utils/http_client_utils.dart';
|
||||
@@ -17,7 +17,7 @@ void main() {
|
||||
when(jwtTokenStorage.getAccessToken()).thenAnswer((_) => null);
|
||||
DiContainer.instance.put(JwtTokenStorage, jwtTokenStorage);
|
||||
|
||||
CustomerController controller = CustomerControllerImpl();
|
||||
FotoCustomerController controller = FotoCustomerControllerImpl();
|
||||
|
||||
group('PictureControllerTest', () {
|
||||
test('returns a list of customers', () async {
|
||||
@@ -0,0 +1,128 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fotodocumentation/controller/base_controller.dart';
|
||||
import 'package:fotodocumentation/controller/questionnaire_customer_controller.dart';
|
||||
import 'package:fotodocumentation/dto/questionnaire_customer_dto.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
import 'package:fotodocumentation/utils/http_client_utils.dart';
|
||||
import 'package:fotodocumentation/utils/jwt_token_storage.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../testing/test_http_client_utils.dart';
|
||||
import '../testing/test_utils.mocks.dart';
|
||||
|
||||
void main() {
|
||||
DiContainer.instance.initState();
|
||||
var jwtTokenStorage = MockJwtTokenStorage();
|
||||
when(jwtTokenStorage.getAccessToken()).thenAnswer((_) => null);
|
||||
DiContainer.instance.put(JwtTokenStorage, jwtTokenStorage);
|
||||
|
||||
QuestionnaireCustomerController controller = QuestionnaireCustomerControllerImpl();
|
||||
|
||||
group('PictureControllerTest', () {
|
||||
test('returns a list of customers', () async {
|
||||
final client = MockClient();
|
||||
DiContainer.instance.put(HttpClientUtils, TestHttpCLientUtilsImpl(client));
|
||||
when(client.get(Uri.parse('http://localhost:8080/api/questionnairecustomer?query=&startsWith='), headers: {"Accept-Language": "en-US"})).thenAnswer((_) async => http.Response(_customersJson, 200));
|
||||
|
||||
var dtos = await controller.getAll("", "");
|
||||
expect(dtos, isA<List<QuestionnaireCustomerListDto>>());
|
||||
expect(dtos.length, 3);
|
||||
});
|
||||
|
||||
test('throws an exception if the http call completes with an error', () async {
|
||||
final client = MockClient();
|
||||
DiContainer.instance.put(HttpClientUtils, TestHttpCLientUtilsImpl(client));
|
||||
|
||||
when(client.get(Uri.parse('http://localhost:8080/api/questionnairecustomer?query=&startsWith='), headers: {"Accept-Language": "en-US"})).thenAnswer((_) async => http.Response('Not Found', 404));
|
||||
|
||||
expect(() async => await controller.getAll("", ""), throwsA(isA<ServerError>()));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('returns a customer', () async {
|
||||
final client = MockClient();
|
||||
DiContainer.instance.put(HttpClientUtils, TestHttpCLientUtilsImpl(client));
|
||||
|
||||
when(client.get(Uri.parse('http://localhost:8080/api/questionnairecustomer/4'), headers: {"Accept-Language": "en-US"}))
|
||||
.thenAnswer((_) async => http.Response(_customerJson, 200));
|
||||
|
||||
var dto = await controller.get(id: 4);
|
||||
expect(dto, isA<QuestionnaireCustomerListDto>());
|
||||
});
|
||||
|
||||
test('export a customer', () async {
|
||||
final client = MockClient();
|
||||
DiContainer.instance.put(HttpClientUtils, TestHttpCLientUtilsImpl(client));
|
||||
|
||||
when(client.get(Uri.parse('http://localhost:8080/api/questionnairecustomer/export/4'), headers: {"Accept-Language": "en-US"}))
|
||||
.thenAnswer((_) async => http.Response(_customerJson, 200));
|
||||
|
||||
var dto = await controller.export(customerId: 4);
|
||||
expect(dto, isA<List<int>>());
|
||||
});
|
||||
|
||||
test('export a customer picture', () async {
|
||||
final client = MockClient();
|
||||
DiContainer.instance.put(HttpClientUtils, TestHttpCLientUtilsImpl(client));
|
||||
|
||||
when(client.get(Uri.parse('http://localhost:8080/api/questionnairecustomer/export/4?picture=1'), headers: {"Accept-Language": "en-US"}))
|
||||
.thenAnswer((_) async => http.Response(_customerJson, 200));
|
||||
|
||||
var dto = await controller.export(customerId: 4, questionnaireId: 1);
|
||||
expect(dto, isA<List<int>>());
|
||||
});
|
||||
}
|
||||
|
||||
String _customersJson = '''[
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Müller Apotheke",
|
||||
"customerNumber": "1234",
|
||||
"lastUpdateDate": 1729764570000
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Meier Apotheke",
|
||||
"customerNumber": "2345",
|
||||
"lastUpdateDate": 1729764570000
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Schmidt Apotheke",
|
||||
"customerNumber": "3456",
|
||||
"lastUpdateDate": 1729764570000
|
||||
}
|
||||
]''';
|
||||
|
||||
String _customerJson = '''{
|
||||
"id": 1,
|
||||
"name": "Müller Apotheke",
|
||||
"customerNumber": "1234",
|
||||
"pictures": [
|
||||
{
|
||||
"id": 1,
|
||||
"comment": "good looking picture 1",
|
||||
"category": null,
|
||||
"pictureDate": 1729764570000,
|
||||
"evaluation": 1,
|
||||
"username": "verboomp",
|
||||
"imageUrl": "",
|
||||
"normalSizeUrl": "",
|
||||
"thumbnailSizeUrl": ""
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"comment": "good looking picture 2",
|
||||
"category": null,
|
||||
"pictureDate": 1729764570000,
|
||||
"evaluation": 1,
|
||||
"username": "verboomp",
|
||||
"imageUrl": "",
|
||||
"normalSizeUrl": "",
|
||||
"thumbnailSizeUrl": ""
|
||||
}
|
||||
]
|
||||
}''';
|
||||
|
||||
Reference in New Issue
Block a user