Skip to content

Commit

Permalink
refactor!: rename PiholeRepository to PiholeApi
Browse files Browse the repository at this point in the history
  • Loading branch information
sterrenb committed Jan 10, 2022
1 parent 2e2ce48 commit 3d3640b
Showing 1 changed file with 41 additions and 43 deletions.
84 changes: 41 additions & 43 deletions test/pihole_repository_dio_test.dart
Expand Up @@ -12,7 +12,7 @@ void main() async {
late PiholeApiParams params;
late Dio dio;
late DioAdapter dioAdapter;
late PiholeApiDio repository;
late PiholeApiDio api;
late CancelToken cancelToken;

setUp(() {
Expand All @@ -29,12 +29,12 @@ void main() async {
allowSelfSignedCertificates: false,
adminHome: "/admin",
);
repository = PiholeApiDio(params);
api = PiholeApiDio(params);
});

group('fetchSummary', () {
test('fetchSummary returns PiSummary', () async {
final res = await repository.fetchSummary(cancelToken);
final res = await api.fetchSummary(cancelToken);
expect(
res,
const PiSummary(
Expand All @@ -60,7 +60,7 @@ void main() async {
test('fetchSummary handles empty reply', () async {
dioAdapter.onGet("/admin/api.php", (request) => request.reply(200, ""),
queryParameters: {'summaryRaw': ''});
expect(repository.fetchSummary(cancelToken),
expect(api.fetchSummary(cancelToken),
throwsA(const PiholeApiFailure.emptyString()));
});

Expand All @@ -70,7 +70,7 @@ void main() async {
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))),
queryParameters: {'summaryRaw': ''});
expect(repository.fetchSummary(cancelToken),
expect(api.fetchSummary(cancelToken),
throwsA(const PiholeApiFailure.general("")));
});

Expand All @@ -84,7 +84,7 @@ void main() async {
type: DioErrorType.other,
error: 'Failed host lookup')),
queryParameters: {'summaryRaw': ''});
expect(repository.fetchSummary(cancelToken),
expect(api.fetchSummary(cancelToken),
throwsA(const PiholeApiFailure.hostname()));
});

Expand All @@ -97,7 +97,7 @@ void main() async {
requestOptions: RequestOptions(path: ""),
type: DioErrorType.connectTimeout)),
queryParameters: {'summaryRaw': ''});
expect(repository.fetchSummary(cancelToken),
expect(api.fetchSummary(cancelToken),
throwsA(const PiholeApiFailure.timeout()));
});

Expand All @@ -110,7 +110,7 @@ void main() async {
requestOptions: RequestOptions(path: ""),
type: DioErrorType.response)),
queryParameters: {'summaryRaw': ''});
expect(repository.fetchSummary(cancelToken),
expect(api.fetchSummary(cancelToken),
throwsA(const PiholeApiFailure.invalidResponse(500)));
});

