forked from PalisadoesFoundation/talawa
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetch plugin list test (PalisadoesFoundation#2115)
* fetch plugin list test * test helpers * fixing workflow * fixing workflow * fixing failing test * fixing failing tets
- Loading branch information
1 parent
2112759
commit 96a8028
Showing
2 changed files
with
113 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import 'dart:io'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:graphql_flutter/graphql_flutter.dart'; | ||
import 'package:hive/hive.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:talawa/plugins/fetch_plugin_list.dart'; | ||
import 'package:talawa/services/graphql_config.dart'; | ||
|
||
import '../helpers/test_helpers.dart'; | ||
import '../helpers/test_locator.dart'; | ||
|
||
/// Tests fetch_plugin_list.dart. | ||
/// | ||
/// more_info_if_required | ||
/// | ||
/// **params**: | ||
/// None | ||
/// | ||
/// **returns**: | ||
/// None | ||
void main() async { | ||
testSetupLocator(); | ||
locator<GraphqlConfig>().test(); | ||
late FetchPluginList fetchPluginList; | ||
|
||
final Directory dir = await Directory.systemTemp.createTemp('talawa_test'); | ||
Hive.init(dir.path); | ||
await Hive.openBox('pluginBox'); | ||
|
||
setUp(() { | ||
registerServices(); | ||
locator.allowReassignment = true; | ||
|
||
locator.registerLazySingleton<FetchPluginList>(() => FetchPluginList()); | ||
fetchPluginList = locator<FetchPluginList>(); | ||
}); | ||
group('FetchPluginList', () { | ||
test('fetchList should fetch plugins and store them in Hive', () async { | ||
final queryResult = QueryResult( | ||
data: { | ||
'getPlugins': [ | ||
{ | ||
'_id': '1', | ||
'pluginName': 'Plugin 1', | ||
'pluginCreatedBy': 'User A', | ||
'pluginDesc': 'Description A', | ||
'pluginInstallStatus': true, | ||
'installedOrgs': ['Org A'], | ||
}, | ||
], | ||
}, | ||
options: QueryOptions( | ||
document: gql(queries.getPluginsList()), | ||
), | ||
source: QueryResultSource.network, | ||
); | ||
|
||
when(locator<GraphqlConfig>().clientToQuery()).thenAnswer( | ||
(_) => locator<GraphQLClient>(), | ||
); | ||
when( | ||
locator<GraphQLClient>().query( | ||
QueryOptions( | ||
document: gql(queries.getPluginsList()), | ||
), | ||
), | ||
).thenAnswer((_) async => queryResult); | ||
await fetchPluginList.fetchList(); | ||
|
||
verify(locator<GraphqlConfig>().clientToQuery()).called(2); | ||
verify( | ||
locator<GraphQLClient>().query( | ||
QueryOptions( | ||
document: gql(queries.getPluginsList()), | ||
), | ||
), | ||
).called(2); | ||
|
||
expect(fetchPluginList.box, isNotNull); | ||
expect( | ||
fetchPluginList.box.get('plugins'), | ||
equals(queryResult.data!["getPlugins"]), | ||
); | ||
}); | ||
}); | ||
} |