From affa3b570e2cbc516bb2804fb54e2f46796dba47 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Thu, 14 Jul 2022 21:35:46 +0100 Subject: [PATCH] plugin: add get manifest unit test regarding the hooks Signed-off-by: Vincenzo Palazzo --- .../test/cln_plugin_method_test.dart | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/cln_plugin/test/cln_plugin_method_test.dart b/packages/cln_plugin/test/cln_plugin_method_test.dart index 0430533..f699164 100644 --- a/packages/cln_plugin/test/cln_plugin_method_test.dart +++ b/packages/cln_plugin/test/cln_plugin_method_test.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:cln_plugin/src/cln_plugin_base.dart'; import 'package:test/test.dart'; @@ -121,6 +123,30 @@ void main() { expect(getManifest["hooks"], isNotNull); expect(getManifest["subscriptions"], isNotNull); }); + + test('deep getManifest Test', () async { + var plugin = Plugin( + dynamic: true, + onInit: (plugin) { + return Future.value({}); + }); + plugin.registerHook( + name: "rpc_command", + callback: (plugin, request) { + plugin.log(level: "info", message: "hook info"); + return Future(() => {"result": "continue"}); + }); + // Adding an empty request and generating a manifest. + var getManifest = await plugin.getManifest(plugin, {}); + + expect(getManifest.containsKey('hooks'), true); + expect(getManifest["hooks"], isNotNull); + var hooks = List.from(jsonDecode(jsonEncode(getManifest["hooks"]))); + expect(hooks.length, 1); + expect(hooks[0]["name"], "rpc_command"); + expect(hooks[0]["before"], isNull); + expect(hooks[0]["after"], isNull); + }); }); group('Init test: ', () { test('Property test - option registered.', () {