From d5ae4b4ef33ae3690669daafa41f643b785e6602 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 18 Jul 2022 15:09:05 +0200 Subject: [PATCH] Add tests for sub URL handling --- test/other/base_provider_test.dart | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/other/base_provider_test.dart b/test/other/base_provider_test.dart index 2f6cbdf1..bd3c4715 100644 --- a/test/other/base_provider_test.dart +++ b/test/other/base_provider_test.dart @@ -58,5 +58,40 @@ void main() { provider.makeUrl('endpoint', id: 42, objectMethod: 'log_data', query: {'a': '2', 'b': 'c'}), ); }); + + test('Test the makeUrl helper with sub url', () async { + // Trailing slash is removed when saving the server URL + testAuthProvider.serverUrl = 'https://example.com/wger-url'; + final WgerBaseProvider provider = WgerBaseProvider(testAuthProvider); + + expect( + Uri.https('example.com', '/wger-url/api/v2/endpoint/'), + provider.makeUrl('endpoint'), + ); + expect( + Uri.https('example.com', '/wger-url/api/v2/endpoint/5/'), + provider.makeUrl('endpoint', id: 5), + ); + expect( + Uri.https('example.com', '/wger-url/api/v2/endpoint/5/log_data/'), + provider.makeUrl('endpoint', id: 5, objectMethod: 'log_data'), + ); + expect( + Uri.https('example.com', '/wger-url/api/v2/endpoint/', {'a': '2', 'b': 'c'}), + provider.makeUrl('endpoint', query: {'a': '2', 'b': 'c'}), + ); + expect( + Uri.https('example.com', '/wger-url/api/v2/endpoint/log_data/', {'a': '2', 'b': 'c'}), + provider.makeUrl('endpoint', objectMethod: 'log_data', query: {'a': '2', 'b': 'c'}), + ); + expect( + Uri.https('example.com', '/wger-url/api/v2/endpoint/42/', {'a': '2', 'b': 'c'}), + provider.makeUrl('endpoint', id: 42, query: {'a': '2', 'b': 'c'}), + ); + expect( + Uri.https('example.com', '/wger-url/api/v2/endpoint/42/log_data/', {'a': '2', 'b': 'c'}), + provider.makeUrl('endpoint', id: 42, objectMethod: 'log_data', query: {'a': '2', 'b': 'c'}), + ); + }); }); }