Expand All @@ -123,7 +123,7 @@ void main() async {
requestOptions: RequestOptions(path: ""),
type: DioErrorType.cancel)),
queryParameters: {'summaryRaw': ''});
expect(repository.fetchSummary(cancelToken),
expect(api.fetchSummary(cancelToken),
throwsA(const PiholeApiFailure.cancelled()));
});
});
Expand Down Expand Up @@ -153,7 +153,7 @@ void main() async {
}
}),
queryParameters: {'getQueryTypes': '', 'auth': 'token'});
final res = await repository.fetchQueryTypes(cancelToken);
final res = await api.fetchQueryTypes(cancelToken);
expect(
res,
PiQueryTypes(types: {
Expand All @@ -170,15 +170,15 @@ void main() async {
test('fetchQueryTypes handles empty list response', () async {
dioAdapter.onGet("/admin/api.php", (request) => request.reply(200, []),
queryParameters: {'getQueryTypes': '', 'auth': 'token'});
expect(repository.fetchQueryTypes(cancelToken),
expect(api.fetchQueryTypes(cancelToken),
throwsA(const PiholeApiFailure.emptyList()));
});

test('fetchQueryTypes handles unauthenticated', () async {
repository = PiholeApiDio(params.copyWith(apiToken: ""));
api = PiholeApiDio(params.copyWith(apiToken: ""));
dioAdapter.onGet("/admin/api.php", (request) => request.reply(200, []),
queryParameters: {'getQueryTypes': '', 'auth': ''});
expect(repository.fetchQueryTypes(cancelToken),
expect(api.fetchQueryTypes(cancelToken),
throwsA(const PiholeApiFailure.notAuthenticated()));
});

Expand All @@ -188,7 +188,7 @@ void main() async {
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))),
queryParameters: {'getQueryTypes': '', 'auth': 'token'});
expect(repository.fetchQueryTypes(cancelToken),
expect(api.fetchQueryTypes(cancelToken),
throwsA(const PiholeApiFailure.general("")));
});
});
Expand All @@ -206,7 +206,7 @@ void main() async {
}
}),
queryParameters: {'getForwardDestinations': '', 'auth': 'token'});
final res = await repository.fetchForwardDestinations(cancelToken);
final res = await api.fetchForwardDestinations(cancelToken);
expect(
res,
PiForwardDestinations(
Expand All @@ -225,7 +225,7 @@ void main() async {
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))),
queryParameters: {'getForwardDestinations': '', 'auth': 'token'});
expect(repository.fetchForwardDestinations(cancelToken),
expect(api.fetchForwardDestinations(cancelToken),
throwsA(const PiholeApiFailure.general("")));
});
});
Expand All @@ -247,7 +247,7 @@ void main() async {
}
}),
queryParameters: {'overTimeData10mins': '', 'auth': 'token'});
final res = await repository.fetchQueriesOverTime(cancelToken);
final res = await api.fetchQueriesOverTime(cancelToken);
expect(
res,
PiQueriesOverTime(
Expand All @@ -270,7 +270,7 @@ void main() async {
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))),
queryParameters: {'overTimeData10mins': '', 'auth': 'token'});
expect(repository.fetchQueriesOverTime(cancelToken),
expect(api.fetchQueriesOverTime(cancelToken),
throwsA(const PiholeApiFailure.general("")));
});
});
Expand All @@ -297,7 +297,7 @@ void main() async {
'overTimeDataClients': '',
'auth': 'token'
});
final res = await repository.fetchClientActivityOverTime(cancelToken);
final res = await api.fetchClientActivityOverTime(cancelToken);
expect(
res,
PiClientActivityOverTime(
Expand Down Expand Up @@ -351,7 +351,7 @@ void main() async {
'overTimeDataClients': '',
'auth': 'token'
});
expect(repository.fetchClientActivityOverTime(cancelToken),
expect(api.fetchClientActivityOverTime(cancelToken),
throwsA(const PiholeApiFailure.general("")));
});
});
Expand All @@ -361,7 +361,7 @@ void main() async {
dioAdapter.onGet("/admin/api.php",
(request) => request.reply(200, {"status": "enabled"}),
queryParameters: {'status': ''});
final res = await repository.ping(cancelToken);
final res = await api.ping(cancelToken);
expect(res, const PiholeStatus.enabled());
});

Expand All @@ -371,8 +371,8 @@ void main() async {
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))),
queryParameters: {'status': ''});
expect(repository.ping(cancelToken),
throwsA(const PiholeApiFailure.general("")));
expect(
api.ping(cancelToken), throwsA(const PiholeApiFailure.general("")));
});
});

Expand All @@ -381,7 +381,7 @@ void main() async {
dioAdapter.onGet("/admin/api.php",
(request) => request.reply(200, {"status": "enabled"}),
queryParameters: {'enable': '', 'auth': 'token'});
final res = await repository.enable(cancelToken);
final res = await api.enable(cancelToken);
expect(res, const PiholeStatus.enabled());
});

Expand All @@ -391,8 +391,8 @@ void main() async {
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))),
queryParameters: {'enable': '', 'auth': 'token'});
expect(repository.enable(cancelToken),
throwsA(const PiholeApiFailure.general("")));
expect(
api.enable(cancelToken), throwsA(const PiholeApiFailure.general("")));
});
});

Expand All @@ -401,7 +401,7 @@ void main() async {
dioAdapter.onGet("/admin/api.php",
(request) => request.reply(200, {"status": "disabled"}),
queryParameters: {'disable': '', 'auth': 'token'});
final res = await repository.disable(cancelToken);
final res = await api.disable(cancelToken);
expect(res, const PiholeStatus.disabled());
});

Expand All @@ -411,7 +411,7 @@ void main() async {
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))),
queryParameters: {'disable': '', 'auth': 'token'});
expect(repository.disable(cancelToken),
expect(api.disable(cancelToken),
throwsA(const PiholeApiFailure.general("")));
});
});
Expand All @@ -422,8 +422,7 @@ void main() async {
(request) => request.reply(200, {"status": "disabled"}),
queryParameters: {'disable': '30', 'auth': 'token'});
withClock(Clock.fixed(DateTime(2000)), () async {
final res =
await repository.sleep(const Duration(seconds: 30), cancelToken);
final res = await api.sleep(const Duration(seconds: 30), cancelToken);
expect(res,
PiholeStatus.sleeping(const Duration(seconds: 30), clock.now()));
});
Expand All @@ -433,8 +432,7 @@ void main() async {
dioAdapter.onGet("/admin/api.php",
(request) => request.reply(200, {"status": "enabled"}),
queryParameters: {'disable': '30', 'auth': 'token'});
final res =
await repository.sleep(const Duration(seconds: 30), cancelToken);
final res = await api.sleep(const Duration(seconds: 30), cancelToken);
expect(res, const PiholeStatus.enabled());
});

Expand All @@ -444,7 +442,7 @@ void main() async {
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))),
queryParameters: {'disable': '60', 'auth': 'token'});
expect(repository.sleep(const Duration(seconds: 60), cancelToken),
expect(api.sleep(const Duration(seconds: 60), cancelToken),
throwsA(const PiholeApiFailure.general("")));
});
});
Expand Down Expand Up @@ -497,7 +495,7 @@ void main() async {
]
}),
queryParameters: {'getAllQueries': '3', 'auth': 'token'});
final res = await repository.fetchQueryItems(cancelToken, 3);
final res = await api.fetchQueryItems(cancelToken, 3);
expect(res, [
QueryItem(
timestamp: DateTime.fromMillisecondsSinceEpoch(1624981977 * 1000),
Expand Down Expand Up @@ -535,7 +533,7 @@ void main() async {
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))),
queryParameters: {'getAllQueries': '10', 'auth': 'token'});
expect(repository.fetchQueryItems(cancelToken, 10),
expect(api.fetchQueryItems(cancelToken, 10),
throwsA(const PiholeApiFailure.general("")));
});
});
Expand All @@ -557,7 +555,7 @@ void main() async {
}
}),
queryParameters: {'topItems': '', 'auth': 'token'});
final res = await repository.fetchTopItems(cancelToken);
final res = await api.fetchTopItems(cancelToken);
expect(
res,
TopItems(
Expand All @@ -580,7 +578,7 @@ void main() async {
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))),
queryParameters: {'topItems': '', 'auth': 'token'});
expect(repository.fetchTopItems(cancelToken),
expect(api.fetchTopItems(cancelToken),
throwsA(const PiholeApiFailure.general("")));
});
});
Expand All @@ -604,7 +602,7 @@ void main() async {
"FTL_branch": "master"
}),
queryParameters: {'versions': ''});
final res = await repository.fetchVersions(cancelToken);
final res = await api.fetchVersions(cancelToken);
expect(
res,
PiVersions(
Expand All @@ -629,7 +627,7 @@ void main() async {
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))),
queryParameters: {'versions': ''});
expect(repository.fetchVersions(cancelToken),
expect(api.fetchVersions(cancelToken),
throwsA(const PiholeApiFailure.general("")));
});
});
Expand All @@ -640,7 +638,7 @@ void main() async {
"/admin",
(request) => request.reply(200, adminHtmlString),
);
final res = await repository.fetchPiDetails(cancelToken);
final res = await api.fetchPiDetails(cancelToken);
expect(
res,
PiDetails(
Expand All @@ -655,7 +653,7 @@ void main() async {
"/admin",
(request) => request.reply(200, ''),
);
expect(repository.fetchPiDetails(cancelToken),
expect(api.fetchPiDetails(cancelToken),
throwsA(const PiholeApiFailure.emptyString()));
});

Expand All @@ -664,7 +662,7 @@ void main() async {
"/admin",
(request) => request.throws(
400, DioError(requestOptions: RequestOptions(path: ""))));
expect(repository.fetchPiDetails(cancelToken),
expect(api.fetchPiDetails(cancelToken),
throwsA(const PiholeApiFailure.general("")));
});

Expand All @@ -673,7 +671,7 @@ void main() async {
"/admin",
(request) => request.reply(200, adminHtmlStringWithoutTags),
);
final res = await repository.fetchPiDetails(cancelToken);
final res = await api.fetchPiDetails(cancelToken);
expect(
res,
PiDetails(
Expand Down

0 comments on commit 3d3640b

Please sign in to comment.